2018-04-24 11:14:27 +02:00
|
|
|
{-# LANGUAGE AllowAmbiguousTypes #-}
|
2018-04-14 03:09:12 +02:00
|
|
|
{-# LANGUAGE ConstraintKinds #-}
|
2018-04-16 05:43:04 +02:00
|
|
|
{-# LANGUAGE DefaultSignatures #-}
|
2018-04-14 03:09:12 +02:00
|
|
|
{-# LANGUAGE FlexibleContexts #-}
|
|
|
|
{-# LANGUAGE FlexibleInstances #-}
|
|
|
|
{-# LANGUAGE LambdaCase #-}
|
2018-04-24 11:14:27 +02:00
|
|
|
{-# LANGUAGE MonoLocalBinds #-}
|
2018-04-14 03:09:12 +02:00
|
|
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
|
|
|
{-# LANGUAGE MultiWayIf #-}
|
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
2018-04-16 19:56:29 +02:00
|
|
|
{-# LANGUAGE TupleSections #-}
|
2018-04-14 03:09:12 +02:00
|
|
|
{-# LANGUAGE TypeApplications #-}
|
|
|
|
{-# LANGUAGE UndecidableInstances #-}
|
|
|
|
|
|
|
|
{-# OPTIONS_GHC -Wno-missing-signatures #-}
|
|
|
|
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
|
|
|
|
|
2018-04-22 23:32:55 +02:00
|
|
|
-- | Although there are a lot of instances in this file, really it's just a
|
|
|
|
-- combinatorial explosion of the following combinations:
|
|
|
|
--
|
|
|
|
-- - Several Haskell types being converted to/from Nix wrappers
|
|
|
|
-- - Several types of Nix wrappers
|
|
|
|
-- - Whether to be shallow or deep while unwrapping
|
|
|
|
|
2018-04-14 03:09:12 +02:00
|
|
|
module Nix.Convert where
|
|
|
|
|
|
|
|
import Control.Monad
|
2018-09-09 17:01:09 +02:00
|
|
|
import Control.Monad.Free
|
2018-04-14 03:09:12 +02:00
|
|
|
import Data.Aeson (toJSON)
|
|
|
|
import qualified Data.Aeson as A
|
2018-04-15 07:58:50 +02:00
|
|
|
import Data.ByteString
|
2018-04-14 03:09:12 +02:00
|
|
|
import Data.HashMap.Lazy (HashMap)
|
|
|
|
import qualified Data.HashMap.Lazy as M
|
2018-04-15 07:58:50 +02:00
|
|
|
import Data.Scientific
|
2018-04-14 03:09:12 +02:00
|
|
|
import Data.Text (Text)
|
2018-04-15 08:52:21 +02:00
|
|
|
import qualified Data.Text as Text
|
2018-04-15 07:58:50 +02:00
|
|
|
import Data.Text.Encoding (encodeUtf8, decodeUtf8)
|
2018-04-14 03:09:12 +02:00
|
|
|
import qualified Data.Vector as V
|
|
|
|
import Nix.Atoms
|
|
|
|
import Nix.Effects
|
|
|
|
import Nix.Expr.Types
|
|
|
|
import Nix.Expr.Types.Annotated
|
2018-04-24 11:14:27 +02:00
|
|
|
import Nix.Frames
|
2018-09-23 22:03:44 +02:00
|
|
|
import Nix.String
|
2018-04-14 03:09:12 +02:00
|
|
|
import Nix.Normal
|
|
|
|
import Nix.Thunk
|
2018-04-16 08:00:09 +02:00
|
|
|
import Nix.Utils
|
2018-04-14 03:09:12 +02:00
|
|
|
import Nix.Value
|
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
class FromValue a m v where
|
|
|
|
fromValue :: v -> m a
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay :: v -> m (Maybe a)
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
type Convertible e m = (Framed e m, MonadVar m, Typeable m)
|
2018-04-22 03:18:03 +02:00
|
|
|
|
|
|
|
instance Convertible e m => FromValue () m (NValueNF m) where
|
2018-04-16 08:00:09 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVConstantF NNull) -> pure $ Just ()
|
2018-04-16 08:00:09 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-16 08:00:09 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TNull v
|
2018-04-16 08:00:09 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m
|
|
|
|
=> FromValue () m (NValue m) where
|
2018-04-16 08:00:09 +02:00
|
|
|
fromValueMay = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
NVConstant NNull -> pure $ Just ()
|
2018-04-16 08:00:09 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-16 08:00:09 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TNull v
|
2018-04-16 08:00:09 +02:00
|
|
|
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m
|
2018-04-16 04:05:44 +02:00
|
|
|
=> FromValue Bool m (NValueNF m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVConstantF (NBool b)) -> pure $ Just b
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TBool v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m
|
|
|
|
=> FromValue Bool m (NValue m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
NVConstant (NBool b) -> pure $ Just b
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TBool v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m
|
2018-04-16 04:05:44 +02:00
|
|
|
=> FromValue Int m (NValueNF m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVConstantF (NInt b)) -> pure $ Just (fromInteger b)
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TInt v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m
|
|
|
|
=> FromValue Int m (NValue m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
NVConstant (NInt b) -> pure $ Just (fromInteger b)
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TInt v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m
|
2018-04-16 04:05:44 +02:00
|
|
|
=> FromValue Integer m (NValueNF m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVConstantF (NInt b)) -> pure $ Just b
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TInt v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m
|
|
|
|
=> FromValue Integer m (NValue m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
NVConstant (NInt b) -> pure $ Just b
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TInt v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m
|
2018-04-16 04:05:44 +02:00
|
|
|
=> FromValue Float m (NValueNF m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVConstantF (NFloat b)) -> pure $ Just b
|
|
|
|
Free (NVConstantF (NInt i)) -> pure $ Just (fromInteger i)
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TFloat v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m
|
|
|
|
=> FromValue Float m (NValue m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
NVConstant (NFloat b) -> pure $ Just b
|
|
|
|
NVConstant (NInt i) -> pure $ Just (fromInteger i)
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TFloat v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-22 03:18:03 +02:00
|
|
|
instance (Convertible e m, MonadEffects m)
|
2018-04-16 04:05:44 +02:00
|
|
|
=> FromValue Text m (NValueNF m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVStrF ns) -> pure $ hackyStringIgnoreContextMaybe ns
|
|
|
|
Free (NVPathF p) -> Just . Text.pack . unStorePath <$> addPath p
|
|
|
|
Free (NVSetF s _) -> case M.lookup "outPath" s of
|
2018-04-18 04:10:36 +02:00
|
|
|
Nothing -> pure Nothing
|
2018-04-18 06:49:29 +02:00
|
|
|
Just p -> fromValueMay @Text p
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TString v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m, MonadEffects m)
|
|
|
|
=> FromValue Text m (NValue m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
NVStr ns -> pure $ hackyStringIgnoreContextMaybe ns
|
2018-04-24 11:14:27 +02:00
|
|
|
NVPath p -> Just . Text.pack . unStorePath <$> addPath p
|
|
|
|
NVSet s _ -> case M.lookup "outPath" s of
|
2018-04-18 04:10:36 +02:00
|
|
|
Nothing -> pure Nothing
|
2018-04-18 06:49:29 +02:00
|
|
|
Just p -> fromValueMay @Text p
|
2018-04-16 19:55:57 +02:00
|
|
|
_ -> pure Nothing
|
|
|
|
fromValue v = fromValueMay v >>= \case
|
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TString v
|
2018-04-16 19:56:29 +02:00
|
|
|
|
2018-04-22 03:18:03 +02:00
|
|
|
instance (Convertible e m, MonadEffects m)
|
2018-05-03 14:07:54 +02:00
|
|
|
=> FromValue NixString m (NValueNF m) where
|
2018-04-16 19:56:29 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVStrF ns) -> pure $ Just ns
|
2018-09-16 02:04:54 +02:00
|
|
|
Free (NVPathF p) -> Just . hackyMakeNixStringWithoutContext . Text.pack . unStorePath <$> addPath p
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVSetF s _) -> case M.lookup "outPath" s of
|
2018-04-18 04:10:36 +02:00
|
|
|
Nothing -> pure Nothing
|
2018-09-16 02:04:54 +02:00
|
|
|
Just p -> fmap hackyMakeNixStringWithoutContext <$> fromValueMay @Text p
|
2018-04-16 19:56:29 +02:00
|
|
|
_ -> pure Nothing
|
|
|
|
fromValue v = fromValueMay v >>= \case
|
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TString v
|
2018-04-16 19:56:29 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m, MonadEffects m)
|
2018-05-03 14:07:54 +02:00
|
|
|
=> FromValue NixString m (NValue m) where
|
2018-04-16 19:56:29 +02:00
|
|
|
fromValueMay = \case
|
2018-05-08 22:47:50 +02:00
|
|
|
NVStr ns -> pure $ Just ns
|
2018-09-16 02:04:54 +02:00
|
|
|
NVPath p -> Just . hackyMakeNixStringWithoutContext . Text.pack . unStorePath <$> addPath p
|
2018-04-24 11:14:27 +02:00
|
|
|
NVSet s _ -> case M.lookup "outPath" s of
|
2018-04-18 04:10:36 +02:00
|
|
|
Nothing -> pure Nothing
|
2018-09-16 02:04:54 +02:00
|
|
|
Just p -> fmap hackyMakeNixStringWithoutContext <$> fromValueMay @Text p
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TString v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m
|
2018-04-16 04:05:44 +02:00
|
|
|
=> FromValue ByteString m (NValueNF m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVStrF ns) -> pure $ encodeUtf8 <$> hackyStringIgnoreContextMaybe ns
|
2018-04-15 07:58:50 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-15 07:58:50 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TString v
|
2018-04-15 07:58:50 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m
|
|
|
|
=> FromValue ByteString m (NValue m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
NVStr ns -> pure $ encodeUtf8 <$> hackyStringIgnoreContextMaybe ns
|
2018-04-15 07:58:50 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-15 07:58:50 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TString v
|
2018-04-15 07:58:50 +02:00
|
|
|
|
2018-04-14 03:09:12 +02:00
|
|
|
newtype Path = Path { getPath :: FilePath }
|
|
|
|
deriving Show
|
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m => FromValue Path m (NValueNF m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVPathF p) -> pure $ Just (Path p)
|
|
|
|
Free (NVStrF ns) -> pure $ Path . Text.unpack <$> hackyStringIgnoreContextMaybe ns
|
|
|
|
Free (NVSetF s _) -> case M.lookup "outPath" s of
|
2018-04-18 06:49:29 +02:00
|
|
|
Nothing -> pure Nothing
|
|
|
|
Just p -> fromValueMay @Path p
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TPath v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m)
|
|
|
|
=> FromValue Path m (NValue m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
NVPath p -> pure $ Just (Path p)
|
2018-09-09 17:01:09 +02:00
|
|
|
NVStr ns -> pure $ Path . Text.unpack <$> hackyStringIgnoreContextMaybe ns
|
2018-04-24 11:14:27 +02:00
|
|
|
NVSet s _ -> case M.lookup "outPath" s of
|
2018-04-18 06:49:29 +02:00
|
|
|
Nothing -> pure Nothing
|
|
|
|
Just p -> fromValueMay @Path p
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TPath v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-26 05:46:46 +02:00
|
|
|
instance (Convertible e m, FromValue a m (NValueNF m), Show a)
|
2018-04-16 04:05:44 +02:00
|
|
|
=> FromValue [a] m (NValueNF m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVListF l) -> sequence <$> traverse fromValueMay l
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TList v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m => FromValue [NThunk m] m (NValue m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
NVList l -> pure $ Just l
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TList v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m
|
2018-04-16 04:05:44 +02:00
|
|
|
=> FromValue (HashMap Text (NValueNF m)) m (NValueNF m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVSetF s _) -> pure $ Just s
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TSet v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m
|
|
|
|
=> FromValue (HashMap Text (NThunk m)) m (NValue m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
NVSet s _ -> pure $ Just s
|
2018-04-14 03:09:12 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TSet v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m
|
2018-04-16 04:05:44 +02:00
|
|
|
=> FromValue (HashMap Text (NValueNF m),
|
2018-04-16 01:21:47 +02:00
|
|
|
HashMap Text SourcePos) m (NValueNF m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVSetF s p) -> pure $ Just (s, p)
|
2018-04-15 08:52:21 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-15 08:52:21 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ ExpectationNF TSet v
|
2018-04-15 08:52:21 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m
|
|
|
|
=> FromValue (HashMap Text (NThunk m),
|
|
|
|
HashMap Text SourcePos) m (NValue m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
NVSet s p -> pure $ Just (s, p)
|
2018-04-15 08:52:21 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-15 08:52:21 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TSet v
|
2018-04-15 08:52:21 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m)
|
|
|
|
=> FromValue (NThunk m) m (NValue m) where
|
|
|
|
fromValueMay = pure . Just . value @_ @_ @m
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-15 07:58:50 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> error "Impossible, see fromValueMay"
|
2018-04-15 07:58:50 +02:00
|
|
|
|
2018-04-22 23:32:55 +02:00
|
|
|
instance (Monad m, FromValue a m v) => FromValue a m (m v) where
|
2018-04-17 06:39:41 +02:00
|
|
|
fromValueMay = (>>= fromValueMay)
|
|
|
|
fromValue = (>>= fromValue)
|
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance (MonadThunk (NValue m) (NThunk m) m, FromValue a m (NValue m))
|
2018-04-17 06:39:41 +02:00
|
|
|
=> FromValue a m (NThunk m) where
|
|
|
|
fromValueMay = force ?? fromValueMay
|
|
|
|
fromValue = force ?? fromValue
|
|
|
|
|
2018-04-22 03:18:03 +02:00
|
|
|
instance (Convertible e m, MonadEffects m)
|
2018-04-16 04:05:44 +02:00
|
|
|
=> FromValue A.Value m (NValueNF m) where
|
2018-04-16 05:22:24 +02:00
|
|
|
fromValueMay = \case
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVConstantF a) -> pure $ Just $ case a of
|
2018-04-14 03:09:12 +02:00
|
|
|
NInt n -> toJSON n
|
|
|
|
NFloat n -> toJSON n
|
|
|
|
NBool b -> toJSON b
|
|
|
|
NNull -> A.Null
|
2018-09-09 17:01:09 +02:00
|
|
|
Free (NVStrF ns) -> pure $ toJSON <$> hackyStringIgnoreContextMaybe ns
|
|
|
|
Free (NVListF l) ->
|
|
|
|
fmap (A.Array . V.fromList) . sequence
|
|
|
|
<$> traverse fromValueMay l
|
|
|
|
Free (NVSetF m _) ->
|
|
|
|
fmap A.Object . sequence <$> traverse fromValueMay m
|
|
|
|
Free (NVPathF p) -> Just . toJSON . unStorePath <$> addPath p
|
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromValue v = fromValueMay v >>= \case
|
2018-04-14 03:09:12 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ CoercionToJsonNF v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
class ToValue a m v where
|
|
|
|
toValue :: a -> m v
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-16 08:00:09 +02:00
|
|
|
instance Applicative m => ToValue () m (NValueNF m) where
|
2018-09-09 17:01:09 +02:00
|
|
|
toValue _ = pure . Free . NVConstantF $ NNull
|
2018-04-16 08:00:09 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToValue () m (NValue m) where
|
|
|
|
toValue _ = pure . nvConstant $ NNull
|
2018-04-16 08:00:09 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
instance Applicative m => ToValue Bool m (NValueNF m) where
|
2018-09-09 17:01:09 +02:00
|
|
|
toValue = pure . Free . NVConstantF . NBool
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToValue Bool m (NValue m) where
|
|
|
|
toValue = pure . nvConstant . NBool
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
instance Applicative m => ToValue Int m (NValueNF m) where
|
2018-09-09 17:01:09 +02:00
|
|
|
toValue = pure . Free . NVConstantF . NInt . toInteger
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToValue Int m (NValue m) where
|
|
|
|
toValue = pure . nvConstant . NInt . toInteger
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
instance Applicative m => ToValue Integer m (NValueNF m) where
|
2018-09-09 17:01:09 +02:00
|
|
|
toValue = pure . Free . NVConstantF . NInt
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToValue Integer m (NValue m) where
|
|
|
|
toValue = pure . nvConstant . NInt
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
instance Applicative m => ToValue Float m (NValueNF m) where
|
2018-09-09 17:01:09 +02:00
|
|
|
toValue = pure . Free . NVConstantF . NFloat
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToValue Float m (NValue m) where
|
|
|
|
toValue = pure . nvConstant . NFloat
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
instance Applicative m => ToValue Text m (NValueNF m) where
|
2018-09-16 02:04:54 +02:00
|
|
|
toValue = pure . Free . NVStrF . hackyMakeNixStringWithoutContext
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToValue Text m (NValue m) where
|
2018-09-16 02:04:54 +02:00
|
|
|
toValue = pure . nvStr . hackyMakeNixStringWithoutContext
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-05-03 14:07:54 +02:00
|
|
|
instance Applicative m => ToValue NixString m (NValueNF m) where
|
2018-09-09 17:01:09 +02:00
|
|
|
toValue = pure . Free . NVStrF
|
2018-04-16 19:56:29 +02:00
|
|
|
|
2018-05-03 14:07:54 +02:00
|
|
|
instance Applicative m => ToValue NixString m (NValue m) where
|
2018-05-08 22:47:50 +02:00
|
|
|
toValue = pure . nvStr
|
2018-04-16 19:56:29 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
instance Applicative m => ToValue ByteString m (NValueNF m) where
|
2018-09-16 02:04:54 +02:00
|
|
|
toValue = pure . Free . NVStrF . hackyMakeNixStringWithoutContext . decodeUtf8
|
2018-04-15 07:58:50 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToValue ByteString m (NValue m) where
|
2018-09-16 02:04:54 +02:00
|
|
|
toValue = pure . nvStr . hackyMakeNixStringWithoutContext . decodeUtf8
|
2018-04-15 07:58:50 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
instance Applicative m => ToValue Path m (NValueNF m) where
|
2018-09-09 17:01:09 +02:00
|
|
|
toValue = pure . Free . NVPathF . getPath
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToValue Path m (NValue m) where
|
|
|
|
toValue = pure . nvPath . getPath
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-22 23:32:55 +02:00
|
|
|
instance MonadThunk (NValue m) (NThunk m) m
|
2018-04-24 11:14:27 +02:00
|
|
|
=> ToValue SourcePos m (NValue m) where
|
2018-04-16 04:05:44 +02:00
|
|
|
toValue (SourcePos f l c) = do
|
2018-04-24 11:14:27 +02:00
|
|
|
f' <- toValue (Text.pack f)
|
|
|
|
l' <- toValue (unPos l)
|
|
|
|
c' <- toValue (unPos c)
|
2018-04-16 01:21:47 +02:00
|
|
|
let pos = M.fromList
|
2018-04-15 10:43:01 +02:00
|
|
|
[ ("file" :: Text, value @_ @_ @m f')
|
|
|
|
, ("line", value @_ @_ @m l')
|
|
|
|
, ("column", value @_ @_ @m c') ]
|
2018-04-24 11:14:27 +02:00
|
|
|
pure $ nvSet pos mempty
|
2018-04-15 08:52:21 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
instance (ToValue a m (NValueNF m), Applicative m)
|
|
|
|
=> ToValue [a] m (NValueNF m) where
|
2018-09-09 17:01:09 +02:00
|
|
|
toValue = fmap (Free . NVListF) . traverse toValue
|
2018-04-15 10:43:01 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToValue [NThunk m] m (NValue m) where
|
|
|
|
toValue = pure . nvList
|
2018-04-15 10:43:01 +02:00
|
|
|
|
2018-04-16 01:21:47 +02:00
|
|
|
instance Applicative m
|
2018-04-16 04:05:44 +02:00
|
|
|
=> ToValue (HashMap Text (NValueNF m)) m (NValueNF m) where
|
2018-09-09 17:01:09 +02:00
|
|
|
toValue = pure . Free . flip NVSetF M.empty
|
2018-04-15 08:52:21 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToValue (HashMap Text (NThunk m)) m (NValue m) where
|
|
|
|
toValue = pure . flip nvSet M.empty
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
instance Applicative m => ToValue (HashMap Text (NValueNF m),
|
2018-04-16 01:21:47 +02:00
|
|
|
HashMap Text SourcePos) m (NValueNF m) where
|
2018-09-09 17:01:09 +02:00
|
|
|
toValue (s, p) = pure $ Free $ NVSetF s p
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToValue (HashMap Text (NThunk m),
|
|
|
|
HashMap Text SourcePos) m (NValue m) where
|
|
|
|
toValue (s, p) = pure $ nvSet s p
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
instance (MonadThunk (NValue m) (NThunk m) m, ToValue a m (NValue m))
|
|
|
|
=> ToValue a m (NThunk m) where
|
|
|
|
toValue = fmap (value @(NValue m) @_ @m) . toValue
|
2018-04-14 03:09:12 +02:00
|
|
|
|
2018-04-16 04:05:44 +02:00
|
|
|
instance Applicative m => ToValue Bool m (NExprF r) where
|
|
|
|
toValue = pure . NConstant . NBool
|
2018-04-15 07:58:50 +02:00
|
|
|
|
2018-04-16 08:00:09 +02:00
|
|
|
instance Applicative m => ToValue () m (NExprF r) where
|
|
|
|
toValue _ = pure . NConstant $ NNull
|
|
|
|
|
2018-05-02 02:33:17 +02:00
|
|
|
whileForcingThunk :: forall s e m r. (Framed e m, Exception s, Typeable m)
|
2018-04-24 20:12:20 +02:00
|
|
|
=> s -> m r -> m r
|
|
|
|
whileForcingThunk frame =
|
|
|
|
withFrame Debug (ForcingThunk @m) . withFrame Debug frame
|
2018-04-24 11:14:27 +02:00
|
|
|
|
|
|
|
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m)
|
|
|
|
=> ToValue A.Value m (NValue m) where
|
2018-04-16 04:05:44 +02:00
|
|
|
toValue = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
A.Object m -> flip nvSet M.empty
|
|
|
|
<$> traverse (thunk . toValue @_ @_ @(NValue m)) m
|
|
|
|
A.Array l -> nvList <$>
|
2018-04-24 20:12:20 +02:00
|
|
|
traverse (\x -> thunk . whileForcingThunk (CoercionFromJson @m x)
|
2018-04-24 11:14:27 +02:00
|
|
|
. toValue $ x) (V.toList l)
|
2018-09-16 02:04:54 +02:00
|
|
|
A.String s -> pure $ nvStr $ hackyMakeNixStringWithoutContext s
|
2018-04-24 11:14:27 +02:00
|
|
|
A.Number n -> pure $ nvConstant $ case floatingOrInteger n of
|
2018-04-15 07:58:50 +02:00
|
|
|
Left r -> NFloat r
|
|
|
|
Right i -> NInt i
|
2018-04-24 11:14:27 +02:00
|
|
|
A.Bool b -> pure $ nvConstant $ NBool b
|
|
|
|
A.Null -> pure $ nvConstant NNull
|
2018-04-16 05:43:04 +02:00
|
|
|
|
|
|
|
class FromNix a m v where
|
|
|
|
fromNix :: v -> m a
|
|
|
|
default fromNix :: FromValue a m v => v -> m a
|
|
|
|
fromNix = fromValue
|
|
|
|
|
|
|
|
fromNixMay :: v -> m (Maybe a)
|
|
|
|
default fromNixMay :: FromValue a m v => v -> m (Maybe a)
|
|
|
|
fromNixMay = fromValueMay
|
|
|
|
|
2018-04-22 23:32:55 +02:00
|
|
|
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m,
|
2018-04-24 11:14:27 +02:00
|
|
|
FromNix a m (NValue m))
|
|
|
|
=> FromNix [a] m (NValue m) where
|
2018-04-16 05:43:04 +02:00
|
|
|
fromNixMay = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
NVList l -> sequence <$> traverse (`force` fromNixMay) l
|
2018-04-16 05:43:04 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromNix v = fromNixMay v >>= \case
|
2018-04-16 05:43:04 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TList v
|
2018-04-16 05:43:04 +02:00
|
|
|
|
2018-04-22 23:32:55 +02:00
|
|
|
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m,
|
2018-04-24 11:14:27 +02:00
|
|
|
FromNix a m (NValue m))
|
|
|
|
=> FromNix (HashMap Text a) m (NValue m) where
|
2018-04-16 05:43:04 +02:00
|
|
|
fromNixMay = \case
|
2018-04-24 11:14:27 +02:00
|
|
|
NVSet s _ -> sequence <$> traverse (`force` fromNixMay) s
|
2018-04-16 05:43:04 +02:00
|
|
|
_ -> pure Nothing
|
2018-04-16 19:54:55 +02:00
|
|
|
fromNix v = fromNixMay v >>= \case
|
2018-04-16 05:43:04 +02:00
|
|
|
Just b -> pure b
|
2018-04-24 11:14:27 +02:00
|
|
|
_ -> throwError $ Expectation TSet v
|
2018-04-16 05:43:04 +02:00
|
|
|
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m => FromNix () m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m => FromNix () m (NValue m) where
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m => FromNix Bool m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m => FromNix Bool m (NValue m) where
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m => FromNix Int m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m => FromNix Int m (NValue m) where
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m => FromNix Integer m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m => FromNix Integer m (NValue m) where
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m => FromNix Float m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m => FromNix Float m (NValue m) where
|
2018-04-22 03:18:03 +02:00
|
|
|
instance (Convertible e m, MonadEffects m) => FromNix Text m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance (Convertible e m, MonadEffects m, MonadThunk (NValue m) (NThunk m) m) => FromNix Text m (NValue m) where
|
2018-05-03 14:07:54 +02:00
|
|
|
instance (Convertible e m, MonadEffects m) => FromNix NixString m (NValueNF m) where
|
|
|
|
instance (Convertible e m, MonadEffects m, MonadThunk (NValue m) (NThunk m) m) => FromNix NixString m (NValue m) where
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m => FromNix ByteString m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m => FromNix ByteString m (NValue m) where
|
2018-04-22 03:18:03 +02:00
|
|
|
instance Convertible e m => FromNix Path m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m) => FromNix Path m (NValue m) where
|
2018-04-22 03:18:03 +02:00
|
|
|
instance (Convertible e m, FromValue a m (NValueNF m), Show a) => FromNix [a] m (NValueNF m) where
|
|
|
|
instance Convertible e m => FromNix (HashMap Text (NValueNF m)) m (NValueNF m) where
|
|
|
|
instance Convertible e m => FromNix (HashMap Text (NValueNF m), HashMap Text SourcePos) m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Convertible e m => FromNix (HashMap Text (NThunk m), HashMap Text SourcePos) m (NValue m) where
|
2018-04-22 23:32:55 +02:00
|
|
|
instance (Convertible e m, MonadEffects m, MonadThunk (NValue m) (NThunk m) m) => FromNix A.Value m (NValueNF m) where
|
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance (Convertible e m, MonadEffects m,
|
2018-09-09 17:01:09 +02:00
|
|
|
MonadThunk (NValue m) (NThunk m) m)
|
|
|
|
=> FromNix A.Value m (NValue m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
fromNixMay = fromNixMay <=< normalForm
|
|
|
|
fromNix = fromNix <=< normalForm
|
2018-04-22 03:18:03 +02:00
|
|
|
|
2018-04-22 23:32:55 +02:00
|
|
|
instance (Monad m, FromNix a m v) => FromNix a m (m v) where
|
2018-04-17 06:39:41 +02:00
|
|
|
fromNixMay = (>>= fromNixMay)
|
|
|
|
fromNix = (>>= fromNix)
|
|
|
|
|
2018-04-22 23:32:55 +02:00
|
|
|
instance (MonadThunk (NValue m) (NThunk m) m, FromNix a m (NValue m))
|
|
|
|
=> FromNix a m (NThunk m) where
|
2018-04-16 08:00:09 +02:00
|
|
|
fromNixMay = force ?? fromNixMay
|
|
|
|
fromNix = force ?? fromNix
|
|
|
|
|
2018-04-22 23:32:55 +02:00
|
|
|
instance MonadThunk (NValue m) (NThunk m) m
|
2018-04-24 11:14:27 +02:00
|
|
|
=> FromNix (NThunk m) m (NValue m) where
|
|
|
|
fromNixMay = pure . Just . value
|
|
|
|
fromNix = pure . value
|
2018-04-22 23:32:55 +02:00
|
|
|
|
2018-04-16 05:43:04 +02:00
|
|
|
class ToNix a m v where
|
|
|
|
toNix :: a -> m v
|
|
|
|
default toNix :: ToValue a m v => a -> m v
|
|
|
|
toNix = toValue
|
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m,
|
|
|
|
ToNix a m (NValue m))
|
|
|
|
=> ToNix [a] m (NValue m) where
|
|
|
|
toNix = fmap nvList
|
|
|
|
. traverse (thunk . ((\v -> whileForcingThunk (ConcerningValue v) (pure v))
|
|
|
|
<=< toNix))
|
|
|
|
|
|
|
|
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m,
|
|
|
|
ToNix a m (NValue m))
|
|
|
|
=> ToNix (HashMap Text a) m (NValue m) where
|
|
|
|
toNix = fmap (flip nvSet M.empty)
|
|
|
|
. traverse (thunk . ((\v -> whileForcingThunk (ConcerningValue v) (pure v))
|
|
|
|
<=< toNix))
|
2018-04-16 05:43:04 +02:00
|
|
|
|
2018-04-16 08:00:09 +02:00
|
|
|
instance Applicative m => ToNix () m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToNix () m (NValue m) where
|
2018-04-16 05:43:04 +02:00
|
|
|
instance Applicative m => ToNix Bool m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToNix Bool m (NValue m) where
|
2018-04-16 05:43:04 +02:00
|
|
|
instance Applicative m => ToNix Int m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToNix Int m (NValue m) where
|
2018-04-16 05:43:04 +02:00
|
|
|
instance Applicative m => ToNix Integer m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToNix Integer m (NValue m) where
|
2018-04-16 05:43:04 +02:00
|
|
|
instance Applicative m => ToNix Float m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToNix Float m (NValue m) where
|
2018-04-16 05:43:04 +02:00
|
|
|
instance Applicative m => ToNix Text m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToNix Text m (NValue m) where
|
2018-05-03 14:07:54 +02:00
|
|
|
instance Applicative m => ToNix NixString m (NValueNF m) where
|
|
|
|
instance Applicative m => ToNix NixString m (NValue m) where
|
2018-04-16 05:43:04 +02:00
|
|
|
instance Applicative m => ToNix ByteString m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToNix ByteString m (NValue m) where
|
2018-04-16 05:43:04 +02:00
|
|
|
instance Applicative m => ToNix Path m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToNix Path m (NValue m) where
|
2018-04-16 05:43:04 +02:00
|
|
|
instance Applicative m => ToNix (HashMap Text (NValueNF m)) m (NValueNF m) where
|
|
|
|
instance Applicative m => ToNix (HashMap Text (NValueNF m), HashMap Text SourcePos) m (NValueNF m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
instance Applicative m => ToNix (HashMap Text (NThunk m), HashMap Text SourcePos) m (NValue m) where
|
|
|
|
instance (Convertible e m, MonadThunk (NValue m) (NThunk m) m) => ToNix A.Value m (NValue m) where
|
2018-04-16 05:43:04 +02:00
|
|
|
instance Applicative m => ToNix Bool m (NExprF r) where
|
2018-04-16 08:00:09 +02:00
|
|
|
instance Applicative m => ToNix () m (NExprF r) where
|
|
|
|
|
2018-04-24 11:14:27 +02:00
|
|
|
instance (MonadThunk (NValue m) (NThunk m) m, ToNix a m (NValue m))
|
2018-04-22 23:32:55 +02:00
|
|
|
=> ToNix a m (NThunk m) where
|
2018-04-24 11:14:27 +02:00
|
|
|
toNix = thunk . toNix
|
2018-04-22 23:32:55 +02:00
|
|
|
|
|
|
|
instance (Applicative m, ToNix a m (NValueNF m)) => ToNix [a] m (NValueNF m) where
|
2018-09-09 17:01:09 +02:00
|
|
|
toNix = fmap (Free . NVListF) . traverse toNix
|
2018-04-22 23:32:55 +02:00
|
|
|
|
|
|
|
instance MonadThunk (NValue m) (NThunk m) m => ToNix (NThunk m) m (NValue m) where
|
2018-04-16 08:00:09 +02:00
|
|
|
toNix = force ?? pure
|
2018-04-26 05:22:31 +02:00
|
|
|
|
|
|
|
convertNix :: forall a t m v. (FromNix a m t, ToNix a m v, Monad m) => t -> m v
|
|
|
|
convertNix = fromNix @a >=> toNix
|