{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

{-# OPTIONS_GHC -fno-warn-name-shadowing #-}

-- | 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

module Nix.Convert where

import           Prelude                 hiding ( force )
import           Control.Monad.Free
import qualified Data.HashMap.Lazy             as M
import           Nix.Atoms
import           Nix.Effects
import           Nix.Expr.Types
import           Nix.Expr.Types.Annotated
import           Nix.Frames
import           Nix.String
import           Nix.Value
import           Nix.Value.Monad
import           Nix.Thunk
import           Nix.Utils

newtype Deeper a = Deeper { Deeper a -> a
getDeeper :: a }
  deriving (Typeable, a -> Deeper b -> Deeper a
(a -> b) -> Deeper a -> Deeper b
(forall a b. (a -> b) -> Deeper a -> Deeper b)
-> (forall a b. a -> Deeper b -> Deeper a) -> Functor Deeper
forall a b. a -> Deeper b -> Deeper a
forall a b. (a -> b) -> Deeper a -> Deeper b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Deeper b -> Deeper a
$c<$ :: forall a b. a -> Deeper b -> Deeper a
fmap :: (a -> b) -> Deeper a -> Deeper b
$cfmap :: forall a b. (a -> b) -> Deeper a -> Deeper b
Functor, Deeper a -> Bool
(a -> m) -> Deeper a -> m
(a -> b -> b) -> b -> Deeper a -> b
(forall m. Monoid m => Deeper m -> m)
-> (forall m a. Monoid m => (a -> m) -> Deeper a -> m)
-> (forall m a. Monoid m => (a -> m) -> Deeper a -> m)
-> (forall a b. (a -> b -> b) -> b -> Deeper a -> b)
-> (forall a b. (a -> b -> b) -> b -> Deeper a -> b)
-> (forall b a. (b -> a -> b) -> b -> Deeper a -> b)
-> (forall b a. (b -> a -> b) -> b -> Deeper a -> b)
-> (forall a. (a -> a -> a) -> Deeper a -> a)
-> (forall a. (a -> a -> a) -> Deeper a -> a)
-> (forall a. Deeper a -> [a])
-> (forall a. Deeper a -> Bool)
-> (forall a. Deeper a -> Int)
-> (forall a. Eq a => a -> Deeper a -> Bool)
-> (forall a. Ord a => Deeper a -> a)
-> (forall a. Ord a => Deeper a -> a)
-> (forall a. Num a => Deeper a -> a)
-> (forall a. Num a => Deeper a -> a)
-> Foldable Deeper
forall a. Eq a => a -> Deeper a -> Bool
forall a. Num a => Deeper a -> a
forall a. Ord a => Deeper a -> a
forall m. Monoid m => Deeper m -> m
forall a. Deeper a -> Bool
forall a. Deeper a -> Int
forall a. Deeper a -> [a]
forall a. (a -> a -> a) -> Deeper a -> a
forall m a. Monoid m => (a -> m) -> Deeper a -> m
forall b a. (b -> a -> b) -> b -> Deeper a -> b
forall a b. (a -> b -> b) -> b -> Deeper a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: Deeper a -> a
$cproduct :: forall a. Num a => Deeper a -> a
sum :: Deeper a -> a
$csum :: forall a. Num a => Deeper a -> a
minimum :: Deeper a -> a
$cminimum :: forall a. Ord a => Deeper a -> a
maximum :: Deeper a -> a
$cmaximum :: forall a. Ord a => Deeper a -> a
elem :: a -> Deeper a -> Bool
$celem :: forall a. Eq a => a -> Deeper a -> Bool
length :: Deeper a -> Int
$clength :: forall a. Deeper a -> Int
null :: Deeper a -> Bool
$cnull :: forall a. Deeper a -> Bool
toList :: Deeper a -> [a]
$ctoList :: forall a. Deeper a -> [a]
foldl1 :: (a -> a -> a) -> Deeper a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Deeper a -> a
foldr1 :: (a -> a -> a) -> Deeper a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Deeper a -> a
foldl' :: (b -> a -> b) -> b -> Deeper a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Deeper a -> b
foldl :: (b -> a -> b) -> b -> Deeper a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Deeper a -> b
foldr' :: (a -> b -> b) -> b -> Deeper a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Deeper a -> b
foldr :: (a -> b -> b) -> b -> Deeper a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Deeper a -> b
foldMap' :: (a -> m) -> Deeper a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Deeper a -> m
foldMap :: (a -> m) -> Deeper a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Deeper a -> m
fold :: Deeper m -> m
$cfold :: forall m. Monoid m => Deeper m -> m
Foldable, Functor Deeper
Foldable Deeper
Functor Deeper
-> Foldable Deeper
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Deeper a -> f (Deeper b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Deeper (f a) -> f (Deeper a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Deeper a -> m (Deeper b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Deeper (m a) -> m (Deeper a))
-> Traversable Deeper
(a -> f b) -> Deeper a -> f (Deeper b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Deeper (m a) -> m (Deeper a)
forall (f :: * -> *) a.
Applicative f =>
Deeper (f a) -> f (Deeper a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Deeper a -> m (Deeper b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Deeper a -> f (Deeper b)
sequence :: Deeper (m a) -> m (Deeper a)
$csequence :: forall (m :: * -> *) a. Monad m => Deeper (m a) -> m (Deeper a)
mapM :: (a -> m b) -> Deeper a -> m (Deeper b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Deeper a -> m (Deeper b)
sequenceA :: Deeper (f a) -> f (Deeper a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Deeper (f a) -> f (Deeper a)
traverse :: (a -> f b) -> Deeper a -> f (Deeper b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Deeper a -> f (Deeper b)
$cp2Traversable :: Foldable Deeper
$cp1Traversable :: Functor Deeper
Traversable)

{-

IMPORTANT NOTE

We used to have Text instances of FromValue, ToValue, FromNix, and ToNix.
However, we're removing these instances because they are dangerous due to the
fact that they hide the way string contexts are handled. It's better to have to
explicitly handle string context in a way that is appropriate for the situation.

Do not add these instances back!

-}


-- * FromValue

class FromValue a m v where
  fromValue    :: v -> m a
  fromValueMay :: v -> m (Maybe a)


-- Please, hide these helper function from export, to be sure they get optimized away.
fromMayToValue
  :: forall t f m a e
  . ( Convertible e t f m
    , FromValue a m (NValue' t f m (NValue t f m))
    )
  => ValueType
  -> NValue' t f m (NValue t f m)
  -> m a
fromMayToValue :: ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue ValueType
t NValue' t f m (NValue t f m)
v =
  do
    Maybe a
v' <- NValue' t f m (NValue t f m) -> m (Maybe a)
forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
fromValueMay NValue' t f m (NValue t f m)
v
    m a -> (a -> m a) -> Maybe a -> m a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
      (ValueFrame t f m -> m a
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ValueFrame t f m -> m a) -> ValueFrame t f m -> m a
forall a b. (a -> b) -> a -> b
$ ValueType -> NValue t f m -> ValueFrame t f m
forall t (f :: * -> *) (m :: * -> *).
ValueType -> NValue t f m -> ValueFrame t f m
Expectation @t @f @m ValueType
t (NValue' t f m (NValue t f m) -> NValue t f m
forall (f :: * -> *) a. f (Free f a) -> Free f a
Free NValue' t f m (NValue t f m)
v))
      a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
      Maybe a
v'

fromMayToDeeperValue
  :: forall t f m a e m1
  . ( Convertible e t f m
    , FromValue (m1 a) m (Deeper (NValue' t f m (NValue t f m)))
    )
  => ValueType
  -> Deeper (NValue' t f m (NValue t f m))
  -> m (m1 a)
fromMayToDeeperValue :: ValueType -> Deeper (NValue' t f m (NValue t f m)) -> m (m1 a)
fromMayToDeeperValue ValueType
t Deeper (NValue' t f m (NValue t f m))
v =
  do
    Maybe (m1 a)
v' <- Deeper (NValue' t f m (NValue t f m)) -> m (Maybe (m1 a))
forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
fromValueMay Deeper (NValue' t f m (NValue t f m))
v
    m (m1 a) -> (m1 a -> m (m1 a)) -> Maybe (m1 a) -> m (m1 a)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
      (ValueFrame t f m -> m (m1 a)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ValueFrame t f m -> m (m1 a)) -> ValueFrame t f m -> m (m1 a)
forall a b. (a -> b) -> a -> b
$ ValueType -> NValue t f m -> ValueFrame t f m
forall t (f :: * -> *) (m :: * -> *).
ValueType -> NValue t f m -> ValueFrame t f m
Expectation @t @f @m ValueType
t (NValue' t f m (NValue t f m) -> NValue t f m
forall (f :: * -> *) a. f (Free f a) -> Free f a
Free (NValue' t f m (NValue t f m) -> NValue t f m)
-> NValue' t f m (NValue t f m) -> NValue t f m
forall a b. (a -> b) -> a -> b
$ Deeper (NValue' t f m (NValue t f m))
-> NValue' t f m (NValue t f m)
forall a. Deeper a -> a
getDeeper Deeper (NValue' t f m (NValue t f m))
v))
      m1 a -> m (m1 a)
forall (f :: * -> *) a. Applicative f => a -> f a
pure
      Maybe (m1 a)
v'

type Convertible e t f m
  = (Framed e m, MonadDataErrorContext t f m, MonadThunk t m (NValue t f m))

instance ( Convertible e t f m
         , MonadValue (NValue t f m) m
         , FromValue a m (NValue' t f m (NValue t f m))
         )
  => FromValue a m (NValue t f m) where

  fromValueMay :: NValue t f m -> m (Maybe a)
fromValueMay =
    (t -> m (Maybe a))
-> (NValue' t f m (NValue t f m) -> m (Maybe a))
-> NValue t f m
-> m (Maybe a)
forall a b (f :: * -> *).
(a -> b) -> (f (Free f a) -> b) -> Free f a -> b
free
      (NValue t f m -> m (Maybe a)
forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
fromValueMay (NValue t f m -> m (Maybe a))
-> (t -> m (NValue t f m)) -> t -> m (Maybe a)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< t -> m (NValue t f m)
forall t (m :: * -> *) a. MonadThunk t m a => t -> m a
force)
      NValue' t f m (NValue t f m) -> m (Maybe a)
forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
fromValueMay
      (NValue t f m -> m (Maybe a))
-> (NValue t f m -> m (NValue t f m))
-> NValue t f m
-> m (Maybe a)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< NValue t f m -> m (NValue t f m)
forall v (m :: * -> *). MonadValue v m => v -> m v
demand

  fromValue :: NValue t f m -> m a
fromValue =
    (t -> m a)
-> (NValue' t f m (NValue t f m) -> m a) -> NValue t f m -> m a
forall a b (f :: * -> *).
(a -> b) -> (f (Free f a) -> b) -> Free f a -> b
free
      (NValue t f m -> m a
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m a) -> (t -> m (NValue t f m)) -> t -> m a
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< t -> m (NValue t f m)
forall t (m :: * -> *) a. MonadThunk t m a => t -> m a
force)
      NValue' t f m (NValue t f m) -> m a
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue
      (NValue t f m -> m a)
-> (NValue t f m -> m (NValue t f m)) -> NValue t f m -> m a
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< NValue t f m -> m (NValue t f m)
forall v (m :: * -> *). MonadValue v m => v -> m v
demand

instance ( Convertible e t f m
         , MonadValue (NValue t f m) m
         , FromValue a m (Deeper (NValue' t f m (NValue t f m)))
         )
  => FromValue a m (Deeper (NValue t f m)) where

  fromValueMay :: Deeper (NValue t f m) -> m (Maybe a)
fromValueMay (Deeper NValue t f m
v) =
    (t -> m (Maybe a))
-> (NValue' t f m (NValue t f m) -> m (Maybe a))
-> NValue t f m
-> m (Maybe a)
forall a b (f :: * -> *).
(a -> b) -> (f (Free f a) -> b) -> Free f a -> b
free
      ((Deeper (NValue t f m) -> m (Maybe a)
forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
fromValueMay (Deeper (NValue t f m) -> m (Maybe a))
-> (NValue t f m -> Deeper (NValue t f m))
-> NValue t f m
-> m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NValue t f m -> Deeper (NValue t f m)
forall a. a -> Deeper a
Deeper) (NValue t f m -> m (Maybe a))
-> (t -> m (NValue t f m)) -> t -> m (Maybe a)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< t -> m (NValue t f m)
forall t (m :: * -> *) a. MonadThunk t m a => t -> m a
force)
      (Deeper (NValue' t f m (NValue t f m)) -> m (Maybe a)
forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
fromValueMay (Deeper (NValue' t f m (NValue t f m)) -> m (Maybe a))
-> (NValue' t f m (NValue t f m)
    -> Deeper (NValue' t f m (NValue t f m)))
-> NValue' t f m (NValue t f m)
-> m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NValue' t f m (NValue t f m)
-> Deeper (NValue' t f m (NValue t f m))
forall a. a -> Deeper a
Deeper)
      (NValue t f m -> m (Maybe a)) -> m (NValue t f m) -> m (Maybe a)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< NValue t f m -> m (NValue t f m)
forall v (m :: * -> *). MonadValue v m => v -> m v
demand NValue t f m
v

  fromValue :: Deeper (NValue t f m) -> m a
fromValue (Deeper NValue t f m
v) =
    (t -> m a)
-> (NValue' t f m (NValue t f m) -> m a) -> NValue t f m -> m a
forall a b (f :: * -> *).
(a -> b) -> (f (Free f a) -> b) -> Free f a -> b
free
      ((Deeper (NValue t f m) -> m a
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (Deeper (NValue t f m) -> m a)
-> (NValue t f m -> Deeper (NValue t f m)) -> NValue t f m -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NValue t f m -> Deeper (NValue t f m)
forall a. a -> Deeper a
Deeper) (NValue t f m -> m a) -> (t -> m (NValue t f m)) -> t -> m a
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< t -> m (NValue t f m)
forall t (m :: * -> *) a. MonadThunk t m a => t -> m a
force)
      (Deeper (NValue' t f m (NValue t f m)) -> m a
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (Deeper (NValue' t f m (NValue t f m)) -> m a)
-> (NValue' t f m (NValue t f m)
    -> Deeper (NValue' t f m (NValue t f m)))
-> NValue' t f m (NValue t f m)
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NValue' t f m (NValue t f m)
-> Deeper (NValue' t f m (NValue t f m))
forall a. a -> Deeper a
Deeper)
      (NValue t f m -> m a) -> m (NValue t f m) -> m a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< NValue t f m -> m (NValue t f m)
forall v (m :: * -> *). MonadValue v m => v -> m v
demand NValue t f m
v

instance Convertible e t f m
  => FromValue () m (NValue' t f m (NValue t f m)) where

  fromValueMay :: NValue' t f m (NValue t f m) -> m (Maybe ())
fromValueMay =
    Maybe () -> m (Maybe ())
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe () -> m (Maybe ()))
-> (NValue' t f m (NValue t f m) -> Maybe ())
-> NValue' t f m (NValue t f m)
-> m (Maybe ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      \case
        NVConstant' NAtom
NNull -> Maybe ()
forall (f :: * -> *). Applicative f => f ()
pass
        NValue' t f m (NValue t f m)
_                 -> Maybe ()
forall a. Monoid a => a
mempty

  fromValue :: NValue' t f m (NValue t f m) -> m ()
fromValue = ValueType -> NValue' t f m (NValue t f m) -> m ()
forall t (f :: * -> *) (m :: * -> *) a e.
(Convertible e t f m,
 FromValue a m (NValue' t f m (NValue t f m))) =>
ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue ValueType
TNull

instance Convertible e t f m
  => FromValue Bool m (NValue' t f m (NValue t f m)) where

  fromValueMay :: NValue' t f m (NValue t f m) -> m (Maybe Bool)
fromValueMay =
    Maybe Bool -> m (Maybe Bool)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Bool -> m (Maybe Bool))
-> (NValue' t f m (NValue t f m) -> Maybe Bool)
-> NValue' t f m (NValue t f m)
-> m (Maybe Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      \case
        NVConstant' (NBool Bool
b) -> Bool -> Maybe Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
b
        NValue' t f m (NValue t f m)
_                     -> Maybe Bool
forall a. Maybe a
Nothing

  fromValue :: NValue' t f m (NValue t f m) -> m Bool
fromValue = ValueType -> NValue' t f m (NValue t f m) -> m Bool
forall t (f :: * -> *) (m :: * -> *) a e.
(Convertible e t f m,
 FromValue a m (NValue' t f m (NValue t f m))) =>
ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue ValueType
TBool

instance Convertible e t f m
  => FromValue Int m (NValue' t f m (NValue t f m)) where

  fromValueMay :: NValue' t f m (NValue t f m) -> m (Maybe Int)
fromValueMay =
    Maybe Int -> m (Maybe Int)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Int -> m (Maybe Int))
-> (NValue' t f m (NValue t f m) -> Maybe Int)
-> NValue' t f m (NValue t f m)
-> m (Maybe Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      \case
        NVConstant' (NInt Integer
b) -> Int -> Maybe Int
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Integer -> Int
forall a. Num a => Integer -> a
fromInteger Integer
b)
        NValue' t f m (NValue t f m)
_                    -> Maybe Int
forall a. Maybe a
Nothing

  fromValue :: NValue' t f m (NValue t f m) -> m Int
fromValue = ValueType -> NValue' t f m (NValue t f m) -> m Int
forall t (f :: * -> *) (m :: * -> *) a e.
(Convertible e t f m,
 FromValue a m (NValue' t f m (NValue t f m))) =>
ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue ValueType
TInt

instance Convertible e t f m
  => FromValue Integer m (NValue' t f m (NValue t f m)) where

  fromValueMay :: NValue' t f m (NValue t f m) -> m (Maybe Integer)
fromValueMay =
    Maybe Integer -> m (Maybe Integer)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Integer -> m (Maybe Integer))
-> (NValue' t f m (NValue t f m) -> Maybe Integer)
-> NValue' t f m (NValue t f m)
-> m (Maybe Integer)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      \case
        NVConstant' (NInt Integer
b) -> Integer -> Maybe Integer
forall (f :: * -> *) a. Applicative f => a -> f a
pure Integer
b
        NValue' t f m (NValue t f m)
_                    -> Maybe Integer
forall a. Maybe a
Nothing

  fromValue :: NValue' t f m (NValue t f m) -> m Integer
fromValue = ValueType -> NValue' t f m (NValue t f m) -> m Integer
forall t (f :: * -> *) (m :: * -> *) a e.
(Convertible e t f m,
 FromValue a m (NValue' t f m (NValue t f m))) =>
ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue ValueType
TInt

instance Convertible e t f m
  => FromValue Float m (NValue' t f m (NValue t f m)) where

  fromValueMay :: NValue' t f m (NValue t f m) -> m (Maybe Float)
fromValueMay =
    Maybe Float -> m (Maybe Float)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Float -> m (Maybe Float))
-> (NValue' t f m (NValue t f m) -> Maybe Float)
-> NValue' t f m (NValue t f m)
-> m (Maybe Float)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      \case
        NVConstant' (NFloat Float
b) -> Float -> Maybe Float
forall (f :: * -> *) a. Applicative f => a -> f a
pure Float
b
        NVConstant' (NInt   Integer
i) -> Float -> Maybe Float
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
i)
        NValue' t f m (NValue t f m)
_                      -> Maybe Float
forall a. Maybe a
Nothing

  fromValue :: NValue' t f m (NValue t f m) -> m Float
fromValue = ValueType -> NValue' t f m (NValue t f m) -> m Float
forall t (f :: * -> *) (m :: * -> *) a e.
(Convertible e t f m,
 FromValue a m (NValue' t f m (NValue t f m))) =>
ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue ValueType
TFloat

instance ( Convertible e t f m
         , MonadValue (NValue t f m) m
         , MonadEffects t f m
         )
  => FromValue NixString m (NValue' t f m (NValue t f m)) where

  fromValueMay :: NValue' t f m (NValue t f m) -> m (Maybe NixString)
fromValueMay =
    \case
      NVStr' NixString
ns -> Maybe NixString -> m (Maybe NixString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe NixString -> m (Maybe NixString))
-> Maybe NixString -> m (Maybe NixString)
forall a b. (a -> b) -> a -> b
$ NixString -> Maybe NixString
forall (f :: * -> *) a. Applicative f => a -> f a
pure NixString
ns
      NVPath' FilePath
p ->
        (StorePath -> Maybe NixString)
-> m StorePath -> m (Maybe NixString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
          (NixString -> Maybe NixString
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NixString -> Maybe NixString)
-> (StorePath -> NixString) -> StorePath -> Maybe NixString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\Text
s -> Text -> StringContext -> NixString
makeNixStringWithSingletonContext Text
s (Text -> ContextFlavor -> StringContext
StringContext Text
s ContextFlavor
DirectPath)) (Text -> NixString)
-> (StorePath -> Text) -> StorePath -> NixString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
forall a. ToText a => a -> Text
toText (FilePath -> Text) -> (StorePath -> FilePath) -> StorePath -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StorePath -> FilePath
unStorePath)
          (FilePath -> m StorePath
forall e (m :: * -> *).
(Framed e m, MonadStore m) =>
FilePath -> m StorePath
addPath FilePath
p)
      NVSet' AttrSet (NValue t f m)
s AttrSet SourcePos
_ ->
        m (Maybe NixString)
-> (NValue t f m -> m (Maybe NixString))
-> Maybe (NValue t f m)
-> m (Maybe NixString)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
          m (Maybe NixString)
forall (f :: * -> *) a. (Applicative f, Monoid a) => f a
stub
          NValue t f m -> m (Maybe NixString)
forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
fromValueMay
          (Text -> AttrSet (NValue t f m) -> Maybe (NValue t f m)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
M.lookup Text
"outPath" AttrSet (NValue t f m)
s)
      NValue' t f m (NValue t f m)
_ -> m (Maybe NixString)
forall (f :: * -> *) a. (Applicative f, Monoid a) => f a
stub

  fromValue :: NValue' t f m (NValue t f m) -> m NixString
fromValue = ValueType -> NValue' t f m (NValue t f m) -> m NixString
forall t (f :: * -> *) (m :: * -> *) a e.
(Convertible e t f m,
 FromValue a m (NValue' t f m (NValue t f m))) =>
ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue (TStringContext -> ValueType
TString TStringContext
NoContext)

instance Convertible e t f m
  => FromValue ByteString m (NValue' t f m (NValue t f m)) where

  fromValueMay :: NValue' t f m (NValue t f m) -> m (Maybe ByteString)
fromValueMay =
    Maybe ByteString -> m (Maybe ByteString)
forall (f :: * -> *) a. Applicative f => a -> f a
pure(Maybe ByteString -> m (Maybe ByteString))
-> (NValue' t f m (NValue t f m) -> Maybe ByteString)
-> NValue' t f m (NValue t f m)
-> m (Maybe ByteString)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      \case
        NVStr' NixString
ns -> Text -> ByteString
forall a b. ConvertUtf8 a b => a -> b
encodeUtf8 (Text -> ByteString) -> Maybe Text -> Maybe ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NixString -> Maybe Text
getStringNoContext  NixString
ns
        NValue' t f m (NValue t f m)
_         -> Maybe ByteString
forall a. Monoid a => a
mempty

  fromValue :: NValue' t f m (NValue t f m) -> m ByteString
fromValue = ValueType -> NValue' t f m (NValue t f m) -> m ByteString
forall t (f :: * -> *) (m :: * -> *) a e.
(Convertible e t f m,
 FromValue a m (NValue' t f m (NValue t f m))) =>
ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue (TStringContext -> ValueType
TString TStringContext
NoContext)


newtype Path = Path { Path -> FilePath
getPath :: FilePath }
    deriving Int -> Path -> ShowS
[Path] -> ShowS
Path -> FilePath
(Int -> Path -> ShowS)
-> (Path -> FilePath) -> ([Path] -> ShowS) -> Show Path
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Path] -> ShowS
$cshowList :: [Path] -> ShowS
show :: Path -> FilePath
$cshow :: Path -> FilePath
showsPrec :: Int -> Path -> ShowS
$cshowsPrec :: Int -> Path -> ShowS
Show

instance ( Convertible e t f m
         , MonadValue (NValue t f m) m
         )
  => FromValue Path m (NValue' t f m (NValue t f m)) where

  fromValueMay :: NValue' t f m (NValue t f m) -> m (Maybe Path)
fromValueMay =
    \case
      NVPath' FilePath
p  -> Maybe Path -> m (Maybe Path)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Path -> m (Maybe Path)) -> Maybe Path -> m (Maybe Path)
forall a b. (a -> b) -> a -> b
$ Path -> Maybe Path
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Path -> Maybe Path) -> Path -> Maybe Path
forall a b. (a -> b) -> a -> b
$ FilePath -> Path
Path FilePath
p
      NVStr'  NixString
ns -> Maybe Path -> m (Maybe Path)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Path -> m (Maybe Path)) -> Maybe Path -> m (Maybe Path)
forall a b. (a -> b) -> a -> b
$ FilePath -> Path
Path (FilePath -> Path) -> (Text -> FilePath) -> Text -> Path
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> FilePath
forall a. ToString a => a -> FilePath
toString (Text -> Path) -> Maybe Text -> Maybe Path
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NixString -> Maybe Text
getStringNoContext  NixString
ns
      NVSet' AttrSet (NValue t f m)
s AttrSet SourcePos
_ ->
        m (Maybe Path)
-> (NValue t f m -> m (Maybe Path))
-> Maybe (NValue t f m)
-> m (Maybe Path)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
          (Maybe Path -> m (Maybe Path)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Path
forall a. Maybe a
Nothing)
          (forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
forall (m :: * -> *) v. FromValue Path m v => v -> m (Maybe Path)
fromValueMay @Path)
          (Text -> AttrSet (NValue t f m) -> Maybe (NValue t f m)
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
M.lookup Text
"outPath" AttrSet (NValue t f m)
s)
      NValue' t f m (NValue t f m)
_ -> Maybe Path -> m (Maybe Path)
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Path
forall a. Maybe a
Nothing

  fromValue :: NValue' t f m (NValue t f m) -> m Path
fromValue = ValueType -> NValue' t f m (NValue t f m) -> m Path
forall t (f :: * -> *) (m :: * -> *) a e.
(Convertible e t f m,
 FromValue a m (NValue' t f m (NValue t f m))) =>
ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue ValueType
TPath

instance Convertible e t f m
  => FromValue [NValue t f m] m (NValue' t f m (NValue t f m)) where

  fromValueMay :: NValue' t f m (NValue t f m) -> m (Maybe [NValue t f m])
fromValueMay =
    Maybe [NValue t f m] -> m (Maybe [NValue t f m])
forall (f :: * -> *) a. Applicative f => a -> f a
pure(Maybe [NValue t f m] -> m (Maybe [NValue t f m]))
-> (NValue' t f m (NValue t f m) -> Maybe [NValue t f m])
-> NValue' t f m (NValue t f m)
-> m (Maybe [NValue t f m])
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      \case
        NVList' [NValue t f m]
l -> [NValue t f m] -> Maybe [NValue t f m]
forall (f :: * -> *) a. Applicative f => a -> f a
pure [NValue t f m]
l
        NValue' t f m (NValue t f m)
_         -> Maybe [NValue t f m]
forall a. Monoid a => a
mempty

  fromValue :: NValue' t f m (NValue t f m) -> m [NValue t f m]
fromValue = ValueType -> NValue' t f m (NValue t f m) -> m [NValue t f m]
forall t (f :: * -> *) (m :: * -> *) a e.
(Convertible e t f m,
 FromValue a m (NValue' t f m (NValue t f m))) =>
ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue ValueType
TList

instance ( Convertible e t f m
         , FromValue a m (NValue t f m)
         )
  => FromValue [a] m (Deeper (NValue' t f m (NValue t f m))) where
  fromValueMay :: Deeper (NValue' t f m (NValue t f m)) -> m (Maybe [a])
fromValueMay =
    \case
      Deeper (NVList' [NValue t f m]
l) -> [Maybe a] -> Maybe [a]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence ([Maybe a] -> Maybe [a]) -> m [Maybe a] -> m (Maybe [a])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (NValue t f m -> m (Maybe a)) -> [NValue t f m] -> m [Maybe a]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse NValue t f m -> m (Maybe a)
forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
fromValueMay [NValue t f m]
l
      Deeper (NValue' t f m (NValue t f m))
_                  -> m (Maybe [a])
forall (f :: * -> *) a. (Applicative f, Monoid a) => f a
stub


  fromValue :: Deeper (NValue' t f m (NValue t f m)) -> m [a]
fromValue = ValueType -> Deeper (NValue' t f m (NValue t f m)) -> m [a]
forall t (f :: * -> *) (m :: * -> *) a e (m1 :: * -> *).
(Convertible e t f m,
 FromValue (m1 a) m (Deeper (NValue' t f m (NValue t f m)))) =>
ValueType -> Deeper (NValue' t f m (NValue t f m)) -> m (m1 a)
fromMayToDeeperValue ValueType
TList

instance Convertible e t f m
  => FromValue (AttrSet (NValue t f m)) m (NValue' t f m (NValue t f m)) where

  fromValueMay :: NValue' t f m (NValue t f m) -> m (Maybe (AttrSet (NValue t f m)))
fromValueMay =
    Maybe (AttrSet (NValue t f m))
-> m (Maybe (AttrSet (NValue t f m)))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (AttrSet (NValue t f m))
 -> m (Maybe (AttrSet (NValue t f m))))
-> (NValue' t f m (NValue t f m) -> Maybe (AttrSet (NValue t f m)))
-> NValue' t f m (NValue t f m)
-> m (Maybe (AttrSet (NValue t f m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      \case
        NVSet' AttrSet (NValue t f m)
s AttrSet SourcePos
_ -> AttrSet (NValue t f m) -> Maybe (AttrSet (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure AttrSet (NValue t f m)
s
        NValue' t f m (NValue t f m)
_          -> Maybe (AttrSet (NValue t f m))
forall a. Monoid a => a
mempty

  fromValue :: NValue' t f m (NValue t f m) -> m (AttrSet (NValue t f m))
fromValue = ValueType
-> NValue' t f m (NValue t f m) -> m (AttrSet (NValue t f m))
forall t (f :: * -> *) (m :: * -> *) a e.
(Convertible e t f m,
 FromValue a m (NValue' t f m (NValue t f m))) =>
ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue ValueType
TSet

instance ( Convertible e t f m
         , FromValue a m (NValue t f m)
         )
  => FromValue (AttrSet a) m (Deeper (NValue' t f m (NValue t f m))) where

  fromValueMay :: Deeper (NValue' t f m (NValue t f m)) -> m (Maybe (AttrSet a))
fromValueMay =
    \case
      Deeper (NVSet' AttrSet (NValue t f m)
s AttrSet SourcePos
_) -> HashMap Text (Maybe a) -> Maybe (AttrSet a)
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence (HashMap Text (Maybe a) -> Maybe (AttrSet a))
-> m (HashMap Text (Maybe a)) -> m (Maybe (AttrSet a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (NValue t f m -> m (Maybe a))
-> AttrSet (NValue t f m) -> m (HashMap Text (Maybe a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse NValue t f m -> m (Maybe a)
forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
fromValueMay AttrSet (NValue t f m)
s
      Deeper (NValue' t f m (NValue t f m))
_                   -> m (Maybe (AttrSet a))
forall (f :: * -> *) a. (Applicative f, Monoid a) => f a
stub

  fromValue :: Deeper (NValue' t f m (NValue t f m)) -> m (AttrSet a)
fromValue = ValueType -> Deeper (NValue' t f m (NValue t f m)) -> m (AttrSet a)
forall t (f :: * -> *) (m :: * -> *) a e (m1 :: * -> *).
(Convertible e t f m,
 FromValue (m1 a) m (Deeper (NValue' t f m (NValue t f m)))) =>
ValueType -> Deeper (NValue' t f m (NValue t f m)) -> m (m1 a)
fromMayToDeeperValue ValueType
TSet

instance Convertible e t f m
  => FromValue (AttrSet (NValue t f m), AttrSet SourcePos) m
              (NValue' t f m (NValue t f m)) where

  fromValueMay :: NValue' t f m (NValue t f m)
-> m (Maybe (AttrSet (NValue t f m), AttrSet SourcePos))
fromValueMay =
    Maybe (AttrSet (NValue t f m), AttrSet SourcePos)
-> m (Maybe (AttrSet (NValue t f m), AttrSet SourcePos))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe (AttrSet (NValue t f m), AttrSet SourcePos)
 -> m (Maybe (AttrSet (NValue t f m), AttrSet SourcePos)))
-> (NValue' t f m (NValue t f m)
    -> Maybe (AttrSet (NValue t f m), AttrSet SourcePos))
-> NValue' t f m (NValue t f m)
-> m (Maybe (AttrSet (NValue t f m), AttrSet SourcePos))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
      \case
        NVSet' AttrSet (NValue t f m)
s AttrSet SourcePos
p -> (AttrSet (NValue t f m), AttrSet SourcePos)
-> Maybe (AttrSet (NValue t f m), AttrSet SourcePos)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (AttrSet (NValue t f m)
s, AttrSet SourcePos
p)
        NValue' t f m (NValue t f m)
_          -> Maybe (AttrSet (NValue t f m), AttrSet SourcePos)
forall a. Monoid a => a
mempty

  fromValue :: NValue' t f m (NValue t f m)
-> m (AttrSet (NValue t f m), AttrSet SourcePos)
fromValue = ValueType
-> NValue' t f m (NValue t f m)
-> m (AttrSet (NValue t f m), AttrSet SourcePos)
forall t (f :: * -> *) (m :: * -> *) a e.
(Convertible e t f m,
 FromValue a m (NValue' t f m (NValue t f m))) =>
ValueType -> NValue' t f m (NValue t f m) -> m a
fromMayToValue ValueType
TSet

instance ( Convertible e t f m
         , FromValue a m (NValue t f m)
         )
  => FromValue (AttrSet a, AttrSet SourcePos) m
              (Deeper (NValue' t f m (NValue t f m))) where

  fromValueMay :: Deeper (NValue' t f m (NValue t f m))
-> m (Maybe (AttrSet a, AttrSet SourcePos))
fromValueMay =
    \case
      Deeper (NVSet' AttrSet (NValue t f m)
s AttrSet SourcePos
p) -> (AttrSet a -> (AttrSet a, AttrSet SourcePos))
-> Maybe (AttrSet a) -> Maybe (AttrSet a, AttrSet SourcePos)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, AttrSet SourcePos
p) (Maybe (AttrSet a) -> Maybe (AttrSet a, AttrSet SourcePos))
-> (HashMap Text (Maybe a) -> Maybe (AttrSet a))
-> HashMap Text (Maybe a)
-> Maybe (AttrSet a, AttrSet SourcePos)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap Text (Maybe a) -> Maybe (AttrSet a)
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence (HashMap Text (Maybe a) -> Maybe (AttrSet a, AttrSet SourcePos))
-> m (HashMap Text (Maybe a))
-> m (Maybe (AttrSet a, AttrSet SourcePos))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (NValue t f m -> m (Maybe a))
-> AttrSet (NValue t f m) -> m (HashMap Text (Maybe a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse NValue t f m -> m (Maybe a)
forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
fromValueMay AttrSet (NValue t f m)
s
      Deeper (NValue' t f m (NValue t f m))
_                   -> m (Maybe (AttrSet a, AttrSet SourcePos))
forall (f :: * -> *) a. (Applicative f, Monoid a) => f a
stub

  fromValue :: Deeper (NValue' t f m (NValue t f m))
-> m (AttrSet a, AttrSet SourcePos)
fromValue = ValueType
-> Deeper (NValue' t f m (NValue t f m))
-> m (AttrSet a, AttrSet SourcePos)
forall t (f :: * -> *) (m :: * -> *) a e (m1 :: * -> *).
(Convertible e t f m,
 FromValue (m1 a) m (Deeper (NValue' t f m (NValue t f m)))) =>
ValueType -> Deeper (NValue' t f m (NValue t f m)) -> m (m1 a)
fromMayToDeeperValue ValueType
TSet

-- This instance needs IncoherentInstances, and only because of ToBuiltin
instance ( Convertible e t f m
         , FromValue a m (NValue' t f m (NValue t f m))
         )
  => FromValue a m (Deeper (NValue' t f m (NValue t f m))) where
  fromValueMay :: Deeper (NValue' t f m (NValue t f m)) -> m (Maybe a)
fromValueMay = NValue' t f m (NValue t f m) -> m (Maybe a)
forall a (m :: * -> *) v. FromValue a m v => v -> m (Maybe a)
fromValueMay (NValue' t f m (NValue t f m) -> m (Maybe a))
-> (Deeper (NValue' t f m (NValue t f m))
    -> NValue' t f m (NValue t f m))
-> Deeper (NValue' t f m (NValue t f m))
-> m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Deeper (NValue' t f m (NValue t f m))
-> NValue' t f m (NValue t f m)
forall a. Deeper a -> a
getDeeper
  fromValue :: Deeper (NValue' t f m (NValue t f m)) -> m a
fromValue    = NValue' t f m (NValue t f m) -> m a
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue' t f m (NValue t f m) -> m a)
-> (Deeper (NValue' t f m (NValue t f m))
    -> NValue' t f m (NValue t f m))
-> Deeper (NValue' t f m (NValue t f m))
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Deeper (NValue' t f m (NValue t f m))
-> NValue' t f m (NValue t f m)
forall a. Deeper a -> a
getDeeper


-- * ToValue

class ToValue a m v where
    toValue :: a -> m v

instance (Convertible e t f m, ToValue a m (NValue' t f m (NValue t f m)))
  => ToValue a m (NValue t f m) where
  toValue :: a -> m (NValue t f m)
toValue = (NValue' t f m (NValue t f m) -> NValue t f m)
-> m (NValue' t f m (NValue t f m)) -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NValue' t f m (NValue t f m) -> NValue t f m
forall (f :: * -> *) a. f (Free f a) -> Free f a
Free (m (NValue' t f m (NValue t f m)) -> m (NValue t f m))
-> (a -> m (NValue' t f m (NValue t f m))) -> a -> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m (NValue' t f m (NValue t f m))
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue

instance ( Convertible e t f m
         , ToValue a m (Deeper (NValue' t f m (NValue t f m)))
         )
  => ToValue a m (Deeper (NValue t f m)) where
  toValue :: a -> m (Deeper (NValue t f m))
toValue = (Deeper (NValue' t f m (NValue t f m)) -> Deeper (NValue t f m))
-> m (Deeper (NValue' t f m (NValue t f m)))
-> m (Deeper (NValue t f m))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((NValue' t f m (NValue t f m) -> NValue t f m)
-> Deeper (NValue' t f m (NValue t f m)) -> Deeper (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NValue' t f m (NValue t f m) -> NValue t f m
forall (f :: * -> *) a. f (Free f a) -> Free f a
Free) (m (Deeper (NValue' t f m (NValue t f m)))
 -> m (Deeper (NValue t f m)))
-> (a -> m (Deeper (NValue' t f m (NValue t f m))))
-> a
-> m (Deeper (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m (Deeper (NValue' t f m (NValue t f m)))
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue

instance Convertible e t f m
  => ToValue () m (NValue' t f m (NValue t f m)) where
  toValue :: () -> m (NValue' t f m (NValue t f m))
toValue ()
_ = NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> (NAtom -> NValue' t f m (NValue t f m))
-> NAtom
-> m (NValue' t f m (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NAtom -> NValue' t f m (NValue t f m)
forall (f :: * -> *) t (m :: * -> *) r.
Applicative f =>
NAtom -> NValue' t f m r
nvConstant' (NAtom -> m (NValue' t f m (NValue t f m)))
-> NAtom -> m (NValue' t f m (NValue t f m))
forall a b. (a -> b) -> a -> b
$ NAtom
NNull

instance Convertible e t f m
  => ToValue Bool m (NValue' t f m (NValue t f m)) where
  toValue :: Bool -> m (NValue' t f m (NValue t f m))
toValue = NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> (Bool -> NValue' t f m (NValue t f m))
-> Bool
-> m (NValue' t f m (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NAtom -> NValue' t f m (NValue t f m)
forall (f :: * -> *) t (m :: * -> *) r.
Applicative f =>
NAtom -> NValue' t f m r
nvConstant' (NAtom -> NValue' t f m (NValue t f m))
-> (Bool -> NAtom) -> Bool -> NValue' t f m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> NAtom
NBool

instance Convertible e t f m
  => ToValue Int m (NValue' t f m (NValue t f m)) where
  toValue :: Int -> m (NValue' t f m (NValue t f m))
toValue = NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> (Int -> NValue' t f m (NValue t f m))
-> Int
-> m (NValue' t f m (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NAtom -> NValue' t f m (NValue t f m)
forall (f :: * -> *) t (m :: * -> *) r.
Applicative f =>
NAtom -> NValue' t f m r
nvConstant' (NAtom -> NValue' t f m (NValue t f m))
-> (Int -> NAtom) -> Int -> NValue' t f m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> NAtom
NInt (Integer -> NAtom) -> (Int -> Integer) -> Int -> NAtom
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Integer
forall a. Integral a => a -> Integer
toInteger

instance Convertible e t f m
  => ToValue Integer m (NValue' t f m (NValue t f m)) where
  toValue :: Integer -> m (NValue' t f m (NValue t f m))
toValue = NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> (Integer -> NValue' t f m (NValue t f m))
-> Integer
-> m (NValue' t f m (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NAtom -> NValue' t f m (NValue t f m)
forall (f :: * -> *) t (m :: * -> *) r.
Applicative f =>
NAtom -> NValue' t f m r
nvConstant' (NAtom -> NValue' t f m (NValue t f m))
-> (Integer -> NAtom) -> Integer -> NValue' t f m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> NAtom
NInt

instance Convertible e t f m
  => ToValue Float m (NValue' t f m (NValue t f m)) where
  toValue :: Float -> m (NValue' t f m (NValue t f m))
toValue = NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> (Float -> NValue' t f m (NValue t f m))
-> Float
-> m (NValue' t f m (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NAtom -> NValue' t f m (NValue t f m)
forall (f :: * -> *) t (m :: * -> *) r.
Applicative f =>
NAtom -> NValue' t f m r
nvConstant' (NAtom -> NValue' t f m (NValue t f m))
-> (Float -> NAtom) -> Float -> NValue' t f m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Float -> NAtom
NFloat

instance Convertible e t f m
  => ToValue NixString m (NValue' t f m (NValue t f m)) where
  toValue :: NixString -> m (NValue' t f m (NValue t f m))
toValue = NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> (NixString -> NValue' t f m (NValue t f m))
-> NixString
-> m (NValue' t f m (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NixString -> NValue' t f m (NValue t f m)
forall (f :: * -> *) t (m :: * -> *) r.
Applicative f =>
NixString -> NValue' t f m r
nvStr'

instance Convertible e t f m
  => ToValue ByteString m (NValue' t f m (NValue t f m)) where
  toValue :: ByteString -> m (NValue' t f m (NValue t f m))
toValue = NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> (ByteString -> NValue' t f m (NValue t f m))
-> ByteString
-> m (NValue' t f m (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NixString -> NValue' t f m (NValue t f m)
forall (f :: * -> *) t (m :: * -> *) r.
Applicative f =>
NixString -> NValue' t f m r
nvStr' (NixString -> NValue' t f m (NValue t f m))
-> (ByteString -> NixString)
-> ByteString
-> NValue' t f m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> NixString
makeNixStringWithoutContext (Text -> NixString)
-> (ByteString -> Text) -> ByteString -> NixString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8

instance Convertible e t f m
  => ToValue Path m (NValue' t f m (NValue t f m)) where
  toValue :: Path -> m (NValue' t f m (NValue t f m))
toValue = NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> (Path -> NValue' t f m (NValue t f m))
-> Path
-> m (NValue' t f m (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> NValue' t f m (NValue t f m)
forall (f :: * -> *) t (m :: * -> *) r.
Applicative f =>
FilePath -> NValue' t f m r
nvPath' (FilePath -> NValue' t f m (NValue t f m))
-> (Path -> FilePath) -> Path -> NValue' t f m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Path -> FilePath
getPath

instance Convertible e t f m
  => ToValue StorePath m (NValue' t f m (NValue t f m)) where
  toValue :: StorePath -> m (NValue' t f m (NValue t f m))
toValue = Path -> m (NValue' t f m (NValue t f m))
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Path -> m (NValue' t f m (NValue t f m)))
-> (StorePath -> Path)
-> StorePath
-> m (NValue' t f m (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Path
Path (FilePath -> Path) -> (StorePath -> FilePath) -> StorePath -> Path
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StorePath -> FilePath
unStorePath

instance ( Convertible e t f m
         )
  => ToValue SourcePos m (NValue' t f m (NValue t f m)) where
  toValue :: SourcePos -> m (NValue' t f m (NValue t f m))
toValue (SourcePos FilePath
f Pos
l Pos
c) = do
    NValue t f m
f' <- NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Text -> NixString
makeNixStringWithoutContext (FilePath -> Text
forall a. ToText a => a -> Text
toText FilePath
f))
    NValue t f m
l' <- Int -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Pos -> Int
unPos Pos
l)
    NValue t f m
c' <- Int -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Pos -> Int
unPos Pos
c)
    let pos :: HashMap Text (NValue t f m)
pos = [(Text, NValue t f m)] -> HashMap Text (NValue t f m)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
M.fromList [(Text
"file" :: Text, NValue t f m
f'), (Text
"line", NValue t f m
l'), (Text
"column", NValue t f m
c')]
    NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall a b. (a -> b) -> a -> b
$ AttrSet SourcePos
-> HashMap Text (NValue t f m) -> NValue' t f m (NValue t f m)
forall (f :: * -> *) r t (m :: * -> *).
Applicative f =>
AttrSet SourcePos -> HashMap Text r -> NValue' t f m r
nvSet' AttrSet SourcePos
forall a. Monoid a => a
mempty HashMap Text (NValue t f m)
pos

-- | With 'ToValue', we can always act recursively
instance Convertible e t f m
  => ToValue [NValue t f m] m (NValue' t f m (NValue t f m)) where
  toValue :: [NValue t f m] -> m (NValue' t f m (NValue t f m))
toValue = NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> ([NValue t f m] -> NValue' t f m (NValue t f m))
-> [NValue t f m]
-> m (NValue' t f m (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [NValue t f m] -> NValue' t f m (NValue t f m)
forall (f :: * -> *) r t (m :: * -> *).
Applicative f =>
[r] -> NValue' t f m r
nvList'

instance (Convertible e t f m, ToValue a m (NValue t f m))
  => ToValue [a] m (Deeper (NValue' t f m (NValue t f m))) where
  toValue :: [a] -> m (Deeper (NValue' t f m (NValue t f m)))
toValue = ([NValue t f m] -> Deeper (NValue' t f m (NValue t f m)))
-> m [NValue t f m] -> m (Deeper (NValue' t f m (NValue t f m)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (NValue' t f m (NValue t f m)
-> Deeper (NValue' t f m (NValue t f m))
forall a. a -> Deeper a
Deeper (NValue' t f m (NValue t f m)
 -> Deeper (NValue' t f m (NValue t f m)))
-> ([NValue t f m] -> NValue' t f m (NValue t f m))
-> [NValue t f m]
-> Deeper (NValue' t f m (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [NValue t f m] -> NValue' t f m (NValue t f m)
forall (f :: * -> *) r t (m :: * -> *).
Applicative f =>
[r] -> NValue' t f m r
nvList') (m [NValue t f m] -> m (Deeper (NValue' t f m (NValue t f m))))
-> ([a] -> m [NValue t f m])
-> [a]
-> m (Deeper (NValue' t f m (NValue t f m)))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> m (NValue t f m)) -> [a] -> m [NValue t f m]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue

instance Convertible e t f m
  => ToValue (AttrSet (NValue t f m)) m (NValue' t f m (NValue t f m)) where
  toValue :: AttrSet (NValue t f m) -> m (NValue' t f m (NValue t f m))
toValue AttrSet (NValue t f m)
s = NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall a b. (a -> b) -> a -> b
$ AttrSet SourcePos
-> AttrSet (NValue t f m) -> NValue' t f m (NValue t f m)
forall (f :: * -> *) r t (m :: * -> *).
Applicative f =>
AttrSet SourcePos -> HashMap Text r -> NValue' t f m r
nvSet' AttrSet SourcePos
forall a. Monoid a => a
mempty AttrSet (NValue t f m)
s

instance (Convertible e t f m, ToValue a m (NValue t f m))
  => ToValue (AttrSet a) m (Deeper (NValue' t f m (NValue t f m))) where
  toValue :: AttrSet a -> m (Deeper (NValue' t f m (NValue t f m)))
toValue AttrSet a
s =
    (HashMap Text (NValue t f m)
 -> AttrSet SourcePos -> Deeper (NValue' t f m (NValue t f m)))
-> m (HashMap Text (NValue t f m))
-> m (AttrSet SourcePos)
-> m (Deeper (NValue' t f m (NValue t f m)))
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2
      (\ HashMap Text (NValue t f m)
v AttrSet SourcePos
s -> NValue' t f m (NValue t f m)
-> Deeper (NValue' t f m (NValue t f m))
forall a. a -> Deeper a
Deeper (NValue' t f m (NValue t f m)
 -> Deeper (NValue' t f m (NValue t f m)))
-> NValue' t f m (NValue t f m)
-> Deeper (NValue' t f m (NValue t f m))
forall a b. (a -> b) -> a -> b
$ AttrSet SourcePos
-> HashMap Text (NValue t f m) -> NValue' t f m (NValue t f m)
forall (f :: * -> *) r t (m :: * -> *).
Applicative f =>
AttrSet SourcePos -> HashMap Text r -> NValue' t f m r
nvSet' AttrSet SourcePos
s HashMap Text (NValue t f m)
v)
      ((a -> m (NValue t f m))
-> AttrSet a -> m (HashMap Text (NValue t f m))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue AttrSet a
s)
      m (AttrSet SourcePos)
forall (f :: * -> *) a. (Applicative f, Monoid a) => f a
stub

instance Convertible e t f m
  => ToValue (AttrSet (NValue t f m), AttrSet SourcePos) m
            (NValue' t f m (NValue t f m)) where
  toValue :: (AttrSet (NValue t f m), AttrSet SourcePos)
-> m (NValue' t f m (NValue t f m))
toValue (AttrSet (NValue t f m)
s, AttrSet SourcePos
p) = NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m)))
-> NValue' t f m (NValue t f m) -> m (NValue' t f m (NValue t f m))
forall a b. (a -> b) -> a -> b
$ AttrSet SourcePos
-> AttrSet (NValue t f m) -> NValue' t f m (NValue t f m)
forall (f :: * -> *) r t (m :: * -> *).
Applicative f =>
AttrSet SourcePos -> HashMap Text r -> NValue' t f m r
nvSet' AttrSet SourcePos
p AttrSet (NValue t f m)
s

instance (Convertible e t f m, ToValue a m (NValue t f m))
  => ToValue (AttrSet a, AttrSet SourcePos) m
            (Deeper (NValue' t f m (NValue t f m))) where
  toValue :: (AttrSet a, AttrSet SourcePos)
-> m (Deeper (NValue' t f m (NValue t f m)))
toValue (AttrSet a
s, AttrSet SourcePos
p) = (\ HashMap Text (NValue t f m)
v AttrSet SourcePos
s -> NValue' t f m (NValue t f m)
-> Deeper (NValue' t f m (NValue t f m))
forall a. a -> Deeper a
Deeper (NValue' t f m (NValue t f m)
 -> Deeper (NValue' t f m (NValue t f m)))
-> NValue' t f m (NValue t f m)
-> Deeper (NValue' t f m (NValue t f m))
forall a b. (a -> b) -> a -> b
$ AttrSet SourcePos
-> HashMap Text (NValue t f m) -> NValue' t f m (NValue t f m)
forall (f :: * -> *) r t (m :: * -> *).
Applicative f =>
AttrSet SourcePos -> HashMap Text r -> NValue' t f m r
nvSet' AttrSet SourcePos
s HashMap Text (NValue t f m)
v) (HashMap Text (NValue t f m)
 -> AttrSet SourcePos -> Deeper (NValue' t f m (NValue t f m)))
-> m (HashMap Text (NValue t f m))
-> m (AttrSet SourcePos -> Deeper (NValue' t f m (NValue t f m)))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (a -> m (NValue t f m))
-> AttrSet a -> m (HashMap Text (NValue t f m))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue AttrSet a
s m (AttrSet SourcePos -> Deeper (NValue' t f m (NValue t f m)))
-> m (AttrSet SourcePos)
-> m (Deeper (NValue' t f m (NValue t f m)))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AttrSet SourcePos -> m (AttrSet SourcePos)
forall (f :: * -> *) a. Applicative f => a -> f a
pure AttrSet SourcePos
p

instance Convertible e t f m
  => ToValue NixLikeContextValue m (NValue' t f m (NValue t f m)) where
  toValue :: NixLikeContextValue -> m (NValue' t f m (NValue t f m))
toValue NixLikeContextValue
nlcv = do
    Maybe (NValue t f m)
path <-
      m (Maybe (NValue t f m))
-> m (Maybe (NValue t f m)) -> Bool -> m (Maybe (NValue t f m))
forall a. a -> a -> Bool -> a
bool
        (Maybe (NValue t f m) -> m (Maybe (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (NValue t f m)
forall a. Maybe a
Nothing)
        (NValue t f m -> Maybe (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> Maybe (NValue t f m))
-> m (NValue t f m) -> m (Maybe (NValue t f m))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue Bool
True)
        (NixLikeContextValue -> Bool
nlcvPath NixLikeContextValue
nlcv)
    Maybe (NValue t f m)
allOutputs <-
      m (Maybe (NValue t f m))
-> m (Maybe (NValue t f m)) -> Bool -> m (Maybe (NValue t f m))
forall a. a -> a -> Bool -> a
bool
        (Maybe (NValue t f m) -> m (Maybe (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (NValue t f m)
forall a. Maybe a
Nothing)
        (NValue t f m -> Maybe (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> Maybe (NValue t f m))
-> m (NValue t f m) -> m (Maybe (NValue t f m))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue Bool
True)
        (NixLikeContextValue -> Bool
nlcvAllOutputs NixLikeContextValue
nlcv)
    Maybe (NValue t f m)
outputs <- do
      let
        outputs :: [NixString]
outputs = Text -> NixString
makeNixStringWithoutContext (Text -> NixString) -> [Text] -> [NixString]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NixLikeContextValue -> [Text]
nlcvOutputs NixLikeContextValue
nlcv

      [NValue t f m]
ts :: [NValue t f m] <- (NixString -> m (NValue t f m)) -> [NixString] -> m [NValue t f m]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue [NixString]
outputs
      m (Maybe (NValue t f m))
-> ([NValue t f m] -> m (Maybe (NValue t f m)))
-> [NValue t f m]
-> m (Maybe (NValue t f m))
forall (t :: * -> *) b a. Foldable t => b -> (t a -> b) -> t a -> b
list
        (Maybe (NValue t f m) -> m (Maybe (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (NValue t f m)
forall a. Maybe a
Nothing)
        ((NValue t f m -> Maybe (NValue t f m))
-> m (NValue t f m) -> m (Maybe (NValue t f m))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NValue t f m -> Maybe (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (m (NValue t f m) -> m (Maybe (NValue t f m)))
-> ([NValue t f m] -> m (NValue t f m))
-> [NValue t f m]
-> m (Maybe (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [NValue t f m] -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue)
        [NValue t f m]
ts
    pure $ AttrSet SourcePos
-> HashMap Text (NValue t f m) -> NValue' t f m (NValue t f m)
forall (f :: * -> *) r t (m :: * -> *).
Applicative f =>
AttrSet SourcePos -> HashMap Text r -> NValue' t f m r
nvSet' AttrSet SourcePos
forall a. Monoid a => a
mempty (HashMap Text (NValue t f m) -> NValue' t f m (NValue t f m))
-> HashMap Text (NValue t f m) -> NValue' t f m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ [(Text, NValue t f m)] -> HashMap Text (NValue t f m)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
M.fromList ([(Text, NValue t f m)] -> HashMap Text (NValue t f m))
-> [(Text, NValue t f m)] -> HashMap Text (NValue t f m)
forall a b. (a -> b) -> a -> b
$ [Maybe (Text, NValue t f m)] -> [(Text, NValue t f m)]
forall a. [Maybe a] -> [a]
catMaybes
      [ (Text
"path",) (NValue t f m -> (Text, NValue t f m))
-> Maybe (NValue t f m) -> Maybe (Text, NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (NValue t f m)
path
      , (Text
"allOutputs",) (NValue t f m -> (Text, NValue t f m))
-> Maybe (NValue t f m) -> Maybe (Text, NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (NValue t f m)
allOutputs
      , (Text
"outputs",) (NValue t f m -> (Text, NValue t f m))
-> Maybe (NValue t f m) -> Maybe (Text, NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (NValue t f m)
outputs
      ]

instance Convertible e t f m => ToValue () m (NExprF (NValue t f m)) where
  toValue :: () -> m (NExprF (NValue t f m))
toValue ()
_ = NExprF (NValue t f m) -> m (NExprF (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NExprF (NValue t f m) -> m (NExprF (NValue t f m)))
-> (NAtom -> NExprF (NValue t f m))
-> NAtom
-> m (NExprF (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NAtom -> NExprF (NValue t f m)
forall r. NAtom -> NExprF r
NConstant (NAtom -> m (NExprF (NValue t f m)))
-> NAtom -> m (NExprF (NValue t f m))
forall a b. (a -> b) -> a -> b
$ NAtom
NNull

instance Convertible e t f m => ToValue Bool m (NExprF (NValue t f m)) where
  toValue :: Bool -> m (NExprF (NValue t f m))
toValue = NExprF (NValue t f m) -> m (NExprF (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NExprF (NValue t f m) -> m (NExprF (NValue t f m)))
-> (Bool -> NExprF (NValue t f m))
-> Bool
-> m (NExprF (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NAtom -> NExprF (NValue t f m)
forall r. NAtom -> NExprF r
NConstant (NAtom -> NExprF (NValue t f m))
-> (Bool -> NAtom) -> Bool -> NExprF (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> NAtom
NBool