{-# LANGUAGE CPP #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PackageImports #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}

{-# OPTIONS_GHC -Wno-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}

module Nix.Builtins (withNixContext, builtins) where

import           Control.Comonad
import           Control.Monad
import           Control.Monad.Catch
import           Control.Monad.ListM            ( sortByM )
import           Control.Monad.Reader           ( asks )
import           Crypto.Hash
import qualified Crypto.Hash.MD5               as MD5
import qualified Crypto.Hash.SHA1              as SHA1
import qualified Crypto.Hash.SHA256            as SHA256
import qualified Crypto.Hash.SHA512            as SHA512
import qualified Data.Aeson                    as A
import           Data.Align                     ( alignWith )
import           Data.Array
import           Data.Bits
import           Data.ByteString                ( ByteString )
import qualified Data.ByteString               as B
import           Data.ByteString.Base16        as Base16
import           Data.Char                      ( isDigit )
import           Data.Fix                       ( foldFix )
import           Data.Foldable                  ( foldrM )
import qualified Data.HashMap.Lazy             as M
import           Data.List
import           Data.Maybe
import           Data.Scientific
import           Data.Set                       ( Set )
import qualified Data.Set                      as S
import           Data.Text                      ( Text )
import qualified Data.Text                     as Text
import           Data.Text.Encoding
import qualified Data.Text.Lazy                as LazyText
import qualified Data.Text.Lazy.Builder        as Builder
import           Data.These                     ( fromThese )
import qualified Data.Time.Clock.POSIX         as Time
import           Data.Traversable               ( for )
import qualified Data.Vector                   as V
import           NeatInterpolation              ( text )
import           Nix.Atoms
import           Nix.Convert
import           Nix.Effects
import           Nix.Effects.Basic              ( fetchTarball )
import qualified Nix.Eval                      as Eval
import           Nix.Exec
import           Nix.Expr.Types
import           Nix.Expr.Types.Annotated
import           Nix.Frames
import           Nix.Json
import           Nix.Normal
import           Nix.Options
import           Nix.Parser              hiding ( nixPath )
import           Nix.Render
import           Nix.Scope
import           Nix.String
import           Nix.String.Coerce
import           Nix.Utils
import           Nix.Value
import           Nix.Value.Equal
import           Nix.Value.Monad
import           Nix.XML
import           System.Nix.Base32              as Base32
import           System.FilePath
import           System.Posix.Files             ( isRegularFile
                                                , isDirectory
                                                , isSymbolicLink
                                                )
import           Text.Read
import           Text.Regex.TDFA

-- | Evaluate a nix expression in the default context
withNixContext
  :: forall e t f m r
   . (MonadNix e t f m, Has e Options)
  => Maybe FilePath
  -> m r
  -> m r
withNixContext :: Maybe FilePath -> m r -> m r
withNixContext mpath :: Maybe FilePath
mpath action :: m r
action = do
  Scopes m (NValue t f m)
base            <- m (Scopes m (NValue t f m))
forall e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, Scoped (NValue t f m) m) =>
m (Scopes m (NValue t f m))
builtins
  Options
opts :: Options <- (e -> Options) -> m Options
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (FoldLike Options e e Options Options -> e -> Options
forall a s t b. FoldLike a s t a b -> s -> a
view FoldLike Options e e Options Options
forall a b. Has a b => Lens' a b
hasLens)
  let i :: NValue t f m
i = [NValue t f m] -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
[NValue t f m] -> NValue t f m
nvList ([NValue t f m] -> NValue t f m) -> [NValue t f m] -> NValue t f m
forall a b. (a -> b) -> a -> b
$ (FilePath -> NValue t f m) -> [FilePath] -> [NValue t f m]
forall a b. (a -> b) -> [a] -> [b]
map
        ( NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr
        (NixString -> NValue t f m)
-> (FilePath -> NixString) -> FilePath -> NValue t f m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> NixString
hackyMakeNixStringWithoutContext
        (Text -> NixString) -> (FilePath -> Text) -> FilePath -> NixString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
Text.pack
        )
        (Options -> [FilePath]
include Options
opts)
  AttrSet (NValue t f m) -> m r -> m r
forall a (m :: * -> *) r. Scoped a m => AttrSet a -> m r -> m r
pushScope (Text -> NValue t f m -> AttrSet (NValue t f m)
forall k v. Hashable k => k -> v -> HashMap k v
M.singleton "__includes" NValue t f m
i) (m r -> m r) -> m r -> m r
forall a b. (a -> b) -> a -> b
$ Scopes m (NValue t f m) -> m r -> m r
forall a (m :: * -> *) r. Scoped a m => Scopes m a -> m r -> m r
pushScopes Scopes m (NValue t f m)
base (m r -> m r) -> m r -> m r
forall a b. (a -> b) -> a -> b
$ case Maybe FilePath
mpath of
    Nothing   -> m r
action
    Just path :: FilePath
path -> do
      FilePath -> m ()
forall (m :: * -> *). Monad m => FilePath -> m ()
traceM (FilePath -> m ()) -> FilePath -> m ()
forall a b. (a -> b) -> a -> b
$ "Setting __cur_file = " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath -> FilePath
forall a. Show a => a -> FilePath
show FilePath
path
      let ref :: NValue t f m
ref = FilePath -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
FilePath -> NValue t f m
nvPath FilePath
path
      AttrSet (NValue t f m) -> m r -> m r
forall a (m :: * -> *) r. Scoped a m => AttrSet a -> m r -> m r
pushScope (Text -> NValue t f m -> AttrSet (NValue t f m)
forall k v. Hashable k => k -> v -> HashMap k v
M.singleton "__cur_file" NValue t f m
ref) m r
action

builtins :: (MonadNix e t f m, Scoped (NValue t f m) m)
         => m (Scopes m (NValue t f m))
builtins :: m (Scopes m (NValue t f m))
builtins = do
  NValue t f m
ref <- m (NValue t f m) -> m (NValue t f m)
forall v (m :: * -> *). MonadValue v m => m v -> m v
defer (m (NValue t f m) -> m (NValue t f m))
-> m (NValue t f m) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ (HashMap Text (NValue t f m)
 -> HashMap Text SourcePos -> NValue t f m)
-> HashMap Text SourcePos
-> HashMap Text (NValue t f m)
-> NValue t f m
forall a b c. (a -> b -> c) -> b -> a -> c
flip HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
nvSet HashMap Text SourcePos
forall k v. HashMap k v
M.empty (HashMap Text (NValue t f m) -> NValue t f m)
-> m (HashMap Text (NValue t f m)) -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m (HashMap Text (NValue t f m))
buildMap
  [(Text, NValue t f m)]
lst <- ([("builtins", NValue t f m
ref)] [(Text, NValue t f m)]
-> [(Text, NValue t f m)] -> [(Text, NValue t f m)]
forall a. [a] -> [a] -> [a]
++) ([(Text, NValue t f m)] -> [(Text, NValue t f m)])
-> m [(Text, NValue t f m)] -> m [(Text, NValue t f m)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m [(Text, NValue t f m)]
topLevelBuiltins
  HashMap Text (NValue t f m)
-> m (Scopes m (NValue t f m)) -> m (Scopes m (NValue t f m))
forall a (m :: * -> *) r. Scoped a m => AttrSet a -> m r -> m r
pushScope ([(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)]
lst) m (Scopes m (NValue t f m))
forall a (m :: * -> *). Scoped a m => m (Scopes m a)
currentScopes
 where
  buildMap :: m (HashMap Text (NValue t f m))
buildMap         = [(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))
-> ([Builtin (NValue t f m)] -> [(Text, NValue t f m)])
-> [Builtin (NValue t f m)]
-> HashMap Text (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Builtin (NValue t f m) -> (Text, NValue t f m))
-> [Builtin (NValue t f m)] -> [(Text, NValue t f m)]
forall a b. (a -> b) -> [a] -> [b]
map Builtin (NValue t f m) -> (Text, NValue t f m)
forall v. Builtin v -> (Text, v)
mapping ([Builtin (NValue t f m)] -> HashMap Text (NValue t f m))
-> m [Builtin (NValue t f m)] -> m (HashMap Text (NValue t f m))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m [Builtin (NValue t f m)]
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
m [Builtin (NValue t f m)]
builtinsList
  topLevelBuiltins :: m [(Text, NValue t f m)]
topLevelBuiltins = (Builtin (NValue t f m) -> (Text, NValue t f m))
-> [Builtin (NValue t f m)] -> [(Text, NValue t f m)]
forall a b. (a -> b) -> [a] -> [b]
map Builtin (NValue t f m) -> (Text, NValue t f m)
forall v. Builtin v -> (Text, v)
mapping ([Builtin (NValue t f m)] -> [(Text, NValue t f m)])
-> m [Builtin (NValue t f m)] -> m [(Text, NValue t f m)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m [Builtin (NValue t f m)]
fullBuiltinsList

  fullBuiltinsList :: m [Builtin (NValue t f m)]
fullBuiltinsList = (Builtin (NValue t f m) -> Builtin (NValue t f m))
-> [Builtin (NValue t f m)] -> [Builtin (NValue t f m)]
forall a b. (a -> b) -> [a] -> [b]
map Builtin (NValue t f m) -> Builtin (NValue t f m)
forall v. Builtin v -> Builtin v
go ([Builtin (NValue t f m)] -> [Builtin (NValue t f m)])
-> m [Builtin (NValue t f m)] -> m [Builtin (NValue t f m)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m [Builtin (NValue t f m)]
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
m [Builtin (NValue t f m)]
builtinsList
   where
    go :: Builtin v -> Builtin v
go b :: Builtin v
b@(Builtin TopLevel _) = Builtin v
b
    go (Builtin Normal (name :: Text
name, builtin :: v
builtin)) =
      BuiltinType -> (Text, v) -> Builtin v
forall v. BuiltinType -> (Text, v) -> Builtin v
Builtin BuiltinType
TopLevel ("__" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
name, v
builtin)

data BuiltinType = Normal | TopLevel
data Builtin v = Builtin
    { Builtin v -> BuiltinType
_kind   :: BuiltinType
    , Builtin v -> (Text, v)
mapping :: (Text, v)
    }

builtinsList :: forall e t f m . MonadNix e t f m => m [Builtin (NValue t f m)]
builtinsList :: m [Builtin (NValue t f m)]
builtinsList = [m (Builtin (NValue t f m))] -> m [Builtin (NValue t f m)]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence
  [ do
    NValue t f m
version <- NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Text -> NixString
principledMakeNixStringWithoutContext "2.3")
    Builtin (NValue t f m) -> m (Builtin (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Builtin (NValue t f m) -> m (Builtin (NValue t f m)))
-> Builtin (NValue t f m) -> m (Builtin (NValue t f m))
forall a b. (a -> b) -> a -> b
$ BuiltinType -> (Text, NValue t f m) -> Builtin (NValue t f m)
forall v. BuiltinType -> (Text, v) -> Builtin v
Builtin BuiltinType
Normal ("nixVersion", NValue t f m
version)
  , do
    NValue t f m
version <- Int -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (5 :: Int)
    Builtin (NValue t f m) -> m (Builtin (NValue t f m))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Builtin (NValue t f m) -> m (Builtin (NValue t f m)))
-> Builtin (NValue t f m) -> m (Builtin (NValue t f m))
forall a b. (a -> b) -> a -> b
$ BuiltinType -> (Text, NValue t f m) -> Builtin (NValue t f m)
forall v. BuiltinType -> (Text, v) -> Builtin v
Builtin BuiltinType
Normal ("langVersion", NValue t f m
version)

  , BuiltinType
-> Text -> m (NValue t f m) -> m (Builtin (NValue t f m))
forall (f :: * -> *) v e.
(MonadValue v f, MonadReader e f, Has e Frames, MonadThrow f) =>
BuiltinType -> Text -> f v -> f (Builtin v)
add0 BuiltinType
Normal   "nixPath"          m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
m (NValue t f m)
nixPath
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
TopLevel "abort"            NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
throw_ -- for now
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "add"              NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
add_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "addErrorContext"  NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
addErrorContext
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "all"              NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
all_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "any"              NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
any_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "attrNames"        NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
attrNames
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "attrValues"       NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
attrValues
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
TopLevel "baseNameOf"       NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
baseNameOf
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "bitAnd"           NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
bitAnd
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "bitOr"            NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
bitOr
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "bitXor"           NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
bitXor
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "catAttrs"         NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
catAttrs
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "compareVersions"  NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
compareVersions_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "concatLists"      NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
concatLists
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "concatMap"        NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
concatMap_
  , BuiltinType
-> Text
-> (NixString -> [NixString] -> Prim m NixString)
-> m (Builtin (NValue t f m))
forall a.
ToBuiltin t f m a =>
BuiltinType -> Text -> a -> m (Builtin (NValue t f m))
add' BuiltinType
Normal   "concatStringsSep" ((NixString -> [NixString] -> NixString)
-> NixString -> [NixString] -> Prim m NixString
forall a b c. (a -> b -> c) -> a -> b -> Prim m c
arity2 NixString -> [NixString] -> NixString
principledIntercalateNixString)
  , BuiltinType
-> Text -> m (NValue t f m) -> m (Builtin (NValue t f m))
forall (f :: * -> *) v e.
(MonadValue v f, MonadReader e f, Has e Frames, MonadThrow f) =>
BuiltinType -> Text -> f v -> f (Builtin v)
add0 BuiltinType
Normal   "currentSystem"    m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
m (NValue t f m)
currentSystem
  , BuiltinType
-> Text -> m (NValue t f m) -> m (Builtin (NValue t f m))
forall (f :: * -> *) v e.
(MonadValue v f, MonadReader e f, Has e Frames, MonadThrow f) =>
BuiltinType -> Text -> f v -> f (Builtin v)
add0 BuiltinType
Normal   "currentTime"      m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
m (NValue t f m)
currentTime_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "deepSeq"          NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
deepSeq

    -- This is compiled in so that we only parse and evaluate it once, at
    -- compile-time.
  , BuiltinType
-> Text -> m (NValue t f m) -> m (Builtin (NValue t f m))
forall (f :: * -> *) v e.
(MonadValue v f, MonadReader e f, Has e Frames, MonadThrow f) =>
BuiltinType -> Text -> f v -> f (Builtin v)
add0 BuiltinType
TopLevel "derivation" $(do
      let Success expr = parseNixText [text|
        drvAttrs @ { outputs ? [ "out" ], ... }:

        let

          strict = derivationStrict drvAttrs;

          commonAttrs = drvAttrs
            // (builtins.listToAttrs outputsList)
            // { all = map (x: x.value) outputsList;
                 inherit drvAttrs;
               };

          outputToAttrListElement = outputName:
            { name = outputName;
              value = commonAttrs // {
                outPath = builtins.getAttr outputName strict;
                drvPath = strict.drvPath;
                type = "derivation";
                inherit outputName;
              };
            };

          outputsList = map outputToAttrListElement outputs;

        in (builtins.head outputsList).value|]
      [| foldFix Eval.eval expr |]
    )

  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
TopLevel "derivationStrict" NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
derivationStrict_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
TopLevel "dirOf"            NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
dirOf
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "div"              NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
div_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "elem"             NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
elem_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "elemAt"           NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
elemAt_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "exec"             NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
exec_
  , BuiltinType
-> Text -> m (NValue t f m) -> m (Builtin (NValue t f m))
forall (f :: * -> *) v e.
(MonadValue v f, MonadReader e f, Has e Frames, MonadThrow f) =>
BuiltinType -> Text -> f v -> f (Builtin v)
add0 BuiltinType
Normal   "false"            (NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant (NAtom -> NValue t f m) -> NAtom -> NValue t f m
forall a b. (a -> b) -> a -> b
$ Bool -> NAtom
NBool Bool
False)
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "fetchTarball"     NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
fetchTarball
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "fetchurl"         NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
fetchurl
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "filter"           NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
filter_
  , BuiltinType
-> Text
-> (NValue t f m
    -> NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f
    -> NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add3 BuiltinType
Normal   "foldl'"           NValue t f m -> NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> NValue t f m -> m (NValue t f m)
foldl'_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "fromJSON"         NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
fromJSON
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "functionArgs"     NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
functionArgs
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "genList"          NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
genList
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "genericClosure"   NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
genericClosure
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "getAttr"          NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
getAttr
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "getEnv"           NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
getEnv_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "hasAttr"          NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
hasAttr
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "hasContext"       NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
hasContext
  , BuiltinType
-> Text
-> (NixString -> NixString -> Prim m NixString)
-> m (Builtin (NValue t f m))
forall a.
ToBuiltin t f m a =>
BuiltinType -> Text -> a -> m (Builtin (NValue t f m))
add' BuiltinType
Normal   "hashString"       (MonadNix e t f m => NixString -> NixString -> Prim m NixString
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NixString -> NixString -> Prim m NixString
hashString @e @t @f @m)
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "head"             NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
head_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
TopLevel "import"           NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
import_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "intersectAttrs"   NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
intersectAttrs
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "isAttrs"          NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
isAttrs
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "isBool"           NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
isBool
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "isFloat"          NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
isFloat
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "isFunction"       NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
isFunction
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "isInt"            NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
isInt
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "isList"           NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
isList
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
TopLevel "isNull"           NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
isNull
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "isString"         NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
isString
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "length"           NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
length_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "lessThan"         NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
lessThan
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "listToAttrs"      NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
listToAttrs
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
TopLevel "map"              NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
map_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
TopLevel "mapAttrs"         NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
mapAttrs_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "match"            NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
match_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "mul"              NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
mul_
  , BuiltinType
-> Text -> m (NValue t f m) -> m (Builtin (NValue t f m))
forall (f :: * -> *) v e.
(MonadValue v f, MonadReader e f, Has e Frames, MonadThrow f) =>
BuiltinType -> Text -> f v -> f (Builtin v)
add0 BuiltinType
Normal   "null"             (NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant NAtom
NNull)
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "parseDrvName"     NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
parseDrvName
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "partition"        NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
partition_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "pathExists"       NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
pathExists_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
TopLevel "placeholder"      NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
placeHolder
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "readDir"          NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
readDir_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "readFile"         NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
readFile_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "findFile"         NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
findFile_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
TopLevel "removeAttrs"      NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
removeAttrs
  , BuiltinType
-> Text
-> (NValue t f m
    -> NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f
    -> NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add3 BuiltinType
Normal   "replaceStrings"   NValue t f m -> NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> NValue t f m -> m (NValue t f m)
replaceStrings
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
TopLevel "scopedImport"     NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
scopedImport
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "seq"              NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
seq_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "sort"             NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
sort_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "split"            NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
split_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "splitVersion"     NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
splitVersion_
  , BuiltinType
-> Text -> m (NValue t f m) -> m (Builtin (NValue t f m))
forall (f :: * -> *) v e.
(MonadValue v f, MonadReader e f, Has e Frames, MonadThrow f) =>
BuiltinType -> Text -> f v -> f (Builtin v)
add0 BuiltinType
Normal   "storeDir"         (NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr (NixString -> NValue t f m) -> NixString -> NValue t f m
forall a b. (a -> b) -> a -> b
$ Text -> NixString
principledMakeNixStringWithoutContext "/nix/store")
  , BuiltinType
-> Text -> (NixString -> Prim m Int) -> m (Builtin (NValue t f m))
forall a.
ToBuiltin t f m a =>
BuiltinType -> Text -> a -> m (Builtin (NValue t f m))
add' BuiltinType
Normal   "stringLength"     ((NixString -> Int) -> NixString -> Prim m Int
forall a b. (a -> b) -> a -> Prim m b
arity1 ((NixString -> Int) -> NixString -> Prim m Int)
-> (NixString -> Int) -> NixString -> Prim m Int
forall a b. (a -> b) -> a -> b
$ Text -> Int
Text.length (Text -> Int) -> (NixString -> Text) -> NixString -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NixString -> Text
principledStringIgnoreContext)
  , BuiltinType
-> Text
-> (Integer -> Integer -> Prim m Integer)
-> m (Builtin (NValue t f m))
forall a.
ToBuiltin t f m a =>
BuiltinType -> Text -> a -> m (Builtin (NValue t f m))
add' BuiltinType
Normal   "sub"              ((Integer -> Integer -> Integer)
-> Integer -> Integer -> Prim m Integer
forall a b c. (a -> b -> c) -> a -> b -> Prim m c
arity2 ((-) @Integer))
  , BuiltinType
-> Text
-> (Int -> Int -> NixString -> Prim m NixString)
-> m (Builtin (NValue t f m))
forall a.
ToBuiltin t f m a =>
BuiltinType -> Text -> a -> m (Builtin (NValue t f m))
add' BuiltinType
Normal   "substring"        (MonadNix e t f m => Int -> Int -> NixString -> Prim m NixString
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
Int -> Int -> NixString -> Prim m NixString
substring @e @t @f @m)
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "tail"             NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
tail_
  , BuiltinType
-> Text -> m (NValue t f m) -> m (Builtin (NValue t f m))
forall (f :: * -> *) v e.
(MonadValue v f, MonadReader e f, Has e Frames, MonadThrow f) =>
BuiltinType -> Text -> f v -> f (Builtin v)
add0 BuiltinType
Normal   "true"             (NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant (NAtom -> NValue t f m) -> NAtom -> NValue t f m
forall a b. (a -> b) -> a -> b
$ Bool -> NAtom
NBool Bool
True)
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
TopLevel "throw"            NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
throw_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "toJSON"           NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
prim_toJSON
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "toFile"           NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
toFile
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "toPath"           NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
toPath
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
TopLevel "toString"         NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
toString
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "toXML"            NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
toXML_
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
TopLevel "trace"            NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
trace_
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "tryEval"          NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
tryEval
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "typeOf"           NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
typeOf
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "valueSize"        NValue t f m -> m (NValue t f m)
forall (m :: * -> *) (f :: * -> *) a t.
(MonadIntrospect m, Applicative f) =>
a -> m (NValue t f m)
getRecursiveSize
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "getContext"                 NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
getContext
  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "appendContext"              NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
appendContext

  , BuiltinType
-> Text
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 BuiltinType
Normal   "unsafeGetAttrPos"           NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
unsafeGetAttrPos
  , BuiltinType
-> Text
-> (NValue t f m -> m (NValue t f m))
-> m (Builtin (NValue t f m))
forall t (f :: * -> *) (f :: * -> *) e.
(MonadValue (NValue t f f) f, MonadReader e f, Has e Frames,
 MonadThrow f, MonadThunk t f (NValue t f f), Comonad f,
 Traversable f, Applicative f) =>
BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  BuiltinType
Normal   "unsafeDiscardStringContext" NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m (NValue t f m)
unsafeDiscardStringContext
  ]
 where
  wrap :: BuiltinType -> Text -> v -> Builtin v
  wrap :: BuiltinType -> Text -> v -> Builtin v
wrap t :: BuiltinType
t n :: Text
n f :: v
f = BuiltinType -> (Text, v) -> Builtin v
forall v. BuiltinType -> (Text, v) -> Builtin v
Builtin BuiltinType
t (Text
n, v
f)

  arity1 :: forall a b. (a -> b) -> (a -> Prim m b)
  arity1 :: (a -> b) -> a -> Prim m b
arity1 f :: a -> b
f = m b -> Prim m b
forall (m :: * -> *) a. m a -> Prim m a
Prim (m b -> Prim m b) -> (a -> m b) -> a -> Prim m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. b -> m b
forall (f :: * -> *) a. Applicative f => a -> f a
pure (b -> m b) -> (a -> b) -> a -> m b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f
  arity2 :: forall a b c. (a -> b -> c) -> (a -> b -> Prim m c)
  arity2 :: (a -> b -> c) -> a -> b -> Prim m c
arity2 f :: a -> b -> c
f = ((m c -> Prim m c
forall (m :: * -> *) a. m a -> Prim m a
Prim (m c -> Prim m c) -> (c -> m c) -> c -> Prim m c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. c -> m c
forall (f :: * -> *) a. Applicative f => a -> f a
pure) (c -> Prim m c) -> (b -> c) -> b -> Prim m c
forall b c a. (b -> c) -> (a -> b) -> a -> c
.) ((b -> c) -> b -> Prim m c) -> (a -> b -> c) -> a -> b -> Prim m c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b -> c
f

  mkThunk :: Text -> m v -> m v
mkThunk n :: Text
n = m v -> m v
forall v (m :: * -> *). MonadValue v m => m v -> m v
defer (m v -> m v) -> (m v -> m v) -> m v -> m v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NixLevel -> ErrorCall -> m v -> m v
forall s e (m :: * -> *) a.
(Framed e m, Exception s) =>
NixLevel -> s -> m a -> m a
withFrame
    NixLevel
Info
    (FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "While calling builtin " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Text -> FilePath
Text.unpack Text
n FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ "\n")

  add0 :: BuiltinType -> Text -> f v -> f (Builtin v)
add0 t :: BuiltinType
t n :: Text
n v :: f v
v = BuiltinType -> Text -> v -> Builtin v
forall v. BuiltinType -> Text -> v -> Builtin v
wrap BuiltinType
t Text
n (v -> Builtin v) -> f v -> f (Builtin v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> f v -> f v
forall v (m :: * -> *) e.
(MonadValue v m, MonadReader e m, Has e Frames, MonadThrow m) =>
Text -> m v -> m v
mkThunk Text
n f v
v
  add :: BuiltinType
-> Text
-> (NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add  t :: BuiltinType
t n :: Text
n v :: NValue t f f -> f (NValue t f f)
v = BuiltinType -> Text -> NValue t f f -> Builtin (NValue t f f)
forall v. BuiltinType -> Text -> v -> Builtin v
wrap BuiltinType
t Text
n (NValue t f f -> Builtin (NValue t f f))
-> f (NValue t f f) -> f (Builtin (NValue t f f))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> f (NValue t f f) -> f (NValue t f f)
forall v (m :: * -> *) e.
(MonadValue v m, MonadReader e m, Has e Frames, MonadThrow m) =>
Text -> m v -> m v
mkThunk Text
n (FilePath -> (NValue t f f -> f (NValue t f f)) -> f (NValue t f f)
forall (m :: * -> *) (f :: * -> *) t.
(MonadThunk t m (NValue t f m), MonadDataContext f m) =>
FilePath -> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
builtin (Text -> FilePath
Text.unpack Text
n) NValue t f f -> f (NValue t f f)
v)
  add2 :: BuiltinType
-> Text
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add2 t :: BuiltinType
t n :: Text
n v :: NValue t f f -> NValue t f f -> f (NValue t f f)
v = BuiltinType -> Text -> NValue t f f -> Builtin (NValue t f f)
forall v. BuiltinType -> Text -> v -> Builtin v
wrap BuiltinType
t Text
n (NValue t f f -> Builtin (NValue t f f))
-> f (NValue t f f) -> f (Builtin (NValue t f f))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> f (NValue t f f) -> f (NValue t f f)
forall v (m :: * -> *) e.
(MonadValue v m, MonadReader e m, Has e Frames, MonadThrow m) =>
Text -> m v -> m v
mkThunk Text
n (FilePath
-> (NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (NValue t f f)
forall t (m :: * -> *) (f :: * -> *).
(MonadThunk t m (NValue t f m), MonadDataContext f m) =>
FilePath
-> (NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (NValue t f m)
builtin2 (Text -> FilePath
Text.unpack Text
n) NValue t f f -> NValue t f f -> f (NValue t f f)
v)
  add3 :: BuiltinType
-> Text
-> (NValue t f f
    -> NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (Builtin (NValue t f f))
add3 t :: BuiltinType
t n :: Text
n v :: NValue t f f -> NValue t f f -> NValue t f f -> f (NValue t f f)
v = BuiltinType -> Text -> NValue t f f -> Builtin (NValue t f f)
forall v. BuiltinType -> Text -> v -> Builtin v
wrap BuiltinType
t Text
n (NValue t f f -> Builtin (NValue t f f))
-> f (NValue t f f) -> f (Builtin (NValue t f f))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> f (NValue t f f) -> f (NValue t f f)
forall v (m :: * -> *) e.
(MonadValue v m, MonadReader e m, Has e Frames, MonadThrow m) =>
Text -> m v -> m v
mkThunk Text
n (FilePath
-> (NValue t f f
    -> NValue t f f -> NValue t f f -> f (NValue t f f))
-> f (NValue t f f)
forall t (m :: * -> *) (f :: * -> *).
(MonadThunk t m (NValue t f m), MonadDataContext f m) =>
FilePath
-> (NValue t f m
    -> NValue t f m -> NValue t f m -> m (NValue t f m))
-> m (NValue t f m)
builtin3 (Text -> FilePath
Text.unpack Text
n) NValue t f f -> NValue t f f -> NValue t f f -> f (NValue t f f)
v)

  add' :: forall a. ToBuiltin t f m a
       => BuiltinType -> Text -> a -> m (Builtin (NValue t f m))
  add' :: BuiltinType -> Text -> a -> m (Builtin (NValue t f m))
add' t :: BuiltinType
t n :: Text
n v :: a
v = BuiltinType -> Text -> NValue t f m -> Builtin (NValue t f m)
forall v. BuiltinType -> Text -> v -> Builtin v
wrap BuiltinType
t Text
n (NValue t f m -> Builtin (NValue t f m))
-> m (NValue t f m) -> m (Builtin (NValue t f m))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> m (NValue t f m) -> m (NValue t f m)
forall v (m :: * -> *) e.
(MonadValue v m, MonadReader e m, Has e Frames, MonadThrow m) =>
Text -> m v -> m v
mkThunk Text
n (FilePath -> a -> m (NValue t f m)
forall t (f :: * -> *) (m :: * -> *) a.
ToBuiltin t f m a =>
FilePath -> a -> m (NValue t f m)
toBuiltin (Text -> FilePath
Text.unpack Text
n) a
v)

-- Primops

foldNixPath
  :: forall e t f m r
   . MonadNix e t f m
  => (FilePath -> Maybe String -> NixPathEntryType -> r -> m r)
  -> r
  -> m r
foldNixPath :: (FilePath -> Maybe FilePath -> NixPathEntryType -> r -> m r)
-> r -> m r
foldNixPath f :: FilePath -> Maybe FilePath -> NixPathEntryType -> r -> m r
f z :: r
z = do
  Maybe (NValue t f m)
mres <- Text -> m (Maybe (NValue t f m))
forall a (m :: * -> *). Scoped a m => Text -> m (Maybe a)
lookupVar "__includes"
  [NixString]
dirs <- case Maybe (NValue t f m)
mres of
    Nothing -> [NixString] -> m [NixString]
forall (m :: * -> *) a. Monad m => a -> m a
return []
    Just v :: NValue t f m
v  -> NValue t f m -> (NValue t f m -> m [NixString]) -> m [NixString]
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
v ((NValue t f m -> m [NixString]) -> m [NixString])
-> (NValue t f m -> m [NixString]) -> m [NixString]
forall a b. (a -> b) -> a -> b
$ Deeper (NValue t f m) -> m [NixString]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (Deeper (NValue t f m) -> m [NixString])
-> (NValue t f m -> Deeper (NValue t f m))
-> NValue t f m
-> m [NixString]
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
  Maybe FilePath
mPath <- FilePath -> m (Maybe FilePath)
forall (m :: * -> *). MonadEnv m => FilePath -> m (Maybe FilePath)
getEnvVar "NIX_PATH"
  Maybe FilePath
mDataDir <- FilePath -> m (Maybe FilePath)
forall (m :: * -> *). MonadEnv m => FilePath -> m (Maybe FilePath)
getEnvVar "NIX_DATA_DIR"
  FilePath
dataDir <- case Maybe FilePath
mDataDir of
    Nothing -> m FilePath
forall (m :: * -> *). MonadPaths m => m FilePath
getDataDir
    Just dataDir :: FilePath
dataDir -> FilePath -> m FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
dataDir
  ((Text, NixPathEntryType) -> r -> m r)
-> r -> [(Text, NixPathEntryType)] -> m r
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> b -> m b) -> b -> t a -> m b
foldrM (Text, NixPathEntryType) -> r -> m r
go r
z
    ([(Text, NixPathEntryType)] -> m r)
-> [(Text, NixPathEntryType)] -> m r
forall a b. (a -> b) -> a -> b
$  (NixString -> (Text, NixPathEntryType))
-> [NixString] -> [(Text, NixPathEntryType)]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> (Text, NixPathEntryType)
fromInclude (Text -> (Text, NixPathEntryType))
-> (NixString -> Text) -> NixString -> (Text, NixPathEntryType)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NixString -> Text
principledStringIgnoreContext) [NixString]
dirs
    [(Text, NixPathEntryType)]
-> [(Text, NixPathEntryType)] -> [(Text, NixPathEntryType)]
forall a. [a] -> [a] -> [a]
++ case Maybe FilePath
mPath of
         Nothing  -> []
         Just str :: FilePath
str -> Text -> [(Text, NixPathEntryType)]
uriAwareSplit (FilePath -> Text
Text.pack FilePath
str)
    [(Text, NixPathEntryType)]
-> [(Text, NixPathEntryType)] -> [(Text, NixPathEntryType)]
forall a. [a] -> [a] -> [a]
++ [ Text -> (Text, NixPathEntryType)
fromInclude (Text -> (Text, NixPathEntryType))
-> Text -> (Text, NixPathEntryType)
forall a b. (a -> b) -> a -> b
$ FilePath -> Text
Text.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ "nix=" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
dataDir FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ "/nix/corepkgs" ]
 where
  fromInclude :: Text -> (Text, NixPathEntryType)
fromInclude x :: Text
x | "://" Text -> Text -> Bool
`Text.isInfixOf` Text
x = (Text
x, NixPathEntryType
PathEntryURI)
                | Bool
otherwise                = (Text
x, NixPathEntryType
PathEntryPath)
  go :: (Text, NixPathEntryType) -> r -> m r
go (x :: Text
x, ty :: NixPathEntryType
ty) rest :: r
rest = case Text -> Text -> [Text]
Text.splitOn "=" Text
x of
    [p :: Text
p] -> FilePath -> Maybe FilePath -> NixPathEntryType -> r -> m r
f (Text -> FilePath
Text.unpack Text
p) Maybe FilePath
forall a. Maybe a
Nothing NixPathEntryType
ty r
rest
    [n :: Text
n, p :: Text
p] -> FilePath -> Maybe FilePath -> NixPathEntryType -> r -> m r
f (Text -> FilePath
Text.unpack Text
p) (FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just (Text -> FilePath
Text.unpack Text
n)) NixPathEntryType
ty r
rest
    _ -> ErrorCall -> m r
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m r) -> ErrorCall -> m r
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "Unexpected entry in NIX_PATH: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Text -> FilePath
forall a. Show a => a -> FilePath
show Text
x

nixPath :: MonadNix e t f m => m (NValue t f m)
nixPath :: m (NValue t f m)
nixPath = ([NValue t f m] -> NValue t f m)
-> 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
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
[NValue t f m] -> NValue t f m
nvList (m [NValue t f m] -> m (NValue t f m))
-> m [NValue t f m] -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ ((FilePath
  -> Maybe FilePath
  -> NixPathEntryType
  -> [NValue t f m]
  -> m [NValue t f m])
 -> [NValue t f m] -> m [NValue t f m])
-> [NValue t f m]
-> (FilePath
    -> Maybe FilePath
    -> NixPathEntryType
    -> [NValue t f m]
    -> m [NValue t f m])
-> m [NValue t f m]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (FilePath
 -> Maybe FilePath
 -> NixPathEntryType
 -> [NValue t f m]
 -> m [NValue t f m])
-> [NValue t f m] -> m [NValue t f m]
forall e t (f :: * -> *) (m :: * -> *) r.
MonadNix e t f m =>
(FilePath -> Maybe FilePath -> NixPathEntryType -> r -> m r)
-> r -> m r
foldNixPath [] ((FilePath
  -> Maybe FilePath
  -> NixPathEntryType
  -> [NValue t f m]
  -> m [NValue t f m])
 -> m [NValue t f m])
-> (FilePath
    -> Maybe FilePath
    -> NixPathEntryType
    -> [NValue t f m]
    -> m [NValue t f m])
-> m [NValue t f m]
forall a b. (a -> b) -> a -> b
$ \p :: FilePath
p mn :: Maybe FilePath
mn ty :: NixPathEntryType
ty rest :: [NValue t f m]
rest ->
  [NValue t f m] -> m [NValue t f m]
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    ([NValue t f m] -> m [NValue t f m])
-> [NValue t f m] -> m [NValue t f m]
forall a b. (a -> b) -> a -> b
$ ((HashMap Text (NValue t f m)
 -> HashMap Text SourcePos -> NValue t f m)
-> HashMap Text SourcePos
-> HashMap Text (NValue t f m)
-> NValue t f m
forall a b c. (a -> b -> c) -> b -> a -> c
flip HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
nvSet HashMap Text SourcePos
forall a. Monoid a => a
mempty (HashMap Text (NValue t f m) -> NValue t f m)
-> HashMap Text (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
        [ case NixPathEntryType
ty of
          PathEntryPath -> ("path", FilePath -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
FilePath -> NValue t f m
nvPath FilePath
p)
          PathEntryURI ->
            ( "uri"
            , NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr (Text -> NixString
hackyMakeNixStringWithoutContext (FilePath -> Text
Text.pack FilePath
p))
            )
        , ( "prefix"
          , NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr
            (Text -> NixString
hackyMakeNixStringWithoutContext (Text -> NixString) -> Text -> NixString
forall a b. (a -> b) -> a -> b
$ FilePath -> Text
Text.pack (FilePath -> Maybe FilePath -> FilePath
forall a. a -> Maybe a -> a
fromMaybe "" Maybe FilePath
mn))
          )
        ]
      )
    NValue t f m -> [NValue t f m] -> [NValue t f m]
forall a. a -> [a] -> [a]
: [NValue t f m]
rest

toString :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
toString :: NValue t f m -> m (NValue t f m)
toString = (NValue t f m -> NValue t f m -> m (NValue t f m))
-> CopyToStoreMode -> CoercionLevel -> NValue t f m -> m NixString
forall e (m :: * -> *) t (f :: * -> *).
(Framed e m, MonadStore m, MonadThrow m,
 MonadDataErrorContext t f m, MonadValue (NValue t f m) m) =>
(NValue t f m -> NValue t f m -> m (NValue t f m))
-> CopyToStoreMode -> CoercionLevel -> NValue t f m -> m NixString
coerceToString NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
callFunc CopyToStoreMode
DontCopyToStore CoercionLevel
CoerceAny (NValue t f m -> m NixString)
-> (NixString -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue

hasAttr
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
hasAttr :: NValue t f m -> NValue t f m -> m (NValue t f m)
hasAttr x :: NValue t f m
x y :: NValue t f m
y = NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
x m NixString -> (NixString -> m Text) -> m Text
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext m Text -> (Text -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \key :: Text
key ->
  NValue t f m -> m (AttrSet (NValue t f m), HashMap Text SourcePos)
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @(AttrSet (NValue t f m), AttrSet SourcePos) NValue t f m
y
    m (AttrSet (NValue t f m), HashMap Text SourcePos)
-> ((AttrSet (NValue t f m), HashMap Text SourcePos)
    -> m (NValue t f m))
-> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(aset :: AttrSet (NValue t f m)
aset, _) -> Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Bool -> m (NValue t f m)) -> Bool -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ Text -> AttrSet (NValue t f m) -> Bool
forall k a. (Eq k, Hashable k) => k -> HashMap k a -> Bool
M.member Text
key AttrSet (NValue t f m)
aset

attrsetGet :: MonadNix e t f m => Text -> AttrSet (NValue t f m) -> m (NValue t f m)
attrsetGet :: Text -> AttrSet (NValue t f m) -> m (NValue t f m)
attrsetGet k :: Text
k s :: AttrSet (NValue t f m)
s = case 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
k AttrSet (NValue t f m)
s of
  Just v :: NValue t f m
v -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure NValue t f m
v
  Nothing ->
    ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "Attribute '" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Text -> FilePath
Text.unpack Text
k FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ "' required"

hasContext :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
hasContext :: NValue t f m -> m (NValue t f m)
hasContext = Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Bool -> m (NValue t f m))
-> (NixString -> Bool) -> NixString -> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NixString -> Bool
stringHasContext (NixString -> m (NValue t f m))
-> (NValue t f m -> m NixString)
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue

getAttr
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
getAttr :: NValue t f m -> NValue t f m -> m (NValue t f m)
getAttr x :: NValue t f m
x y :: NValue t f m
y = NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
x m NixString -> (NixString -> m Text) -> m Text
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext m Text -> (Text -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \key :: Text
key ->
  NValue t f m -> m (AttrSet (NValue t f m), HashMap Text SourcePos)
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @(AttrSet (NValue t f m), AttrSet SourcePos) NValue t f m
y
    m (AttrSet (NValue t f m), HashMap Text SourcePos)
-> ((AttrSet (NValue t f m), HashMap Text SourcePos)
    -> m (NValue t f m))
-> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(aset :: AttrSet (NValue t f m)
aset, _) -> Text -> AttrSet (NValue t f m) -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
Text -> AttrSet (NValue t f m) -> m (NValue t f m)
attrsetGet Text
key AttrSet (NValue t f m)
aset

unsafeGetAttrPos
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
unsafeGetAttrPos :: NValue t f m -> NValue t f m -> m (NValue t f m)
unsafeGetAttrPos x :: NValue t f m
x y :: NValue t f m
y = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
x ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \x' :: NValue t f m
x' -> NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
y ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \y' :: NValue t f m
y' -> case (NValue t f m
x', NValue t f m
y') of
  (NVStr ns :: NixString
ns, NVSet _ apos :: HashMap Text SourcePos
apos) ->
    case Text -> HashMap Text SourcePos -> Maybe SourcePos
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
M.lookup (NixString -> Text
hackyStringIgnoreContext NixString
ns) HashMap Text SourcePos
apos of
      Nothing    -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant NAtom
NNull
      Just delta :: SourcePos
delta -> SourcePos -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue SourcePos
delta
  (x :: NValue t f m
x, y :: NValue t f m
y) ->
    ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
      (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
      (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "Invalid types for builtins.unsafeGetAttrPos: "
      FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ (NValue t f m, NValue t f m) -> FilePath
forall a. Show a => a -> FilePath
show (NValue t f m
x, NValue t f m
y)

-- This function is a bit special in that it doesn't care about the contents
-- of the list.
length_
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
length_ :: NValue t f m -> m (NValue t f m)
length_ = Int -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Int -> m (NValue t f m))
-> ([NValue t f m] -> Int) -> [NValue t f m] -> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([NValue t f m] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length :: [NValue t f m] -> Int) ([NValue t f m] -> m (NValue t f m))
-> (NValue t f m -> m [NValue t f m])
-> NValue t f m
-> m (NValue t f m)
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 a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue

add_
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
add_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
add_ x :: NValue t f m
x y :: NValue t f m
y = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
x ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \x' :: NValue t f m
x' -> NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
y ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \y' :: NValue t f m
y' -> case (NValue t f m
x', NValue t f m
y') of
  (NVConstant (NInt   x :: Integer
x), NVConstant (NInt y :: Integer
y)  ) -> Integer -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Integer
x Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
y :: Integer)
  (NVConstant (NFloat x :: Float
x), NVConstant (NInt y :: Integer
y)  ) -> Float -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Float
x Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
y)
  (NVConstant (NInt   x :: Integer
x), NVConstant (NFloat y :: Float
y)) -> Float -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
x Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
y)
  (NVConstant (NFloat x :: Float
x), NVConstant (NFloat y :: Float
y)) -> Float -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Float
x Float -> Float -> Float
forall a. Num a => a -> a -> a
+ Float
y)
  (_                    , _                    ) -> ValueFrame t f m -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ValueFrame t f m -> m (NValue t f m))
-> ValueFrame t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NValue t f m -> NValue t f m -> ValueFrame t f m
forall t (f :: * -> *) (m :: * -> *).
NValue t f m -> NValue t f m -> ValueFrame t f m
Addition NValue t f m
x' NValue t f m
y'

mul_
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
mul_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
mul_ x :: NValue t f m
x y :: NValue t f m
y = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
x ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \x' :: NValue t f m
x' -> NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
y ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \y' :: NValue t f m
y' -> case (NValue t f m
x', NValue t f m
y') of
  (NVConstant (NInt   x :: Integer
x), NVConstant (NInt y :: Integer
y)  ) -> Integer -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Integer
x Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
* Integer
y :: Integer)
  (NVConstant (NFloat x :: Float
x), NVConstant (NInt y :: Integer
y)  ) -> Float -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Float
x Float -> Float -> Float
forall a. Num a => a -> a -> a
* Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
y)
  (NVConstant (NInt   x :: Integer
x), NVConstant (NFloat y :: Float
y)) -> Float -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
x Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
y)
  (NVConstant (NFloat x :: Float
x), NVConstant (NFloat y :: Float
y)) -> Float -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Float
x Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
y)
  (_, _) -> ValueFrame t f m -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ValueFrame t f m -> m (NValue t f m))
-> ValueFrame t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NValue t f m -> NValue t f m -> ValueFrame t f m
forall t (f :: * -> *) (m :: * -> *).
NValue t f m -> NValue t f m -> ValueFrame t f m
Multiplication NValue t f m
x' NValue t f m
y'

div_
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
div_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
div_ x :: NValue t f m
x y :: NValue t f m
y = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
x ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \x' :: NValue t f m
x' -> NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
y ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \y' :: NValue t f m
y' -> case (NValue t f m
x', NValue t f m
y') of
  (NVConstant (NInt x :: Integer
x), NVConstant (NInt y :: Integer
y)) | Integer
y Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
/= 0 ->
    Integer -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Double -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
floor (Integer -> Double
forall a. Num a => Integer -> a
fromInteger Integer
x Double -> Double -> Double
forall a. Fractional a => a -> a -> a
/ Integer -> Double
forall a. Num a => Integer -> a
fromInteger Integer
y :: Double) :: Integer)
  (NVConstant (NFloat x :: Float
x), NVConstant (NInt y :: Integer
y)) | Integer
y Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
/= 0 ->
    Float -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Float
x Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
y)
  (NVConstant (NInt x :: Integer
x), NVConstant (NFloat y :: Float
y)) | Float
y Float -> Float -> Bool
forall a. Eq a => a -> a -> Bool
/= 0 ->
    Float -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
x Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
y)
  (NVConstant (NFloat x :: Float
x), NVConstant (NFloat y :: Float
y)) | Float
y Float -> Float -> Bool
forall a. Eq a => a -> a -> Bool
/= 0 -> Float -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Float
x Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
y)
  (_, _) -> ValueFrame t f m -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ValueFrame t f m -> m (NValue t f m))
-> ValueFrame t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NValue t f m -> NValue t f m -> ValueFrame t f m
forall t (f :: * -> *) (m :: * -> *).
NValue t f m -> NValue t f m -> ValueFrame t f m
Division NValue t f m
x' NValue t f m
y'

anyM :: Monad m => (a -> m Bool) -> [a] -> m Bool
anyM :: (a -> m Bool) -> [a] -> m Bool
anyM _ []       = Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
anyM p :: a -> m Bool
p (x :: a
x : xs :: [a]
xs) = do
  Bool
q <- a -> m Bool
p a
x
  if Bool
q then Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True else (a -> m Bool) -> [a] -> m Bool
forall (m :: * -> *) a. Monad m => (a -> m Bool) -> [a] -> m Bool
anyM a -> m Bool
p [a]
xs

any_
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
any_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
any_ f :: NValue t f m
f = Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Bool -> m (NValue t f m))
-> (NValue t f m -> m Bool) -> NValue t f m -> m (NValue t f m)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< (NValue t f m -> m Bool) -> [NValue t f m] -> m Bool
forall (m :: * -> *) a. Monad m => (a -> m Bool) -> [a] -> m Bool
anyM NValue t f m -> m Bool
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue ([NValue t f m] -> m Bool)
-> (NValue t f m -> m [NValue t f m]) -> NValue t f m -> m Bool
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))
-> [NValue t f m] -> m [NValue t f m]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (NValue t f m
f NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc`) ([NValue t f m] -> m [NValue t f m])
-> (NValue t f m -> m [NValue t f m])
-> NValue t f m
-> m [NValue t f m]
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 a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue

allM :: Monad m => (a -> m Bool) -> [a] -> m Bool
allM :: (a -> m Bool) -> [a] -> m Bool
allM _ []       = Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
allM p :: a -> m Bool
p (x :: a
x : xs :: [a]
xs) = do
  Bool
q <- a -> m Bool
p a
x
  if Bool
q then (a -> m Bool) -> [a] -> m Bool
forall (m :: * -> *) a. Monad m => (a -> m Bool) -> [a] -> m Bool
allM a -> m Bool
p [a]
xs else Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False

all_
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
all_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
all_ f :: NValue t f m
f = Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Bool -> m (NValue t f m))
-> (NValue t f m -> m Bool) -> NValue t f m -> m (NValue t f m)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< (NValue t f m -> m Bool) -> [NValue t f m] -> m Bool
forall (m :: * -> *) a. Monad m => (a -> m Bool) -> [a] -> m Bool
allM NValue t f m -> m Bool
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue ([NValue t f m] -> m Bool)
-> (NValue t f m -> m [NValue t f m]) -> NValue t f m -> m Bool
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))
-> [NValue t f m] -> m [NValue t f m]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (NValue t f m
f NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc`) ([NValue t f m] -> m [NValue t f m])
-> (NValue t f m -> m [NValue t f m])
-> NValue t f m
-> m [NValue t f m]
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 a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue

foldl'_
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
foldl'_ :: NValue t f m -> NValue t f m -> NValue t f m -> m (NValue t f m)
foldl'_ f :: NValue t f m
f z :: NValue t f m
z xs :: NValue t f m
xs = NValue t f m -> m [NValue t f m]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @[NValue t f m] NValue t f m
xs m [NValue t f m]
-> ([NValue t f m] -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (NValue t f m -> NValue t f m -> m (NValue t f m))
-> NValue t f m -> [NValue t f m] -> m (NValue t f m)
forall (t :: * -> *) (m :: * -> *) b a.
(Foldable t, Monad m) =>
(b -> a -> m b) -> b -> t a -> m b
foldM NValue t f m -> NValue t f m -> m (NValue t f m)
go NValue t f m
z
  where go :: NValue t f m -> NValue t f m -> m (NValue t f m)
go b :: NValue t f m
b a :: NValue t f m
a = NValue t f m
f NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc` NValue t f m
b m (NValue t f m)
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc` NValue t f m
a)

head_ :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
head_ :: NValue t f m -> m (NValue t f m)
head_ = NValue t f m -> m [NValue t f m]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m [NValue t f m])
-> ([NValue t f m] -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \case
  []    -> ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall "builtins.head: empty list"
  h :: NValue t f m
h : _ -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure NValue t f m
h

tail_ :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
tail_ :: NValue t f m -> m (NValue t f m)
tail_ = NValue t f m -> m [NValue t f m]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m [NValue t f m])
-> ([NValue t f m] -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \case
  []    -> ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall "builtins.tail: empty list"
  _ : t :: [NValue t f m]
t -> NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ [NValue t f m] -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
[NValue t f m] -> NValue t f m
nvList [NValue t f m]
t

data VersionComponent
   = VersionComponent_Pre -- ^ The string "pre"
   | VersionComponent_String Text -- ^ A string other than "pre"
   | VersionComponent_Number Integer -- ^ A number
   deriving (Int -> VersionComponent -> FilePath -> FilePath
[VersionComponent] -> FilePath -> FilePath
VersionComponent -> FilePath
(Int -> VersionComponent -> FilePath -> FilePath)
-> (VersionComponent -> FilePath)
-> ([VersionComponent] -> FilePath -> FilePath)
-> Show VersionComponent
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
showList :: [VersionComponent] -> FilePath -> FilePath
$cshowList :: [VersionComponent] -> FilePath -> FilePath
show :: VersionComponent -> FilePath
$cshow :: VersionComponent -> FilePath
showsPrec :: Int -> VersionComponent -> FilePath -> FilePath
$cshowsPrec :: Int -> VersionComponent -> FilePath -> FilePath
Show, ReadPrec [VersionComponent]
ReadPrec VersionComponent
Int -> ReadS VersionComponent
ReadS [VersionComponent]
(Int -> ReadS VersionComponent)
-> ReadS [VersionComponent]
-> ReadPrec VersionComponent
-> ReadPrec [VersionComponent]
-> Read VersionComponent
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [VersionComponent]
$creadListPrec :: ReadPrec [VersionComponent]
readPrec :: ReadPrec VersionComponent
$creadPrec :: ReadPrec VersionComponent
readList :: ReadS [VersionComponent]
$creadList :: ReadS [VersionComponent]
readsPrec :: Int -> ReadS VersionComponent
$creadsPrec :: Int -> ReadS VersionComponent
Read, VersionComponent -> VersionComponent -> Bool
(VersionComponent -> VersionComponent -> Bool)
-> (VersionComponent -> VersionComponent -> Bool)
-> Eq VersionComponent
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VersionComponent -> VersionComponent -> Bool
$c/= :: VersionComponent -> VersionComponent -> Bool
== :: VersionComponent -> VersionComponent -> Bool
$c== :: VersionComponent -> VersionComponent -> Bool
Eq, Eq VersionComponent
Eq VersionComponent =>
(VersionComponent -> VersionComponent -> Ordering)
-> (VersionComponent -> VersionComponent -> Bool)
-> (VersionComponent -> VersionComponent -> Bool)
-> (VersionComponent -> VersionComponent -> Bool)
-> (VersionComponent -> VersionComponent -> Bool)
-> (VersionComponent -> VersionComponent -> VersionComponent)
-> (VersionComponent -> VersionComponent -> VersionComponent)
-> Ord VersionComponent
VersionComponent -> VersionComponent -> Bool
VersionComponent -> VersionComponent -> Ordering
VersionComponent -> VersionComponent -> VersionComponent
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: VersionComponent -> VersionComponent -> VersionComponent
$cmin :: VersionComponent -> VersionComponent -> VersionComponent
max :: VersionComponent -> VersionComponent -> VersionComponent
$cmax :: VersionComponent -> VersionComponent -> VersionComponent
>= :: VersionComponent -> VersionComponent -> Bool
$c>= :: VersionComponent -> VersionComponent -> Bool
> :: VersionComponent -> VersionComponent -> Bool
$c> :: VersionComponent -> VersionComponent -> Bool
<= :: VersionComponent -> VersionComponent -> Bool
$c<= :: VersionComponent -> VersionComponent -> Bool
< :: VersionComponent -> VersionComponent -> Bool
$c< :: VersionComponent -> VersionComponent -> Bool
compare :: VersionComponent -> VersionComponent -> Ordering
$ccompare :: VersionComponent -> VersionComponent -> Ordering
$cp1Ord :: Eq VersionComponent
Ord)

versionComponentToString :: VersionComponent -> Text
versionComponentToString :: VersionComponent -> Text
versionComponentToString = \case
  VersionComponent_Pre      -> "pre"
  VersionComponent_String s :: Text
s -> Text
s
  VersionComponent_Number n :: Integer
n -> FilePath -> Text
Text.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ Integer -> FilePath
forall a. Show a => a -> FilePath
show Integer
n

-- | Based on https://github.com/NixOS/nix/blob/4ee4fda521137fed6af0446948b3877e0c5db803/src/libexpr/names.cc#L44
versionComponentSeparators :: String
versionComponentSeparators :: FilePath
versionComponentSeparators = ".-"

splitVersion :: Text -> [VersionComponent]
splitVersion :: Text -> [VersionComponent]
splitVersion s :: Text
s = case Text -> Maybe (Char, Text)
Text.uncons Text
s of
  Nothing -> []
  Just (h :: Char
h, t :: Text
t)
    | Char
h Char -> FilePath -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` FilePath
versionComponentSeparators
    -> Text -> [VersionComponent]
splitVersion Text
t
    | Char -> Bool
isDigit Char
h
    -> let (digits :: Text
digits, rest :: Text
rest) = (Char -> Bool) -> Text -> (Text, Text)
Text.span Char -> Bool
isDigit Text
s
       in
         Integer -> VersionComponent
VersionComponent_Number
             (Integer -> Maybe Integer -> Integer
forall a. a -> Maybe a -> a
fromMaybe (FilePath -> Integer
forall a. HasCallStack => FilePath -> a
error (FilePath -> Integer) -> FilePath -> Integer
forall a b. (a -> b) -> a -> b
$ "splitVersion: couldn't parse " FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> Text -> FilePath
forall a. Show a => a -> FilePath
show Text
digits)
             (Maybe Integer -> Integer) -> Maybe Integer -> Integer
forall a b. (a -> b) -> a -> b
$ FilePath -> Maybe Integer
forall a. Read a => FilePath -> Maybe a
readMaybe
             (FilePath -> Maybe Integer) -> FilePath -> Maybe Integer
forall a b. (a -> b) -> a -> b
$ Text -> FilePath
Text.unpack Text
digits
             )
           VersionComponent -> [VersionComponent] -> [VersionComponent]
forall a. a -> [a] -> [a]
: Text -> [VersionComponent]
splitVersion Text
rest
    | Bool
otherwise
    -> let (chars :: Text
chars, rest :: Text
rest) = (Char -> Bool) -> Text -> (Text, Text)
Text.span
             (\c :: Char
c -> Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Char -> Bool
isDigit Char
c Bool -> Bool -> Bool
|| Char
c Char -> FilePath -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` FilePath
versionComponentSeparators)
             Text
s
           thisComponent :: VersionComponent
thisComponent = case Text
chars of
             "pre" -> VersionComponent
VersionComponent_Pre
             x :: Text
x     -> Text -> VersionComponent
VersionComponent_String Text
x
       in  VersionComponent
thisComponent VersionComponent -> [VersionComponent] -> [VersionComponent]
forall a. a -> [a] -> [a]
: Text -> [VersionComponent]
splitVersion Text
rest

splitVersion_ :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
splitVersion_ :: NValue t f m -> m (NValue t f m)
splitVersion_ = NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m NixString)
-> (NixString -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext (NixString -> m Text)
-> (Text -> m (NValue t f m)) -> NixString -> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \s :: Text
s ->
  NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a. Monad m => a -> m a
return
    (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ [NValue t f m] -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
[NValue t f m] -> NValue t f m
nvList
    ([NValue t f m] -> NValue t f m) -> [NValue t f m] -> NValue t f m
forall a b. (a -> b) -> a -> b
$ ((VersionComponent -> NValue t f m)
 -> [VersionComponent] -> [NValue t f m])
-> [VersionComponent]
-> (VersionComponent -> NValue t f m)
-> [NValue t f m]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (VersionComponent -> NValue t f m)
-> [VersionComponent] -> [NValue t f m]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> [VersionComponent]
splitVersion Text
s)
    ((VersionComponent -> NValue t f m) -> [NValue t f m])
-> (VersionComponent -> NValue t f m) -> [NValue t f m]
forall a b. (a -> b) -> a -> b
$ NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr
    (NixString -> NValue t f m)
-> (VersionComponent -> NixString)
-> VersionComponent
-> NValue t f m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> NixString
principledMakeNixStringWithoutContext
    (Text -> NixString)
-> (VersionComponent -> Text) -> VersionComponent -> NixString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionComponent -> Text
versionComponentToString

compareVersions :: Text -> Text -> Ordering
compareVersions :: Text -> Text -> Ordering
compareVersions s1 :: Text
s1 s2 :: Text
s2 = [Ordering] -> Ordering
forall a. Monoid a => [a] -> a
mconcat
  ([Ordering] -> Ordering) -> [Ordering] -> Ordering
forall a b. (a -> b) -> a -> b
$ (These VersionComponent VersionComponent -> Ordering)
-> [VersionComponent] -> [VersionComponent] -> [Ordering]
forall (f :: * -> *) a b c.
Semialign f =>
(These a b -> c) -> f a -> f b -> f c
alignWith These VersionComponent VersionComponent -> Ordering
f (Text -> [VersionComponent]
splitVersion Text
s1) (Text -> [VersionComponent]
splitVersion Text
s2)
 where
  z :: VersionComponent
z = Text -> VersionComponent
VersionComponent_String ""
  f :: These VersionComponent VersionComponent -> Ordering
f = (VersionComponent -> VersionComponent -> Ordering)
-> (VersionComponent, VersionComponent) -> Ordering
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry VersionComponent -> VersionComponent -> Ordering
forall a. Ord a => a -> a -> Ordering
compare ((VersionComponent, VersionComponent) -> Ordering)
-> (These VersionComponent VersionComponent
    -> (VersionComponent, VersionComponent))
-> These VersionComponent VersionComponent
-> Ordering
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VersionComponent
-> VersionComponent
-> These VersionComponent VersionComponent
-> (VersionComponent, VersionComponent)
forall a b. a -> b -> These a b -> (a, b)
fromThese VersionComponent
z VersionComponent
z

compareVersions_
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
compareVersions_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
compareVersions_ t1 :: NValue t f m
t1 t2 :: NValue t f m
t2 = NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
t1 m NixString -> (NixString -> m Text) -> m Text
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext m Text -> (Text -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \s1 :: Text
s1 ->
  NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
t2 m NixString -> (NixString -> m Text) -> m Text
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext m Text -> (Text -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \s2 :: Text
s2 ->
    NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant (NAtom -> NValue t f m) -> NAtom -> NValue t f m
forall a b. (a -> b) -> a -> b
$ Integer -> NAtom
NInt (Integer -> NAtom) -> Integer -> NAtom
forall a b. (a -> b) -> a -> b
$ case Text -> Text -> Ordering
compareVersions Text
s1 Text
s2 of
      LT -> -1
      EQ -> 0
      GT -> 1

splitDrvName :: Text -> (Text, Text)
splitDrvName :: Text -> (Text, Text)
splitDrvName s :: Text
s =
  let
    sep :: Text
sep    = "-"
    pieces :: [Text]
pieces = Text -> Text -> [Text]
Text.splitOn Text
sep Text
s
    isFirstVersionPiece :: Text -> Bool
isFirstVersionPiece p :: Text
p = case Text -> Maybe (Char, Text)
Text.uncons Text
p of
      Just (h :: Char
h, _) | Char -> Bool
isDigit Char
h -> Bool
True
      _                       -> Bool
False
    -- Like 'break', but always puts the first item into the first result
    -- list
    breakAfterFirstItem :: (a -> Bool) -> [a] -> ([a], [a])
    breakAfterFirstItem :: (a -> Bool) -> [a] -> ([a], [a])
breakAfterFirstItem f :: a -> Bool
f = \case
      h :: a
h : t :: [a]
t -> let (a :: [a]
a, b :: [a]
b) = (a -> Bool) -> [a] -> ([a], [a])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break a -> Bool
f [a]
t in (a
h a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
a, [a]
b)
      []    -> ([], [])
    (namePieces :: [Text]
namePieces, versionPieces :: [Text]
versionPieces) =
      (Text -> Bool) -> [Text] -> ([Text], [Text])
forall a. (a -> Bool) -> [a] -> ([a], [a])
breakAfterFirstItem Text -> Bool
isFirstVersionPiece [Text]
pieces
  in
    (Text -> [Text] -> Text
Text.intercalate Text
sep [Text]
namePieces, Text -> [Text] -> Text
Text.intercalate Text
sep [Text]
versionPieces)

parseDrvName
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
parseDrvName :: NValue t f m -> m (NValue t f m)
parseDrvName = NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m NixString)
-> (NixString -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext (NixString -> m Text)
-> (Text -> m (NValue t f m)) -> NixString -> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \s :: Text
s -> do
  let (Text
name :: Text, Text
version :: Text) = Text -> (Text, Text)
splitDrvName Text
s
  forall a (m :: * -> *) v. ToValue a m v => a -> m v
forall (m :: * -> *) v.
ToValue (AttrSet (NValue t f m)) m v =>
AttrSet (NValue t f m) -> m v
toValue @(AttrSet (NValue t f m)) (AttrSet (NValue t f m) -> m (NValue t f m))
-> AttrSet (NValue t f m) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ [(Text, NValue t f m)] -> AttrSet (NValue t f m)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
M.fromList
    [ ( "name" :: Text
      , NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr (NixString -> NValue t f m) -> NixString -> NValue t f m
forall a b. (a -> b) -> a -> b
$ Text -> NixString
principledMakeNixStringWithoutContext Text
name
      )
    , ( "version"
      , NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr (NixString -> NValue t f m) -> NixString -> NValue t f m
forall a b. (a -> b) -> a -> b
$ Text -> NixString
principledMakeNixStringWithoutContext Text
version
      )
    ]

match_
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
match_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
match_ pat :: NValue t f m
pat str :: NValue t f m
str = NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
pat m NixString -> (NixString -> m Text) -> m Text
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext m Text -> (Text -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \p :: Text
p ->
  NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
str m NixString -> (NixString -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ns :: NixString
ns -> do
        -- NOTE: Currently prim_match in nix/src/libexpr/primops.cc ignores the
        -- context of its second argument. This is probably a bug but we're
        -- going to preserve the behavior here until it is fixed upstream.
        -- Relevant issue: https://github.com/NixOS/nix/issues/2547
    let s :: Text
s  = NixString -> Text
principledStringIgnoreContext NixString
ns

    let re :: Regex
re = ByteString -> Regex
forall regex compOpt execOpt source.
RegexMaker regex compOpt execOpt source =>
source -> regex
makeRegex (Text -> ByteString
encodeUtf8 Text
p) :: Regex
    let mkMatch :: Text -> m v
mkMatch t :: Text
t
          | Text -> Bool
Text.null Text
t = () -> m v
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue ()
          | -- Shorthand for Null
            Bool
otherwise   = NixString -> m v
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (NixString -> m v) -> NixString -> m v
forall a b. (a -> b) -> a -> b
$ Text -> NixString
principledMakeNixStringWithoutContext Text
t
    case Regex
-> ByteString
-> Maybe (ByteString, MatchText ByteString, ByteString)
forall regex source.
RegexLike regex source =>
regex -> source -> Maybe (source, MatchText source, source)
matchOnceText Regex
re (Text -> ByteString
encodeUtf8 Text
s) of
      Just ("", sarr :: MatchText ByteString
sarr, "") -> do
        let s :: [ByteString]
s = ((ByteString, (Int, Int)) -> ByteString)
-> [(ByteString, (Int, Int))] -> [ByteString]
forall a b. (a -> b) -> [a] -> [b]
map (ByteString, (Int, Int)) -> ByteString
forall a b. (a, b) -> a
fst (MatchText ByteString -> [(ByteString, (Int, Int))]
forall i e. Array i e -> [e]
elems MatchText ByteString
sarr)
        [NValue t f m] -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
[NValue t f m] -> NValue t f m
nvList ([NValue t f m] -> NValue t f m)
-> m [NValue t f m] -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ByteString -> m (NValue t f m))
-> [ByteString] -> m [NValue t f m]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (Text -> m (NValue t f m)
forall (m :: * -> *) v.
(ToValue () m v, ToValue NixString m v) =>
Text -> m v
mkMatch (Text -> m (NValue t f m))
-> (ByteString -> Text) -> ByteString -> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Text
decodeUtf8)
                            (if [ByteString] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ByteString]
s Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> 1 then [ByteString] -> [ByteString]
forall a. [a] -> [a]
tail [ByteString]
s else [ByteString]
s)
      _ -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant NAtom
NNull

split_
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
split_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
split_ pat :: NValue t f m
pat str :: NValue t f m
str = NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
pat m NixString -> (NixString -> m Text) -> m Text
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext m Text -> (Text -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \p :: Text
p ->
  NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
str m NixString -> (NixString -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \ns :: NixString
ns -> do
        -- NOTE: Currently prim_split in nix/src/libexpr/primops.cc ignores the
        -- context of its second argument. This is probably a bug but we're
        -- going to preserve the behavior here until it is fixed upstream.
        -- Relevant issue: https://github.com/NixOS/nix/issues/2547
    let s :: Text
s = NixString -> Text
principledStringIgnoreContext NixString
ns
    let re :: Regex
re       = ByteString -> Regex
forall regex compOpt execOpt source.
RegexMaker regex compOpt execOpt source =>
source -> regex
makeRegex (Text -> ByteString
encodeUtf8 Text
p) :: Regex
        haystack :: ByteString
haystack = Text -> ByteString
encodeUtf8 Text
s
    NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ [NValue t f m] -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
[NValue t f m] -> NValue t f m
nvList ([NValue t f m] -> NValue t f m) -> [NValue t f m] -> NValue t f m
forall a b. (a -> b) -> a -> b
$ Int -> [[(ByteString, (Int, Int))]] -> ByteString -> [NValue t f m]
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
Int -> [[(ByteString, (Int, Int))]] -> ByteString -> [NValue t f m]
splitMatches 0
                                   ((MatchText ByteString -> [(ByteString, (Int, Int))])
-> [MatchText ByteString] -> [[(ByteString, (Int, Int))]]
forall a b. (a -> b) -> [a] -> [b]
map MatchText ByteString -> [(ByteString, (Int, Int))]
forall i e. Array i e -> [e]
elems ([MatchText ByteString] -> [[(ByteString, (Int, Int))]])
-> [MatchText ByteString] -> [[(ByteString, (Int, Int))]]
forall a b. (a -> b) -> a -> b
$ Regex -> ByteString -> [MatchText ByteString]
forall regex source.
RegexLike regex source =>
regex -> source -> [MatchText source]
matchAllText Regex
re ByteString
haystack)
                                   ByteString
haystack

splitMatches
  :: forall e t f m
   . MonadNix e t f m
  => Int
  -> [[(ByteString, (Int, Int))]]
  -> ByteString
  -> [NValue t f m]
splitMatches :: Int -> [[(ByteString, (Int, Int))]] -> ByteString -> [NValue t f m]
splitMatches _ [] haystack :: ByteString
haystack = [ByteString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
ByteString -> NValue t f m
thunkStr ByteString
haystack]
splitMatches _ ([] : _) _ =
  FilePath -> [NValue t f m]
forall a. HasCallStack => FilePath -> a
error "Error in splitMatches: this should never happen!"
splitMatches numDropped :: Int
numDropped (((_, (start :: Int
start, len :: Int
len)) : captures :: [(ByteString, (Int, Int))]
captures) : mts :: [[(ByteString, (Int, Int))]]
mts) haystack :: ByteString
haystack =
  ByteString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
ByteString -> NValue t f m
thunkStr ByteString
before NValue t f m -> [NValue t f m] -> [NValue t f m]
forall a. a -> [a] -> [a]
: NValue t f m
caps NValue t f m -> [NValue t f m] -> [NValue t f m]
forall a. a -> [a] -> [a]
: Int -> [[(ByteString, (Int, Int))]] -> ByteString -> [NValue t f m]
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
Int -> [[(ByteString, (Int, Int))]] -> ByteString -> [NValue t f m]
splitMatches (Int
numDropped Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
relStart Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
len)
                                        [[(ByteString, (Int, Int))]]
mts
                                        (Int -> ByteString -> ByteString
B.drop Int
len ByteString
rest)
 where
  relStart :: Int
relStart       = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max 0 Int
start Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
numDropped
  (before :: ByteString
before, rest :: ByteString
rest) = Int -> ByteString -> (ByteString, ByteString)
B.splitAt Int
relStart ByteString
haystack
  caps :: NValue t f m
caps           = [NValue t f m] -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
[NValue t f m] -> NValue t f m
nvList (((ByteString, (Int, Int)) -> NValue t f m)
-> [(ByteString, (Int, Int))] -> [NValue t f m]
forall a b. (a -> b) -> [a] -> [b]
map (ByteString, (Int, Int)) -> NValue t f m
forall a (f :: * -> *) b t (m :: * -> *).
(Ord a, Num a, Applicative f) =>
(ByteString, (a, b)) -> NValue t f m
f [(ByteString, (Int, Int))]
captures)
  f :: (ByteString, (a, b)) -> NValue t f m
f (a :: ByteString
a, (s :: a
s, _)) = if a
s a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< 0 then NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant NAtom
NNull else ByteString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
ByteString -> NValue t f m
thunkStr ByteString
a

thunkStr :: ByteString -> NValue t f m
thunkStr s :: ByteString
s = NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr (Text -> NixString
hackyMakeNixStringWithoutContext (ByteString -> Text
decodeUtf8 ByteString
s))

substring :: forall e t f m. MonadNix e t f m => Int -> Int -> NixString -> Prim m NixString
substring :: Int -> Int -> NixString -> Prim m NixString
substring start :: Int
start len :: Int
len str :: NixString
str = m NixString -> Prim m NixString
forall (m :: * -> *) a. m a -> Prim m a
Prim (m NixString -> Prim m NixString)
-> m NixString -> Prim m NixString
forall a b. (a -> b) -> a -> b
$ if Int
start Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< 0 --NOTE: negative values of 'len' are OK
  then
    ErrorCall -> m NixString
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
    (ErrorCall -> m NixString) -> ErrorCall -> m NixString
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
    (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "builtins.substring: negative start position: "
    FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Int -> FilePath
forall a. Show a => a -> FilePath
show Int
start
  else NixString -> m NixString
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NixString -> m NixString) -> NixString -> m NixString
forall a b. (a -> b) -> a -> b
$ (Text -> Text) -> NixString -> NixString
principledModifyNixContents (Int -> Text -> Text
Text.take Int
len (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> Text
Text.drop Int
start) NixString
str

attrNames
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
attrNames :: NValue t f m -> m (NValue t f m)
attrNames =
  forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue (AttrSet (NValue t f m)) m v =>
v -> m (AttrSet (NValue t f m))
fromValue @(AttrSet (NValue t f m))
    (NValue t f m -> m (AttrSet (NValue t f m)))
-> (AttrSet (NValue t f m) -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (Deeper (NValue t f m) -> NValue t f m)
-> m (Deeper (NValue t f m)) -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Deeper (NValue t f m) -> NValue t f m
forall a. Deeper a -> a
getDeeper
    (m (Deeper (NValue t f m)) -> m (NValue t f m))
-> (AttrSet (NValue t f m) -> m (Deeper (NValue t f m)))
-> AttrSet (NValue t f m)
-> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   [NixString] -> m (Deeper (NValue t f m))
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue
    ([NixString] -> m (Deeper (NValue t f m)))
-> (AttrSet (NValue t f m) -> [NixString])
-> AttrSet (NValue t f m)
-> m (Deeper (NValue t f m))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   (Text -> NixString) -> [Text] -> [NixString]
forall a b. (a -> b) -> [a] -> [b]
map Text -> NixString
principledMakeNixStringWithoutContext
    ([Text] -> [NixString])
-> (AttrSet (NValue t f m) -> [Text])
-> AttrSet (NValue t f m)
-> [NixString]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   [Text] -> [Text]
forall a. Ord a => [a] -> [a]
sort
    ([Text] -> [Text])
-> (AttrSet (NValue t f m) -> [Text])
-> AttrSet (NValue t f m)
-> [Text]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   AttrSet (NValue t f m) -> [Text]
forall k v. HashMap k v -> [k]
M.keys

attrValues
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
attrValues :: NValue t f m -> m (NValue t f m)
attrValues =
  forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue (AttrSet (NValue t f m)) m v =>
v -> m (AttrSet (NValue t f m))
fromValue @(AttrSet (NValue t f m))
    (NValue t f m -> m (AttrSet (NValue t f m)))
-> (AttrSet (NValue t f m) -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m 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] -> m (NValue t f m))
-> (AttrSet (NValue t f m) -> [NValue t f m])
-> AttrSet (NValue t f m)
-> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   ((Text, NValue t f m) -> NValue t f m)
-> [(Text, NValue t f m)] -> [NValue t f m]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text, NValue t f m) -> NValue t f m
forall a b. (a, b) -> b
snd
    ([(Text, NValue t f m)] -> [NValue t f m])
-> (AttrSet (NValue t f m) -> [(Text, NValue t f m)])
-> AttrSet (NValue t f m)
-> [NValue t f m]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   ((Text, NValue t f m) -> Text)
-> [(Text, NValue t f m)] -> [(Text, NValue t f m)]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn ((Text, NValue t f m) -> Text
forall a b. (a, b) -> a
fst @Text @(NValue t f m))
    ([(Text, NValue t f m)] -> [(Text, NValue t f m)])
-> (AttrSet (NValue t f m) -> [(Text, NValue t f m)])
-> AttrSet (NValue t f m)
-> [(Text, NValue t f m)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   AttrSet (NValue t f m) -> [(Text, NValue t f m)]
forall k v. HashMap k v -> [(k, v)]
M.toList

map_
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
map_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
map_ f :: NValue t f m
f =
  [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] -> m (NValue t f m))
-> (NValue t f m -> m [NValue t f m])
-> NValue t f m
-> m (NValue t f m)
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))
-> [NValue t f m] -> m [NValue t f m]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse
          ( forall v (m :: * -> *). MonadValue v m => m v -> m v
forall (m :: * -> *).
MonadValue (NValue t f m) m =>
m (NValue t f m) -> m (NValue t f m)
defer @(NValue t f m)
          (m (NValue t f m) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NixLevel -> ErrorCall -> m (NValue t f m) -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s) =>
NixLevel -> s -> m a -> m a
withFrame NixLevel
Debug (FilePath -> ErrorCall
ErrorCall "While applying f in map:\n")
          (m (NValue t f m) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (NValue t f m
f NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc`)
          )
    ([NValue t f m] -> m [NValue t f m])
-> (NValue t f m -> m [NValue t f m])
-> NValue t f m
-> m [NValue t f m]
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue [NValue t f m] m v =>
v -> m [NValue t f m]
fromValue @[NValue t f m]

mapAttrs_
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
mapAttrs_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
mapAttrs_ f :: NValue t f m
f xs :: NValue t f m
xs = NValue t f m -> m (AttrSet (NValue t f m))
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @(AttrSet (NValue t f m)) NValue t f m
xs m (AttrSet (NValue t f m))
-> (AttrSet (NValue t f m) -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \aset :: AttrSet (NValue t f m)
aset -> do
  let pairs :: [(Text, NValue t f m)]
pairs = AttrSet (NValue t f m) -> [(Text, NValue t f m)]
forall k v. HashMap k v -> [(k, v)]
M.toList AttrSet (NValue t f m)
aset
  [NValue t f m]
values <- [(Text, NValue t f m)]
-> ((Text, NValue t f m) -> m (NValue t f m)) -> m [NValue t f m]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for [(Text, NValue t f m)]
pairs (((Text, NValue t f m) -> m (NValue t f m)) -> m [NValue t f m])
-> ((Text, NValue t f m) -> m (NValue t f m)) -> m [NValue t f m]
forall a b. (a -> b) -> a -> b
$ \(key :: Text
key, value :: NValue t f m
value) ->
    forall v (m :: * -> *). MonadValue v m => m v -> m v
forall (m :: * -> *).
MonadValue (NValue t f m) m =>
m (NValue t f m) -> m (NValue t f m)
defer @(NValue t f m)
      (m (NValue t f m) -> m (NValue t f m))
-> m (NValue t f m) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$   NixLevel -> ErrorCall -> m (NValue t f m) -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s) =>
NixLevel -> s -> m a -> m a
withFrame NixLevel
Debug (FilePath -> ErrorCall
ErrorCall "While applying f in mapAttrs:\n")
      (m (NValue t f m) -> m (NValue t f m))
-> m (NValue t f m) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$   NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
callFunc (NValue t f m -> NValue t f m -> m (NValue t f m))
-> NValue t f m -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => f (a -> b) -> a -> f b
?? NValue t f m
value
      (NValue t f m -> m (NValue t f m))
-> m (NValue t f m) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
callFunc NValue t f m
f (NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr (Text -> NixString
principledMakeNixStringWithoutContext Text
key))
  AttrSet (NValue t f m) -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (AttrSet (NValue t f m) -> m (NValue t f m))
-> ([NValue t f m] -> AttrSet (NValue t f m))
-> [NValue t f m]
-> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Text, NValue t f m)] -> AttrSet (NValue t f m)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
M.fromList ([(Text, NValue t f m)] -> AttrSet (NValue t f m))
-> ([NValue t f m] -> [(Text, NValue t f m)])
-> [NValue t f m]
-> AttrSet (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Text] -> [NValue t f m] -> [(Text, NValue t f m)]
forall a b. [a] -> [b] -> [(a, b)]
zip (((Text, NValue t f m) -> Text) -> [(Text, NValue t f m)] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text, NValue t f m) -> Text
forall a b. (a, b) -> a
fst [(Text, NValue t f m)]
pairs) ([NValue t f m] -> m (NValue t f m))
-> [NValue t f m] -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ [NValue t f m]
values

filter_
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
filter_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
filter_ f :: NValue t f m
f =
  [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] -> m (NValue t f m))
-> (NValue t f m -> m [NValue t f m])
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< (NValue t f m -> m Bool) -> [NValue t f m] -> m [NValue t f m]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM (NValue t f m -> m Bool
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m Bool)
-> (NValue t f m -> m (NValue t f m)) -> NValue t f m -> m Bool
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
callFunc NValue t f m
f)
    ([NValue t f m] -> m [NValue t f m])
-> (NValue t f m -> m [NValue t f m])
-> NValue t f m
-> m [NValue t f m]
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 a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue

catAttrs
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
catAttrs :: NValue t f m -> NValue t f m -> m (NValue t f m)
catAttrs attrName :: NValue t f m
attrName xs :: NValue t f m
xs = NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
attrName m NixString -> (NixString -> m Text) -> m Text
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext m Text -> (Text -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \n :: Text
n ->
  NValue t f m -> m [NValue t f m]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @[NValue t f m] NValue t f m
xs m [NValue t f m]
-> ([NValue t f m] -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \l :: [NValue t f m]
l ->
    ([Maybe (NValue t f m)] -> NValue t f m)
-> m [Maybe (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
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
[NValue t f m] -> NValue t f m
nvList ([NValue t f m] -> NValue t f m)
-> ([Maybe (NValue t f m)] -> [NValue t f m])
-> [Maybe (NValue t f m)]
-> NValue t f m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe (NValue t f m)] -> [NValue t f m]
forall a. [Maybe a] -> [a]
catMaybes)
      (m [Maybe (NValue t f m)] -> m (NValue t f m))
-> m [Maybe (NValue t f m)] -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ [NValue t f m]
-> (NValue t f m -> m (Maybe (NValue t f m)))
-> m [Maybe (NValue t f m)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [NValue t f m]
l
      ((NValue t f m -> m (Maybe (NValue t f m)))
 -> m [Maybe (NValue t f m)])
-> (NValue t f m -> m (Maybe (NValue t f m)))
-> m [Maybe (NValue t f m)]
forall a b. (a -> b) -> a -> b
$ (HashMap Text (NValue t f m) -> Maybe (NValue t f m))
-> m (HashMap Text (NValue t f m)) -> m (Maybe (NValue t f m))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Text -> HashMap Text (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
n)
      (m (HashMap Text (NValue t f m)) -> m (Maybe (NValue t f m)))
-> (NValue t f m -> m (HashMap Text (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
 -> (NValue t f m -> m (HashMap Text (NValue t f m)))
 -> m (HashMap Text (NValue t f m)))
-> (NValue t f m -> m (HashMap Text (NValue t f m)))
-> NValue t f m
-> m (HashMap Text (NValue t f m))
forall a b c. (a -> b -> c) -> b -> a -> c
flip NValue t f m
-> (NValue t f m -> m (HashMap Text (NValue t f m)))
-> m (HashMap Text (NValue t f m))
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m -> m (HashMap Text (NValue t f m))
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue

baseNameOf :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
baseNameOf :: NValue t f m -> m (NValue t f m)
baseNameOf x :: NValue t f m
x = do
  NixString
ns <- (NValue t f m -> NValue t f m -> m (NValue t f m))
-> CopyToStoreMode -> CoercionLevel -> NValue t f m -> m NixString
forall e (m :: * -> *) t (f :: * -> *).
(Framed e m, MonadStore m, MonadThrow m,
 MonadDataErrorContext t f m, MonadValue (NValue t f m) m) =>
(NValue t f m -> NValue t f m -> m (NValue t f m))
-> CopyToStoreMode -> CoercionLevel -> NValue t f m -> m NixString
coerceToString NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
callFunc CopyToStoreMode
DontCopyToStore CoercionLevel
CoerceStringy NValue t f m
x
  NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr
    ((Text -> Text) -> NixString -> NixString
principledModifyNixContents (FilePath -> Text
Text.pack (FilePath -> Text) -> (Text -> FilePath) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> FilePath
takeFileName (FilePath -> FilePath) -> (Text -> FilePath) -> Text -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> FilePath
Text.unpack) NixString
ns)

bitAnd
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
bitAnd :: NValue t f m -> NValue t f m -> m (NValue t f m)
bitAnd x :: NValue t f m
x y :: NValue t f m
y =
  NValue t f m -> m Integer
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @Integer NValue t f m
x m Integer -> (Integer -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a :: Integer
a -> NValue t f m -> m Integer
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @Integer NValue t f m
y m Integer -> (Integer -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \b :: Integer
b -> Integer -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Integer
a Integer -> Integer -> Integer
forall a. Bits a => a -> a -> a
.&. Integer
b)

bitOr
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
bitOr :: NValue t f m -> NValue t f m -> m (NValue t f m)
bitOr x :: NValue t f m
x y :: NValue t f m
y =
  NValue t f m -> m Integer
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @Integer NValue t f m
x m Integer -> (Integer -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a :: Integer
a -> NValue t f m -> m Integer
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @Integer NValue t f m
y m Integer -> (Integer -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \b :: Integer
b -> Integer -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Integer
a Integer -> Integer -> Integer
forall a. Bits a => a -> a -> a
.|. Integer
b)

bitXor
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
bitXor :: NValue t f m -> NValue t f m -> m (NValue t f m)
bitXor x :: NValue t f m
x y :: NValue t f m
y = NValue t f m -> m Integer
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @Integer NValue t f m
x
  m Integer -> (Integer -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a :: Integer
a -> NValue t f m -> m Integer
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @Integer NValue t f m
y m Integer -> (Integer -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \b :: Integer
b -> Integer -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Integer
a Integer -> Integer -> Integer
forall a. Bits a => a -> a -> a
`xor` Integer
b)

dirOf :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
dirOf :: NValue t f m -> m (NValue t f m)
dirOf x :: NValue t f m
x = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
x ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \case
  NVStr ns :: NixString
ns -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr
    ((Text -> Text) -> NixString -> NixString
principledModifyNixContents (FilePath -> Text
Text.pack (FilePath -> Text) -> (Text -> FilePath) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> FilePath
takeDirectory (FilePath -> FilePath) -> (Text -> FilePath) -> Text -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> FilePath
Text.unpack) NixString
ns)
  NVPath path :: FilePath
path -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
FilePath -> NValue t f m
nvPath (FilePath -> NValue t f m) -> FilePath -> NValue t f m
forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath
takeDirectory FilePath
path
  v :: NValue t f m
v ->
    ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "dirOf: expected string or path, got " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
v

-- jww (2018-04-28): This should only be a string argument, and not coerced?
unsafeDiscardStringContext
  :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
unsafeDiscardStringContext :: NValue t f m -> m (NValue t f m)
unsafeDiscardStringContext mnv :: NValue t f m
mnv = do
  NixString
ns <- NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
mnv
  NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (NixString -> m (NValue t f m)) -> NixString -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ Text -> NixString
principledMakeNixStringWithoutContext (Text -> NixString) -> Text -> NixString
forall a b. (a -> b) -> a -> b
$ NixString -> Text
principledStringIgnoreContext
    NixString
ns

seq_
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
seq_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
seq_ a :: NValue t f m
a b :: NValue t f m
b = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
a ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \_ -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure NValue t f m
b

-- | We evaluate 'a' only for its effects, so data cycles are ignored.
deepSeq
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
deepSeq :: NValue t f m -> NValue t f m -> m (NValue t f m)
deepSeq a :: NValue t f m
a b :: NValue t f m
b = NValue t f m
b NValue t f m -> m () -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ NValue t f m -> m ()
forall e (m :: * -> *) t (f :: * -> *).
(Framed e m, MonadThunk t m (NValue t f m),
 MonadDataErrorContext t f m, Ord (ThunkId m)) =>
NValue t f m -> m ()
normalForm_ NValue t f m
a

elem_
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
elem_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
elem_ x :: NValue t f m
x = Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Bool -> m (NValue t f m))
-> (NValue t f m -> m Bool) -> NValue t f m -> m (NValue t f m)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< (NValue t f m -> m Bool) -> [NValue t f m] -> m Bool
forall (m :: * -> *) a. Monad m => (a -> m Bool) -> [a] -> m Bool
anyM (NValue t f m -> NValue t f m -> m Bool
forall t (f :: * -> *) (m :: * -> *).
(MonadThunk t m (NValue t f m), Comonad f) =>
NValue t f m -> NValue t f m -> m Bool
valueEqM NValue t f m
x) ([NValue t f m] -> m Bool)
-> (NValue t f m -> m [NValue t f m]) -> NValue t f m -> m Bool
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 a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue

elemAt :: [a] -> Int -> Maybe a
elemAt :: [a] -> Int -> Maybe a
elemAt ls :: [a]
ls i :: Int
i = case Int -> [a] -> [a]
forall a. Int -> [a] -> [a]
drop Int
i [a]
ls of
  []    -> Maybe a
forall a. Maybe a
Nothing
  a :: a
a : _ -> a -> Maybe a
forall a. a -> Maybe a
Just a
a

elemAt_
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
elemAt_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
elemAt_ xs :: NValue t f m
xs n :: NValue t f m
n = NValue t f m -> m Int
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
n m Int -> (Int -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \n' :: Int
n' -> NValue t f m -> m [NValue t f m]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
xs m [NValue t f m]
-> ([NValue t f m] -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \xs' :: [NValue t f m]
xs' ->
  case [NValue t f m] -> Int -> Maybe (NValue t f m)
forall a. [a] -> Int -> Maybe a
elemAt [NValue t f m]
xs' Int
n' of
    Just a :: NValue t f m
a -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure NValue t f m
a
    Nothing ->
      ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
        (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
        (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "builtins.elem: Index "
        FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Int -> FilePath
forall a. Show a => a -> FilePath
show Int
n'
        FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ " too large for list of length "
        FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Int -> FilePath
forall a. Show a => a -> FilePath
show ([NValue t f m] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [NValue t f m]
xs')

genList
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
genList :: NValue t f m -> NValue t f m -> m (NValue t f m)
genList f :: NValue t f m
f = forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v. FromValue Integer m v => v -> m Integer
fromValue @Integer (NValue t f m -> m Integer)
-> (Integer -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \n :: Integer
n -> if Integer
n Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
>= 0
  then [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] -> m (NValue t f m))
-> m [NValue t f m] -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< [Integer] -> (Integer -> m (NValue t f m)) -> m [NValue t f m]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [0 .. Integer
n Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- 1] (\i :: Integer
i -> m (NValue t f m) -> m (NValue t f m)
forall v (m :: * -> *). MonadValue v m => m v -> m v
defer (m (NValue t f m) -> m (NValue t f m))
-> m (NValue t f m) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ (NValue t f m
f NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc`) (NValue t f m -> m (NValue t f m))
-> m (NValue t f m) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Integer -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue Integer
i)
  else
    ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
    (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
    (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "builtins.genList: Expected a non-negative number, got "
    FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Integer -> FilePath
forall a. Show a => a -> FilePath
show Integer
n

-- We wrap values solely to provide an Ord instance for genericClosure
newtype WValue t f m = WValue (NValue t f m)

instance Comonad f => Eq (WValue t f m) where
  WValue (NVConstant (NFloat x :: Float
x)) == :: WValue t f m -> WValue t f m -> Bool
== WValue (NVConstant (NInt y :: Integer
y)) =
    Float
x Float -> Float -> Bool
forall a. Eq a => a -> a -> Bool
== Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
y
  WValue (NVConstant (NInt   x :: Integer
x)) == WValue (NVConstant (NFloat y :: Float
y)) =
    Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
x Float -> Float -> Bool
forall a. Eq a => a -> a -> Bool
== Float
y
  WValue (NVConstant (NInt   x :: Integer
x)) == WValue (NVConstant (NInt   y :: Integer
y)) = Integer
x Integer -> Integer -> Bool
forall a. Eq a => a -> a -> Bool
== Integer
y
  WValue (NVConstant (NFloat x :: Float
x)) == WValue (NVConstant (NFloat y :: Float
y)) = Float
x Float -> Float -> Bool
forall a. Eq a => a -> a -> Bool
== Float
y
  WValue (NVPath     x :: FilePath
x         ) == WValue (NVPath     y :: FilePath
y         ) = FilePath
x FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== FilePath
y
  WValue (NVStr x :: NixString
x) == WValue (NVStr y :: NixString
y) =
    NixString -> Text
hackyStringIgnoreContext NixString
x Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== NixString -> Text
hackyStringIgnoreContext NixString
y
  _ == _ = Bool
False

instance Comonad f => Ord (WValue t f m) where
  WValue (NVConstant (NFloat x :: Float
x)) <= :: WValue t f m -> WValue t f m -> Bool
<= WValue (NVConstant (NInt y :: Integer
y)) =
    Float
x Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
y
  WValue (NVConstant (NInt   x :: Integer
x)) <= WValue (NVConstant (NFloat y :: Float
y)) =
    Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
x Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
<= Float
y
  WValue (NVConstant (NInt   x :: Integer
x)) <= WValue (NVConstant (NInt   y :: Integer
y)) = Integer
x Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
<= Integer
y
  WValue (NVConstant (NFloat x :: Float
x)) <= WValue (NVConstant (NFloat y :: Float
y)) = Float
x Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
<= Float
y
  WValue (NVPath     x :: FilePath
x         ) <= WValue (NVPath     y :: FilePath
y         ) = FilePath
x FilePath -> FilePath -> Bool
forall a. Ord a => a -> a -> Bool
<= FilePath
y
  WValue (NVStr x :: NixString
x) <= WValue (NVStr y :: NixString
y) =
    NixString -> Text
hackyStringIgnoreContext NixString
x Text -> Text -> Bool
forall a. Ord a => a -> a -> Bool
<= NixString -> Text
hackyStringIgnoreContext NixString
y
  _ <= _ = Bool
False

genericClosure
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
genericClosure :: NValue t f m -> m (NValue t f m)
genericClosure = forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue (AttrSet (NValue t f m)) m v =>
v -> m (AttrSet (NValue t f m))
fromValue @(AttrSet (NValue t f m)) (NValue t f m -> m (AttrSet (NValue t f m)))
-> (AttrSet (NValue t f m) -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \s :: AttrSet (NValue t f m)
s ->
  case (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 "startSet" AttrSet (NValue t f m)
s, 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 "operator" AttrSet (NValue t f m)
s) of
    (Nothing, Nothing) ->
      ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
        (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
        (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "builtins.genericClosure: "
        FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ "Attributes 'startSet' and 'operator' required"
    (Nothing, Just _) ->
      ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
        (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall
        (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "builtins.genericClosure: Attribute 'startSet' required"
    (Just _, Nothing) ->
      ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
        (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall
        (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "builtins.genericClosure: Attribute 'operator' required"
    (Just startSet :: NValue t f m
startSet, Just operator :: NValue t f m
operator) ->
      NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
startSet ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue [NValue t f m] m v =>
v -> m [NValue t f m]
fromValue @[NValue t f m] (NValue t f m -> m [NValue t f m])
-> ([NValue t f m] -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \ss :: [NValue t f m]
ss ->
        NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
operator ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \op :: NValue t f m
op -> forall a (m :: * -> *) v. ToValue a m v => a -> m v
forall (m :: * -> *) v.
ToValue [NValue t f m] m v =>
[NValue t f m] -> m v
toValue @[NValue t f m] ([NValue t f m] -> m (NValue t f m))
-> m [NValue t f m] -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (Set (WValue t f m), [NValue t f m]) -> [NValue t f m]
forall a b. (a, b) -> b
snd ((Set (WValue t f m), [NValue t f m]) -> [NValue t f m])
-> m (Set (WValue t f m), [NValue t f m]) -> m [NValue t f m]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NValue t f m
-> [NValue t f m]
-> Set (WValue t f m)
-> m (Set (WValue t f m), [NValue t f m])
go NValue t f m
op [NValue t f m]
ss Set (WValue t f m)
forall a. Set a
S.empty
 where
  go
    :: NValue t f m
    -> [NValue t f m]
    -> Set (WValue t f m)
    -> m (Set (WValue t f m), [NValue t f m])
  go :: NValue t f m
-> [NValue t f m]
-> Set (WValue t f m)
-> m (Set (WValue t f m), [NValue t f m])
go _  []       ks :: Set (WValue t f m)
ks = (Set (WValue t f m), [NValue t f m])
-> m (Set (WValue t f m), [NValue t f m])
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Set (WValue t f m)
ks, [])
  go op :: NValue t f m
op (t :: NValue t f m
t : ts :: [NValue t f m]
ts) ks :: Set (WValue t f m)
ks = NValue t f m
-> (NValue t f m -> m (Set (WValue t f m), [NValue t f m]))
-> m (Set (WValue t f m), [NValue t f m])
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
t ((NValue t f m -> m (Set (WValue t f m), [NValue t f m]))
 -> m (Set (WValue t f m), [NValue t f m]))
-> (NValue t f m -> m (Set (WValue t f m), [NValue t f m]))
-> m (Set (WValue t f m), [NValue t f m])
forall a b. (a -> b) -> a -> b
$ \v :: NValue t f m
v -> NValue t f m -> m (AttrSet (NValue t f m))
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @(AttrSet (NValue t f m)) NValue t f m
v m (AttrSet (NValue t f m))
-> (AttrSet (NValue t f m)
    -> m (Set (WValue t f m), [NValue t f m]))
-> m (Set (WValue t f m), [NValue t f m])
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \s :: AttrSet (NValue t f m)
s -> do
    NValue t f m
k <- Text -> AttrSet (NValue t f m) -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
Text -> AttrSet (NValue t f m) -> m (NValue t f m)
attrsetGet "key" AttrSet (NValue t f m)
s
    NValue t f m
-> (NValue t f m -> m (Set (WValue t f m), [NValue t f m]))
-> m (Set (WValue t f m), [NValue t f m])
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
k ((NValue t f m -> m (Set (WValue t f m), [NValue t f m]))
 -> m (Set (WValue t f m), [NValue t f m]))
-> (NValue t f m -> m (Set (WValue t f m), [NValue t f m]))
-> m (Set (WValue t f m), [NValue t f m])
forall a b. (a -> b) -> a -> b
$ \k' :: NValue t f m
k' -> do
      if WValue t f m -> Set (WValue t f m) -> Bool
forall a. Ord a => a -> Set a -> Bool
S.member (NValue t f m -> WValue t f m
forall t (f :: * -> *) (m :: * -> *). NValue t f m -> WValue t f m
WValue NValue t f m
k') Set (WValue t f m)
ks
        then NValue t f m
-> [NValue t f m]
-> Set (WValue t f m)
-> m (Set (WValue t f m), [NValue t f m])
go NValue t f m
op [NValue t f m]
ts Set (WValue t f m)
ks
        else do
          [NValue t f m]
ys <- forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue [NValue t f m] m v =>
v -> m [NValue t f m]
fromValue @[NValue t f m] (NValue t f m -> m [NValue t f m])
-> m (NValue t f m) -> m [NValue t f m]
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< (NValue t f m
op NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc` NValue t f m
v)
          case Set (WValue t f m) -> [WValue t f m]
forall a. Set a -> [a]
S.toList Set (WValue t f m)
ks of
            []           -> NValue t f m -> NValue t f m -> m ()
forall e (m :: * -> *) t (f :: * -> *).
(Framed e m, MonadDataErrorContext t f m) =>
NValue t f m -> NValue t f m -> m ()
checkComparable NValue t f m
k' NValue t f m
k'
            WValue j :: NValue t f m
j : _ -> NValue t f m -> NValue t f m -> m ()
forall e (m :: * -> *) t (f :: * -> *).
(Framed e m, MonadDataErrorContext t f m) =>
NValue t f m -> NValue t f m -> m ()
checkComparable NValue t f m
k' NValue t f m
j
          ([NValue t f m] -> [NValue t f m])
-> (Set (WValue t f m), [NValue t f m])
-> (Set (WValue t f m), [NValue t f m])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (NValue t f m
t NValue t f m -> [NValue t f m] -> [NValue t f m]
forall a. a -> [a] -> [a]
:) ((Set (WValue t f m), [NValue t f m])
 -> (Set (WValue t f m), [NValue t f m]))
-> m (Set (WValue t f m), [NValue t f m])
-> m (Set (WValue t f m), [NValue t f m])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NValue t f m
-> [NValue t f m]
-> Set (WValue t f m)
-> m (Set (WValue t f m), [NValue t f m])
go NValue t f m
op ([NValue t f m]
ts [NValue t f m] -> [NValue t f m] -> [NValue t f m]
forall a. [a] -> [a] -> [a]
++ [NValue t f m]
ys) (WValue t f m -> Set (WValue t f m) -> Set (WValue t f m)
forall a. Ord a => a -> Set a -> Set a
S.insert (NValue t f m -> WValue t f m
forall t (f :: * -> *) (m :: * -> *). NValue t f m -> WValue t f m
WValue NValue t f m
k') Set (WValue t f m)
ks)

replaceStrings
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
replaceStrings :: NValue t f m -> NValue t f m -> NValue t f m -> m (NValue t f m)
replaceStrings tfrom :: NValue t f m
tfrom tto :: NValue t f m
tto ts :: NValue t f m
ts = Deeper (NValue t f m) -> m [NixString]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> Deeper (NValue t f m)
forall a. a -> Deeper a
Deeper NValue t f m
tfrom) m [NixString]
-> ([NixString] -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([NixString]
nsFrom :: [NixString]) ->
  Deeper (NValue t f m) -> m [NixString]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> Deeper (NValue t f m)
forall a. a -> Deeper a
Deeper NValue t f m
tto) m [NixString]
-> ([NixString] -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \([NixString]
nsTo :: [NixString]) ->
    NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
ts m NixString -> (NixString -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(NixString
ns :: NixString) -> do
      let from :: [Text]
from = (NixString -> Text) -> [NixString] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map NixString -> Text
principledStringIgnoreContext [NixString]
nsFrom
      Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([NixString] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [NixString]
nsFrom Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= [NixString] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [NixString]
nsTo)
        (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$  ErrorCall -> m ()
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
        (ErrorCall -> m ()) -> ErrorCall -> m ()
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
        (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "'from' and 'to' arguments to 'replaceStrings'"
        FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ " have different lengths"
      let
        lookupPrefix :: Text -> Maybe (Text, NixString, Text)
lookupPrefix s :: Text
s = do
          (prefix :: Text
prefix, replacement :: NixString
replacement) <- ((Text, NixString) -> Bool)
-> [(Text, NixString)] -> Maybe (Text, NixString)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((Text -> Text -> Bool
`Text.isPrefixOf` Text
s) (Text -> Bool)
-> ((Text, NixString) -> Text) -> (Text, NixString) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text, NixString) -> Text
forall a b. (a, b) -> a
fst)
            ([(Text, NixString)] -> Maybe (Text, NixString))
-> [(Text, NixString)] -> Maybe (Text, NixString)
forall a b. (a -> b) -> a -> b
$ [Text] -> [NixString] -> [(Text, NixString)]
forall a b. [a] -> [b] -> [(a, b)]
zip [Text]
from [NixString]
nsTo
          let rest :: Text
rest = Int -> Text -> Text
Text.drop (Text -> Int
Text.length Text
prefix) Text
s
          (Text, NixString, Text) -> Maybe (Text, NixString, Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
prefix, NixString
replacement, Text
rest)
        finish :: Builder -> HashSet StringContext -> NixString
finish b :: Builder
b =
          Text -> HashSet StringContext -> NixString
principledMakeNixString (Text -> Text
LazyText.toStrict (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ Builder -> Text
Builder.toLazyText Builder
b)
        go :: Text -> Builder -> HashSet StringContext -> NixString
go orig :: Text
orig result :: Builder
result ctx :: HashSet StringContext
ctx = case Text -> Maybe (Text, NixString, Text)
lookupPrefix Text
orig of
          Nothing -> case Text -> Maybe (Char, Text)
Text.uncons Text
orig of
            Nothing     -> Builder -> HashSet StringContext -> NixString
finish Builder
result HashSet StringContext
ctx
            Just (h :: Char
h, t :: Text
t) -> Text -> Builder -> HashSet StringContext -> NixString
go Text
t (Builder
result Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Char -> Builder
Builder.singleton Char
h) HashSet StringContext
ctx
          Just (prefix :: Text
prefix, replacementNS :: NixString
replacementNS, rest :: Text
rest) ->
            let replacement :: Text
replacement = NixString -> Text
principledStringIgnoreContext NixString
replacementNS
                newCtx :: HashSet StringContext
newCtx      = NixString -> HashSet StringContext
principledGetContext NixString
replacementNS
            in  case Text
prefix of
                  "" -> case Text -> Maybe (Char, Text)
Text.uncons Text
rest of
                    Nothing -> Builder -> HashSet StringContext -> NixString
finish
                      (Builder
result Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
Builder.fromText Text
replacement)
                      (HashSet StringContext
ctx HashSet StringContext
-> HashSet StringContext -> HashSet StringContext
forall a. Semigroup a => a -> a -> a
<> HashSet StringContext
newCtx)
                    Just (h :: Char
h, t :: Text
t) -> Text -> Builder -> HashSet StringContext -> NixString
go
                      Text
t
                      ([Builder] -> Builder
forall a. Monoid a => [a] -> a
mconcat
                        [ Builder
result
                        , Text -> Builder
Builder.fromText Text
replacement
                        , Char -> Builder
Builder.singleton Char
h
                        ]
                      )
                      (HashSet StringContext
ctx HashSet StringContext
-> HashSet StringContext -> HashSet StringContext
forall a. Semigroup a => a -> a -> a
<> HashSet StringContext
newCtx)
                  _ -> Text -> Builder -> HashSet StringContext -> NixString
go Text
rest
                          (Builder
result Builder -> Builder -> Builder
forall a. Semigroup a => a -> a -> a
<> Text -> Builder
Builder.fromText Text
replacement)
                          (HashSet StringContext
ctx HashSet StringContext
-> HashSet StringContext -> HashSet StringContext
forall a. Semigroup a => a -> a -> a
<> HashSet StringContext
newCtx)
      NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue
        (NixString -> m (NValue t f m)) -> NixString -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ Text -> Builder -> HashSet StringContext -> NixString
go (NixString -> Text
principledStringIgnoreContext NixString
ns) Builder
forall a. Monoid a => a
mempty
        (HashSet StringContext -> NixString)
-> HashSet StringContext -> NixString
forall a b. (a -> b) -> a -> b
$ NixString -> HashSet StringContext
principledGetContext NixString
ns

removeAttrs
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
removeAttrs :: NValue t f m -> NValue t f m -> m (NValue t f m)
removeAttrs set :: NValue t f m
set = Deeper (NValue t f m) -> m [NixString]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (Deeper (NValue t f m) -> m [NixString])
-> (NValue t f m -> Deeper (NValue t f m))
-> NValue t f m
-> m [NixString]
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 [NixString])
-> ([NixString] -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \([NixString]
nsToRemove :: [NixString]) ->
  NValue t f m -> m (AttrSet (NValue t f m), HashMap Text SourcePos)
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @(AttrSet (NValue t f m), AttrSet SourcePos) NValue t f m
set m (AttrSet (NValue t f m), HashMap Text SourcePos)
-> ((AttrSet (NValue t f m), HashMap Text SourcePos)
    -> m (NValue t f m))
-> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(m :: AttrSet (NValue t f m)
m, p :: HashMap Text SourcePos
p) -> do
    [Text]
toRemove <- (NixString -> m Text) -> [NixString] -> m [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext [NixString]
nsToRemove
    (AttrSet (NValue t f m), HashMap Text SourcePos)
-> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (AttrSet (NValue t f m) -> [Text] -> AttrSet (NValue t f m)
forall v. HashMap Text v -> [Text] -> HashMap Text v
go AttrSet (NValue t f m)
m [Text]
toRemove, HashMap Text SourcePos -> [Text] -> HashMap Text SourcePos
forall v. HashMap Text v -> [Text] -> HashMap Text v
go HashMap Text SourcePos
p [Text]
toRemove)
  where go :: HashMap Text v -> [Text] -> HashMap Text v
go = (HashMap Text v -> Text -> HashMap Text v)
-> HashMap Text v -> [Text] -> HashMap Text v
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' ((Text -> HashMap Text v -> HashMap Text v)
-> HashMap Text v -> Text -> HashMap Text v
forall a b c. (a -> b -> c) -> b -> a -> c
flip Text -> HashMap Text v -> HashMap Text v
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> HashMap k v
M.delete)

intersectAttrs
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
intersectAttrs :: NValue t f m -> NValue t f m -> m (NValue t f m)
intersectAttrs set1 :: NValue t f m
set1 set2 :: NValue t f m
set2 =
  NValue t f m -> m (AttrSet (NValue t f m), HashMap Text SourcePos)
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @(AttrSet (NValue t f m), AttrSet SourcePos) NValue t f m
set1 m (AttrSet (NValue t f m), HashMap Text SourcePos)
-> ((AttrSet (NValue t f m), HashMap Text SourcePos)
    -> m (NValue t f m))
-> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(s1 :: AttrSet (NValue t f m)
s1, p1 :: HashMap Text SourcePos
p1) ->
    NValue t f m -> m (AttrSet (NValue t f m), HashMap Text SourcePos)
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @(AttrSet (NValue t f m), AttrSet SourcePos) NValue t f m
set2 m (AttrSet (NValue t f m), HashMap Text SourcePos)
-> ((AttrSet (NValue t f m), HashMap Text SourcePos)
    -> m (NValue t f m))
-> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(s2 :: AttrSet (NValue t f m)
s2, p2 :: HashMap Text SourcePos
p2) ->
      NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ AttrSet (NValue t f m) -> HashMap Text SourcePos -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
nvSet (AttrSet (NValue t f m)
s2 AttrSet (NValue t f m)
-> AttrSet (NValue t f m) -> AttrSet (NValue t f m)
forall k v w.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k w -> HashMap k v
`M.intersection` AttrSet (NValue t f m)
s1) (HashMap Text SourcePos
p2 HashMap Text SourcePos
-> HashMap Text SourcePos -> HashMap Text SourcePos
forall k v w.
(Eq k, Hashable k) =>
HashMap k v -> HashMap k w -> HashMap k v
`M.intersection` HashMap Text SourcePos
p1)

functionArgs
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
functionArgs :: NValue t f m -> m (NValue t f m)
functionArgs fun :: NValue t f m
fun = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
fun ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \case
  NVClosure p :: Params ()
p _ ->
    forall a (m :: * -> *) v. ToValue a m v => a -> m v
forall (m :: * -> *) v.
ToValue (AttrSet (NValue t f m)) m v =>
AttrSet (NValue t f m) -> m v
toValue @(AttrSet (NValue t f m)) (AttrSet (NValue t f m) -> m (NValue t f m))
-> AttrSet (NValue t f m) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant (NAtom -> NValue t f m) -> (Bool -> NAtom) -> Bool -> NValue t f m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> NAtom
NBool (Bool -> NValue t f m)
-> HashMap Text Bool -> AttrSet (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case Params ()
p of
      Param name :: Text
name     -> Text -> Bool -> HashMap Text Bool
forall k v. Hashable k => k -> v -> HashMap k v
M.singleton Text
name Bool
False
      ParamSet s :: ParamSet ()
s _ _ -> Maybe () -> Bool
forall a. Maybe a -> Bool
isJust (Maybe () -> Bool) -> HashMap Text (Maybe ()) -> HashMap Text Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParamSet () -> HashMap Text (Maybe ())
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
M.fromList ParamSet ()
s
  v :: NValue t f m
v ->
    ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
      (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
      (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "builtins.functionArgs: expected function, got "
      FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
v

toFile
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
toFile :: NValue t f m -> NValue t f m -> m (NValue t f m)
toFile name :: NValue t f m
name s :: NValue t f m
s = do
  Text
name' <- NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext (NixString -> m Text) -> m NixString -> m Text
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
name
  NixString
s'    <- NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
s
  -- TODO Using hacky here because we still need to turn the context into
  -- runtime references of the resulting file.
  -- See prim_toFile in nix/src/libexpr/primops.cc
  StorePath
mres  <- FilePath -> FilePath -> m StorePath
forall e (m :: * -> *).
(Framed e m, MonadStore m) =>
FilePath -> FilePath -> m StorePath
toFile_ (Text -> FilePath
Text.unpack Text
name')
                   (Text -> FilePath
Text.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ NixString -> Text
hackyStringIgnoreContext NixString
s')
  let t :: Text
t  = FilePath -> Text
Text.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ StorePath -> FilePath
unStorePath StorePath
mres
      sc :: StringContext
sc = Text -> ContextFlavor -> StringContext
StringContext Text
t ContextFlavor
DirectPath
  NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (NixString -> m (NValue t f m)) -> NixString -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ Text -> StringContext -> NixString
principledMakeNixStringWithSingletonContext Text
t StringContext
sc

toPath :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
toPath :: NValue t f m -> m (NValue t f m)
toPath = forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v. FromValue Path m v => v -> m Path
fromValue @Path (NValue t f m -> m Path)
-> (Path -> m (NValue t f m)) -> NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> forall a (m :: * -> *) v. ToValue a m v => a -> m v
forall (m :: * -> *) v. ToValue Path m v => Path -> m v
toValue @Path

pathExists_ :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
pathExists_ :: NValue t f m -> m (NValue t f m)
pathExists_ path :: NValue t f m
path = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
path ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \case
  NVPath p :: FilePath
p  -> Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Bool -> m (NValue t f m)) -> m Bool -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< FilePath -> m Bool
forall (m :: * -> *). MonadFile m => FilePath -> m Bool
pathExists FilePath
p
  NVStr  ns :: NixString
ns -> Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Bool -> m (NValue t f m)) -> m Bool -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< FilePath -> m Bool
forall (m :: * -> *). MonadFile m => FilePath -> m Bool
pathExists (Text -> FilePath
Text.unpack (NixString -> Text
hackyStringIgnoreContext NixString
ns))
  v :: NValue t f m
v ->
    ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
      (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
      (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "builtins.pathExists: expected path, got "
      FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
v

hasKind
  :: forall a e t f m
   . (MonadNix e t f m, FromValue a m (NValue t f m))
  => NValue t f m
  -> m (NValue t f m)
hasKind :: NValue t f m -> m (NValue t f m)
hasKind = 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))
-> (Maybe a -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (Bool -> m (NValue t f m))
-> (Maybe a -> Bool) -> Maybe a -> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
  Just (a
_ :: a) -> Bool
True
  _             -> Bool
False

isAttrs
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
isAttrs :: NValue t f m -> m (NValue t f m)
isAttrs = forall a e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue a m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m,
 FromValue (AttrSet (NValue t f m)) m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
hasKind @(AttrSet (NValue t f m))

isList
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
isList :: NValue t f m -> m (NValue t f m)
isList = forall a e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue a m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue [NValue t f m] m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
hasKind @[NValue t f m]

isString
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
isString :: NValue t f m -> m (NValue t f m)
isString = forall a e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue a m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue NixString m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
hasKind @NixString

isInt
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
isInt :: NValue t f m -> m (NValue t f m)
isInt = forall a e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue a m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue Int m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
hasKind @Int

isFloat
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
isFloat :: NValue t f m -> m (NValue t f m)
isFloat = forall a e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue a m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue Float m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
hasKind @Float

isBool
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
isBool :: NValue t f m -> m (NValue t f m)
isBool = forall a e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue a m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue Bool m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
hasKind @Bool

isNull
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
isNull :: NValue t f m -> m (NValue t f m)
isNull = forall a e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue a m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, FromValue () m (NValue t f m)) =>
NValue t f m -> m (NValue t f m)
hasKind @()

isFunction :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
isFunction :: NValue t f m -> m (NValue t f m)
isFunction func :: NValue t f m
func = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
func ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \case
  NVClosure{} -> Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue Bool
True
  _           -> Bool -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue Bool
False

throw_ :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
throw_ :: NValue t f m -> m (NValue t f m)
throw_ mnv :: NValue t f m
mnv = do
  NixString
ns <- (NValue t f m -> NValue t f m -> m (NValue t f m))
-> CopyToStoreMode -> CoercionLevel -> NValue t f m -> m NixString
forall e (m :: * -> *) t (f :: * -> *).
(Framed e m, MonadStore m, MonadThrow m,
 MonadDataErrorContext t f m, MonadValue (NValue t f m) m) =>
(NValue t f m -> NValue t f m -> m (NValue t f m))
-> CopyToStoreMode -> CoercionLevel -> NValue t f m -> m NixString
coerceToString NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
callFunc CopyToStoreMode
CopyToStore CoercionLevel
CoerceStringy NValue t f m
mnv
  ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m (NValue t f m))
-> (Text -> ErrorCall) -> Text -> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> (Text -> FilePath) -> Text -> ErrorCall
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> FilePath
Text.unpack (Text -> m (NValue t f m)) -> Text -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NixString -> Text
principledStringIgnoreContext NixString
ns

import_
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
import_ :: NValue t f m -> m (NValue t f m)
import_ = NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
scopedImport (HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
nvSet HashMap Text (NValue t f m)
forall k v. HashMap k v
M.empty HashMap Text SourcePos
forall k v. HashMap k v
M.empty)

scopedImport
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
scopedImport :: NValue t f m -> NValue t f m -> m (NValue t f m)
scopedImport asetArg :: NValue t f m
asetArg pathArg :: NValue t f m
pathArg = NValue t f m -> m (AttrSet (NValue t f m))
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @(AttrSet (NValue t f m)) NValue t f m
asetArg m (AttrSet (NValue t f m))
-> (AttrSet (NValue t f m) -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \s :: AttrSet (NValue t f m)
s ->
  NValue t f m -> m Path
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
pathArg m Path -> (Path -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \(Path p :: FilePath
p) -> do
    FilePath
path  <- FilePath -> m FilePath
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
FilePath -> m FilePath
pathToDefaultNix @t @f @m FilePath
p
    Maybe (NValue t f m)
mres  <- Text -> m (Maybe (NValue t f m))
forall a (m :: * -> *). Scoped a m => Text -> m (Maybe a)
lookupVar "__cur_file"
    FilePath
path' <- case Maybe (NValue t f m)
mres of
      Nothing -> do
        FilePath -> m ()
forall (m :: * -> *). Monad m => FilePath -> m ()
traceM "No known current directory"
        FilePath -> m FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
path
      Just p :: NValue t f m
p -> NValue t f m -> (NValue t f m -> m FilePath) -> m FilePath
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
p ((NValue t f m -> m FilePath) -> m FilePath)
-> (NValue t f m -> m FilePath) -> m FilePath
forall a b. (a -> b) -> a -> b
$ NValue t f m -> m Path
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m Path)
-> (Path -> m FilePath) -> NValue t f m -> m FilePath
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \(Path p' :: FilePath
p') -> do
        FilePath -> m ()
forall (m :: * -> *). Monad m => FilePath -> m ()
traceM (FilePath -> m ()) -> FilePath -> m ()
forall a b. (a -> b) -> a -> b
$ "Current file being evaluated is: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath -> FilePath
forall a. Show a => a -> FilePath
show FilePath
p'
        FilePath -> m FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return (FilePath -> m FilePath) -> FilePath -> m FilePath
forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath
takeDirectory FilePath
p' FilePath -> FilePath -> FilePath
</> FilePath
path
    forall a (m :: * -> *) r. Scoped a m => m r -> m r
forall (m :: * -> *) r. Scoped (NValue t f m) m => m r -> m r
clearScopes @(NValue t f m)
      (m (NValue t f m) -> m (NValue t f m))
-> m (NValue t f m) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ Maybe FilePath -> m (NValue t f m) -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *) r.
(MonadNix e t f m, Has e Options) =>
Maybe FilePath -> m r -> m r
withNixContext (FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
path')
      (m (NValue t f m) -> m (NValue t f m))
-> m (NValue t f m) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ AttrSet (NValue t f m) -> m (NValue t f m) -> m (NValue t f m)
forall a (m :: * -> *) r. Scoped a m => AttrSet a -> m r -> m r
pushScope AttrSet (NValue t f m)
s
      (m (NValue t f m) -> m (NValue t f m))
-> m (NValue t f m) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> m (NValue t f m)
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
FilePath -> m (NValue t f m)
importPath @t @f @m FilePath
path'

getEnv_ :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
getEnv_ :: NValue t f m -> m (NValue t f m)
getEnv_ = NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m NixString)
-> (NixString -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext (NixString -> m Text)
-> (Text -> m (NValue t f m)) -> NixString -> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \s :: Text
s -> do
  Maybe FilePath
mres <- FilePath -> m (Maybe FilePath)
forall (m :: * -> *). MonadEnv m => FilePath -> m (Maybe FilePath)
getEnvVar (Text -> FilePath
Text.unpack Text
s)
  NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (NixString -> m (NValue t f m)) -> NixString -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ Text -> NixString
principledMakeNixStringWithoutContext (Text -> NixString) -> Text -> NixString
forall a b. (a -> b) -> a -> b
$ case Maybe FilePath
mres of
    Nothing -> ""
    Just v :: FilePath
v  -> FilePath -> Text
Text.pack FilePath
v

sort_
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
sort_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
sort_ comp :: NValue t f m
comp = NValue t f m -> m [NValue t f m]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m [NValue t f m])
-> ([NValue t f m] -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (NValue t f m -> NValue t f m -> m Ordering)
-> [NValue t f m] -> m [NValue t f m]
forall (m :: * -> *) a.
Monad m =>
(a -> a -> m Ordering) -> [a] -> m [a]
sortByM (NValue t f m -> NValue t f m -> NValue t f m -> m Ordering
forall e (m :: * -> *) t (f :: * -> *).
(MonadReader e m, MonadValue (NValue t f m) m,
 HasCitations1 m (NValue t f m) f, HasCitations m (NValue t f m) t,
 Traversable f, Comonad f, MonadThunk t m (NValue t f m),
 MonadEffects t f m, Alternative m, MonadCatch m, MonadFix m,
 Scoped (NValue t f m) m, Applicative f, Has e Frames,
 Has e Options, Has e SrcSpan, Show t, Typeable f, Typeable m,
 Typeable t) =>
NValue t f m -> NValue t f m -> NValue t f m -> m Ordering
cmp NValue t f m
comp) ([NValue t f m] -> m [NValue t f m])
-> ([NValue t f m] -> m (NValue t f m))
-> [NValue t f m]
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> [NValue t f m] -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue
 where
  cmp :: NValue t f m -> NValue t f m -> NValue t f m -> m Ordering
cmp f :: NValue t f m
f a :: NValue t f m
a b :: NValue t f m
b = do
    NValue t f m
isLessThan <- NValue t f m
f NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc` NValue t f m
a m (NValue t f m)
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc` NValue t f m
b)
    NValue t f m -> m Bool
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
isLessThan m Bool -> (Bool -> m Ordering) -> m Ordering
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
      True  -> Ordering -> m Ordering
forall (f :: * -> *) a. Applicative f => a -> f a
pure Ordering
LT
      False -> do
        NValue t f m
isGreaterThan <- NValue t f m
f NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc` NValue t f m
b m (NValue t f m)
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc` NValue t f m
a)
        NValue t f m -> m Bool
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
isGreaterThan m Bool -> (Bool -> Ordering) -> m Ordering
forall (f :: * -> *) a c. Functor f => f a -> (a -> c) -> f c
<&> \case
          True  -> Ordering
GT
          False -> Ordering
EQ

lessThan
  :: MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
lessThan :: NValue t f m -> NValue t f m -> m (NValue t f m)
lessThan ta :: NValue t f m
ta tb :: NValue t f m
tb = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
ta ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \va :: NValue t f m
va -> NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
tb ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \vb :: NValue t f m
vb -> do
  let badType :: m Bool
badType =
        ErrorCall -> m Bool
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
          (ErrorCall -> m Bool) -> ErrorCall -> m Bool
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
          (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "builtins.lessThan: expected two numbers or two strings, "
          FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ "got "
          FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
va
          FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ " and "
          FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
vb
  NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant (NAtom -> NValue t f m) -> (Bool -> NAtom) -> Bool -> NValue t f m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> NAtom
NBool (Bool -> NValue t f m) -> m Bool -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> case (NValue t f m
va, NValue t f m
vb) of
    (NVConstant ca :: NAtom
ca, NVConstant cb :: NAtom
cb) -> case (NAtom
ca, NAtom
cb) of
      (NInt   a :: Integer
a, NInt b :: Integer
b  ) -> Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> m Bool) -> Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ Integer
a Integer -> Integer -> Bool
forall a. Ord a => a -> a -> Bool
< Integer
b
      (NFloat a :: Float
a, NInt b :: Integer
b  ) -> Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> m Bool) -> Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ Float
a Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
< Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
b
      (NInt   a :: Integer
a, NFloat b :: Float
b) -> Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> m Bool) -> Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ Integer -> Float
forall a. Num a => Integer -> a
fromInteger Integer
a Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
< Float
b
      (NFloat a :: Float
a, NFloat b :: Float
b) -> Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> m Bool) -> Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ Float
a Float -> Float -> Bool
forall a. Ord a => a -> a -> Bool
< Float
b
      _                    -> m Bool
badType
    (NVStr a :: NixString
a, NVStr b :: NixString
b) ->
      Bool -> m Bool
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Bool -> m Bool) -> Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ NixString -> Text
principledStringIgnoreContext NixString
a Text -> Text -> Bool
forall a. Ord a => a -> a -> Bool
< NixString -> Text
principledStringIgnoreContext NixString
b
    _ -> m Bool
badType

concatLists
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
concatLists :: NValue t f m -> m (NValue t f m)
concatLists =
  forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue [NValue t f m] m v =>
v -> m [NValue t f m]
fromValue @[NValue t f m]
    (NValue t f m -> m [NValue t f m])
-> ([NValue t f m] -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (NValue t f m -> m [NValue t f m])
-> [NValue t f m] -> m [[NValue t f m]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((NValue t f m
 -> (NValue t f m -> m [NValue t f m]) -> m [NValue t f m])
-> (NValue t f m -> m [NValue t f m])
-> NValue t f m
-> m [NValue t f m]
forall a b c. (a -> b -> c) -> b -> a -> c
flip NValue t f m
-> (NValue t f m -> m [NValue t f m]) -> m [NValue t f m]
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand ((NValue t f m -> m [NValue t f m])
 -> NValue t f m -> m [NValue t f m])
-> (NValue t f m -> m [NValue t f m])
-> NValue t f m
-> m [NValue t f m]
forall a b. (a -> b) -> a -> b
$ forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue [NValue t f m] m v =>
v -> m [NValue t f m]
fromValue @[NValue t f m] (NValue t f m -> m [NValue t f m])
-> ([NValue t f m] -> m [NValue t f m])
-> NValue t f m
-> m [NValue t f m]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> [NValue t f m] -> m [NValue t f m]
forall (f :: * -> *) a. Applicative f => a -> f a
pure)
    ([NValue t f m] -> m [[NValue t f m]])
-> ([[NValue t f m]] -> m (NValue t f m))
-> [NValue t f m]
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m 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] -> m (NValue t f m))
-> ([[NValue t f m]] -> [NValue t f m])
-> [[NValue t f m]]
-> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   [[NValue t f m]] -> [NValue t f m]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat

concatMap_
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
concatMap_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
concatMap_ f :: NValue t f m
f =
  forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue [NValue t f m] m v =>
v -> m [NValue t f m]
fromValue @[NValue t f m]
    (NValue t f m -> m [NValue t f m])
-> ([NValue t f m] -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (NValue t f m -> m [NValue t f m])
-> [NValue t f m] -> m [[NValue t f m]]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse NValue t f m -> m [NValue t f m]
applyFunc
    ([NValue t f m] -> m [[NValue t f m]])
-> ([[NValue t f m]] -> m (NValue t f m))
-> [NValue t f m]
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m 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] -> m (NValue t f m))
-> ([[NValue t f m]] -> [NValue t f m])
-> [[NValue t f m]]
-> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[NValue t f m]] -> [NValue t f m]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
  where
    applyFunc :: NValue t f m  -> m [NValue t f m]
    applyFunc :: NValue t f m -> m [NValue t f m]
applyFunc =  (NValue t f m
f NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc`) (NValue t f m -> m (NValue t f m))
-> (NValue t f m -> m [NValue t f m])
-> NValue t f m
-> m [NValue t f m]
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> NValue t f m -> m [NValue t f m]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue

listToAttrs
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
listToAttrs :: NValue t f m -> m (NValue t f m)
listToAttrs = forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue [NValue t f m] m v =>
v -> m [NValue t f m]
fromValue @[NValue t f m] (NValue t f m -> m [NValue t f m])
-> ([NValue t f m] -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \l :: [NValue t f m]
l ->
  ([(Text, NValue t f m)] -> NValue t f m)
-> m [(Text, NValue t f m)] -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((HashMap Text (NValue t f m)
 -> HashMap Text SourcePos -> NValue t f m)
-> HashMap Text SourcePos
-> HashMap Text (NValue t f m)
-> NValue t f m
forall a b c. (a -> b -> c) -> b -> a -> c
flip HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
nvSet HashMap Text SourcePos
forall k v. HashMap k v
M.empty (HashMap Text (NValue t f m) -> NValue t f m)
-> ([(Text, NValue t f m)] -> HashMap Text (NValue t f m))
-> [(Text, NValue t f m)]
-> NValue t f m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(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)] -> [(Text, NValue t f m)])
-> [(Text, NValue t f m)]
-> HashMap Text (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Text, NValue t f m)] -> [(Text, NValue t f m)]
forall a. [a] -> [a]
reverse)
    (m [(Text, NValue t f m)] -> m (NValue t f m))
-> m [(Text, NValue t f m)] -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$   [NValue t f m]
-> (NValue t f m -> m (Text, NValue t f m))
-> m [(Text, NValue t f m)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [NValue t f m]
l
    ((NValue t f m -> m (Text, NValue t f m))
 -> m [(Text, NValue t f m)])
-> (NValue t f m -> m (Text, NValue t f m))
-> m [(Text, NValue t f m)]
forall a b. (a -> b) -> a -> b
$   (NValue t f m
 -> (NValue t f m -> m (Text, NValue t f m))
 -> m (Text, NValue t f m))
-> (NValue t f m -> m (Text, NValue t f m))
-> NValue t f m
-> m (Text, NValue t f m)
forall a b c. (a -> b -> c) -> b -> a -> c
flip NValue t f m
-> (NValue t f m -> m (Text, NValue t f m))
-> m (Text, NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand
    ((NValue t f m -> m (Text, NValue t f m))
 -> NValue t f m -> m (Text, NValue t f m))
-> (NValue t f m -> m (Text, NValue t f m))
-> NValue t f m
-> m (Text, NValue t f m)
forall a b. (a -> b) -> a -> b
$   forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue (HashMap Text (NValue t f m)) m v =>
v -> m (HashMap Text (NValue t f m))
fromValue @(AttrSet (NValue t f m))
    (NValue t f m -> m (HashMap Text (NValue t f m)))
-> (HashMap Text (NValue t f m) -> m (Text, NValue t f m))
-> NValue t f m
-> m (Text, NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \s :: HashMap Text (NValue t f m)
s -> do
          NValue t f m
t <- Text -> HashMap Text (NValue t f m) -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
Text -> AttrSet (NValue t f m) -> m (NValue t f m)
attrsetGet "name" HashMap Text (NValue t f m)
s
          NValue t f m
-> (NValue t f m -> m (Text, NValue t f m))
-> m (Text, NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
t ((NValue t f m -> m (Text, NValue t f m))
 -> m (Text, NValue t f m))
-> (NValue t f m -> m (Text, NValue t f m))
-> m (Text, NValue t f m)
forall a b. (a -> b) -> a -> b
$ NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m NixString)
-> (NixString -> m (Text, NValue t f m))
-> NValue t f m
-> m (Text, NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \n :: NixString
n -> do
            Text
name <- NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext NixString
n
            NValue t f m
val  <- Text -> HashMap Text (NValue t f m) -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
Text -> AttrSet (NValue t f m) -> m (NValue t f m)
attrsetGet "value" HashMap Text (NValue t f m)
s
            (Text, NValue t f m) -> m (Text, NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text
name, NValue t f m
val)

-- prim_hashString from nix/src/libexpr/primops.cc
-- fail if context in the algo arg
-- propagate context from the s arg
hashString
  :: forall e t f m. MonadNix e t f m => NixString -> NixString -> Prim m NixString
hashString :: NixString -> NixString -> Prim m NixString
hashString nsAlgo :: NixString
nsAlgo ns :: NixString
ns = m NixString -> Prim m NixString
forall (m :: * -> *) a. m a -> Prim m a
Prim (m NixString -> Prim m NixString)
-> m NixString -> Prim m NixString
forall a b. (a -> b) -> a -> b
$ do
  Text
algo <- NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext NixString
nsAlgo
  let f :: (Text -> Text) -> m NixString
f g :: Text -> Text
g = NixString -> m NixString
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NixString -> m NixString) -> NixString -> m NixString
forall a b. (a -> b) -> a -> b
$ (Text -> Text) -> NixString -> NixString
principledModifyNixContents Text -> Text
g NixString
ns
  case Text
algo of
    "md5" ->
      (Text -> Text) -> m NixString
f ((Text -> Text) -> m NixString) -> (Text -> Text) -> m NixString
forall a b. (a -> b) -> a -> b
$ \s :: Text
s ->
                FilePath -> Text
Text.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ MD5 -> FilePath
forall a. Show a => a -> FilePath
show (ByteString -> MD5
forall a. HashAlgorithm a => ByteString -> a
hash (Text -> ByteString
encodeUtf8 Text
s) :: MD5.MD5)
    "sha1" ->
      (Text -> Text) -> m NixString
f ((Text -> Text) -> m NixString) -> (Text -> Text) -> m NixString
forall a b. (a -> b) -> a -> b
$ \s :: Text
s ->
                FilePath -> Text
Text.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ SHA1 -> FilePath
forall a. Show a => a -> FilePath
show (ByteString -> SHA1
forall a. HashAlgorithm a => ByteString -> a
hash (Text -> ByteString
encodeUtf8 Text
s) :: SHA1.SHA1)
    "sha256" ->
      (Text -> Text) -> m NixString
f ((Text -> Text) -> m NixString) -> (Text -> Text) -> m NixString
forall a b. (a -> b) -> a -> b
$ \s :: Text
s ->
                FilePath -> Text
Text.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ SHA256 -> FilePath
forall a. Show a => a -> FilePath
show (ByteString -> SHA256
forall a. HashAlgorithm a => ByteString -> a
hash (Text -> ByteString
encodeUtf8 Text
s) :: SHA256.SHA256)
    "sha512" ->
      (Text -> Text) -> m NixString
f ((Text -> Text) -> m NixString) -> (Text -> Text) -> m NixString
forall a b. (a -> b) -> a -> b
$ \s :: Text
s ->
                FilePath -> Text
Text.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ SHA512 -> FilePath
forall a. Show a => a -> FilePath
show (ByteString -> SHA512
forall a. HashAlgorithm a => ByteString -> a
hash (Text -> ByteString
encodeUtf8 Text
s) :: SHA512.SHA512)
    _ ->
      ErrorCall -> m NixString
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
        (ErrorCall -> m NixString) -> ErrorCall -> m NixString
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
        (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "builtins.hashString: "
        FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ "expected \"md5\", \"sha1\", \"sha256\", or \"sha512\", got "
        FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Text -> FilePath
forall a. Show a => a -> FilePath
show Text
algo

placeHolder :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
placeHolder :: NValue t f m -> m (NValue t f m)
placeHolder = NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m NixString)
-> (NixString -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext (NixString -> m Text)
-> (Text -> m (NValue t f m)) -> NixString -> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \t :: Text
t -> do
  NixString
h <- Prim m NixString -> m NixString
forall (m :: * -> *) a. Prim m a -> m a
runPrim
    (NixString -> NixString -> Prim m NixString
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NixString -> NixString -> Prim m NixString
hashString (Text -> NixString
principledMakeNixStringWithoutContext "sha256")
                (Text -> NixString
principledMakeNixStringWithoutContext ("nix-output:" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
t))
    )
  NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue
    (NixString -> m (NValue t f m)) -> NixString -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ Text -> NixString
principledMakeNixStringWithoutContext
    (Text -> NixString) -> Text -> NixString
forall a b. (a -> b) -> a -> b
$ Char -> Text -> Text
Text.cons '/'
    (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ ByteString -> Text
Base32.encode
    (ByteString -> Text) -> ByteString -> Text
forall a b. (a -> b) -> a -> b
$ (ByteString, ByteString) -> ByteString
forall a b. (a, b) -> a
fst             -- The result coming out of hashString is base16 encoded
    ((ByteString, ByteString) -> ByteString)
-> (ByteString, ByteString) -> ByteString
forall a b. (a -> b) -> a -> b
$ ByteString -> (ByteString, ByteString)
Base16.decode
    (ByteString -> (ByteString, ByteString))
-> ByteString -> (ByteString, ByteString)
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
encodeUtf8
    (Text -> ByteString) -> Text -> ByteString
forall a b. (a -> b) -> a -> b
$ NixString -> Text
principledStringIgnoreContext NixString
h

absolutePathFromValue :: MonadNix e t f m => NValue t f m -> m FilePath
absolutePathFromValue :: NValue t f m -> m FilePath
absolutePathFromValue = \case
  NVStr ns :: NixString
ns -> do
    let path :: FilePath
path = Text -> FilePath
Text.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ NixString -> Text
hackyStringIgnoreContext NixString
ns
    Bool -> m () -> m ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FilePath -> Bool
isAbsolute FilePath
path)
      (m () -> m ()) -> m () -> m ()
forall a b. (a -> b) -> a -> b
$  ErrorCall -> m ()
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
      (ErrorCall -> m ()) -> ErrorCall -> m ()
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
      (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "string "
      FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath -> FilePath
forall a. Show a => a -> FilePath
show FilePath
path
      FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ " doesn't represent an absolute path"
    FilePath -> m FilePath
forall (f :: * -> *) a. Applicative f => a -> f a
pure FilePath
path
  NVPath path :: FilePath
path -> FilePath -> m FilePath
forall (f :: * -> *) a. Applicative f => a -> f a
pure FilePath
path
  v :: NValue t f m
v           -> ErrorCall -> m FilePath
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m FilePath) -> ErrorCall -> m FilePath
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "expected a path, got " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
v

readFile_ :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
readFile_ :: NValue t f m -> m (NValue t f m)
readFile_ path :: NValue t f m
path = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
path ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$
  NValue t f m -> m FilePath
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m FilePath
absolutePathFromValue (NValue t f m -> m FilePath)
-> (FilePath -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> FilePath -> m ByteString
forall (m :: * -> *). MonadFile m => FilePath -> m ByteString
Nix.Render.readFile (FilePath -> m ByteString)
-> (ByteString -> m (NValue t f m)) -> FilePath -> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> ByteString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue

findFile_
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
findFile_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
findFile_ aset :: NValue t f m
aset filePath :: NValue t f m
filePath = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
aset ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \aset' :: NValue t f m
aset' -> NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
filePath ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \filePath' :: NValue t f m
filePath' ->
  case (NValue t f m
aset', NValue t f m
filePath') of
    (NVList x :: [NValue t f m]
x, NVStr ns :: NixString
ns) -> do
      FilePath
mres <- [NValue t f m] -> FilePath -> m FilePath
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
[NValue t f m] -> FilePath -> m FilePath
findPath @t @f @m [NValue t f m]
x (Text -> FilePath
Text.unpack (NixString -> Text
hackyStringIgnoreContext NixString
ns))
      NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
FilePath -> NValue t f m
nvPath FilePath
mres
    (NVList _, y :: NValue t f m
y) ->
      ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "expected a string, got " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
y
    (x :: NValue t f m
x, NVStr _) -> ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "expected a list, got " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
x
    (x :: NValue t f m
x, y :: NValue t f m
y) ->
      ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "Invalid types for builtins.findFile: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ (NValue t f m, NValue t f m) -> FilePath
forall a. Show a => a -> FilePath
show
        (NValue t f m
x, NValue t f m
y)

data FileType
   = FileTypeRegular
   | FileTypeDirectory
   | FileTypeSymlink
   | FileTypeUnknown
   deriving (Int -> FileType -> FilePath -> FilePath
[FileType] -> FilePath -> FilePath
FileType -> FilePath
(Int -> FileType -> FilePath -> FilePath)
-> (FileType -> FilePath)
-> ([FileType] -> FilePath -> FilePath)
-> Show FileType
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
showList :: [FileType] -> FilePath -> FilePath
$cshowList :: [FileType] -> FilePath -> FilePath
show :: FileType -> FilePath
$cshow :: FileType -> FilePath
showsPrec :: Int -> FileType -> FilePath -> FilePath
$cshowsPrec :: Int -> FileType -> FilePath -> FilePath
Show, ReadPrec [FileType]
ReadPrec FileType
Int -> ReadS FileType
ReadS [FileType]
(Int -> ReadS FileType)
-> ReadS [FileType]
-> ReadPrec FileType
-> ReadPrec [FileType]
-> Read FileType
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FileType]
$creadListPrec :: ReadPrec [FileType]
readPrec :: ReadPrec FileType
$creadPrec :: ReadPrec FileType
readList :: ReadS [FileType]
$creadList :: ReadS [FileType]
readsPrec :: Int -> ReadS FileType
$creadsPrec :: Int -> ReadS FileType
Read, FileType -> FileType -> Bool
(FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool) -> Eq FileType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FileType -> FileType -> Bool
$c/= :: FileType -> FileType -> Bool
== :: FileType -> FileType -> Bool
$c== :: FileType -> FileType -> Bool
Eq, Eq FileType
Eq FileType =>
(FileType -> FileType -> Ordering)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> FileType)
-> (FileType -> FileType -> FileType)
-> Ord FileType
FileType -> FileType -> Bool
FileType -> FileType -> Ordering
FileType -> FileType -> FileType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FileType -> FileType -> FileType
$cmin :: FileType -> FileType -> FileType
max :: FileType -> FileType -> FileType
$cmax :: FileType -> FileType -> FileType
>= :: FileType -> FileType -> Bool
$c>= :: FileType -> FileType -> Bool
> :: FileType -> FileType -> Bool
$c> :: FileType -> FileType -> Bool
<= :: FileType -> FileType -> Bool
$c<= :: FileType -> FileType -> Bool
< :: FileType -> FileType -> Bool
$c< :: FileType -> FileType -> Bool
compare :: FileType -> FileType -> Ordering
$ccompare :: FileType -> FileType -> Ordering
$cp1Ord :: Eq FileType
Ord)

instance Convertible e t f m => ToValue FileType m (NValue t f m) where
  toValue :: FileType -> m (NValue t f m)
toValue = NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (NixString -> m (NValue t f m))
-> (FileType -> NixString) -> FileType -> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> NixString
principledMakeNixStringWithoutContext (Text -> NixString) -> (FileType -> Text) -> FileType -> NixString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
    FileTypeRegular   -> "regular" :: Text
    FileTypeDirectory -> "directory"
    FileTypeSymlink   -> "symlink"
    FileTypeUnknown   -> "unknown"

readDir_
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
readDir_ :: NValue t f m -> m (NValue t f m)
readDir_ p :: NValue t f m
p = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
p ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \path' :: NValue t f m
path' -> do
  FilePath
path           <- NValue t f m -> m FilePath
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m FilePath
absolutePathFromValue NValue t f m
path'
  [FilePath]
items          <- FilePath -> m [FilePath]
forall (m :: * -> *). MonadFile m => FilePath -> m [FilePath]
listDirectory FilePath
path
  [(Text, FileType)]
itemsWithTypes <- [FilePath]
-> (FilePath -> m (Text, FileType)) -> m [(Text, FileType)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [FilePath]
items ((FilePath -> m (Text, FileType)) -> m [(Text, FileType)])
-> (FilePath -> m (Text, FileType)) -> m [(Text, FileType)]
forall a b. (a -> b) -> a -> b
$ \item :: FilePath
item -> do
    FileStatus
s <- FilePath -> m FileStatus
forall (m :: * -> *). MonadFile m => FilePath -> m FileStatus
getSymbolicLinkStatus (FilePath -> m FileStatus) -> FilePath -> m FileStatus
forall a b. (a -> b) -> a -> b
$ FilePath
path FilePath -> FilePath -> FilePath
</> FilePath
item
    let t :: FileType
t = if
          | FileStatus -> Bool
isRegularFile FileStatus
s  -> FileType
FileTypeRegular
          | FileStatus -> Bool
isDirectory FileStatus
s    -> FileType
FileTypeDirectory
          | FileStatus -> Bool
isSymbolicLink FileStatus
s -> FileType
FileTypeSymlink
          | Bool
otherwise        -> FileType
FileTypeUnknown
    (Text, FileType) -> m (Text, FileType)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (FilePath -> Text
Text.pack FilePath
item, FileType
t)
  Deeper (NValue t f m) -> NValue t f m
forall a. Deeper a -> a
getDeeper (Deeper (NValue t f m) -> NValue t f m)
-> m (Deeper (NValue t f m)) -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> HashMap Text FileType -> m (Deeper (NValue t f m))
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue ([(Text, FileType)] -> HashMap Text FileType
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
M.fromList [(Text, FileType)]
itemsWithTypes)

fromJSON
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
fromJSON :: NValue t f m -> m (NValue t f m)
fromJSON arg :: NValue t f m
arg = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
arg ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue (NValue t f m -> m NixString)
-> (NixString -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> NixString -> m Text
forall e (m :: * -> *). Framed e m => NixString -> m Text
fromStringNoContext (NixString -> m Text)
-> (Text -> m (NValue t f m)) -> NixString -> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \encoded :: Text
encoded ->
  case FromJSON Value => ByteString -> Either FilePath Value
forall a. FromJSON a => ByteString -> Either FilePath a
A.eitherDecodeStrict' @A.Value (ByteString -> Either FilePath Value)
-> ByteString -> Either FilePath Value
forall a b. (a -> b) -> a -> b
$ Text -> ByteString
encodeUtf8 Text
encoded of
    Left jsonError :: FilePath
jsonError ->
      ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "builtins.fromJSON: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
jsonError
    Right v :: Value
v -> Value -> m (NValue t f m)
forall t (m :: * -> *). Value -> m (NValue t f m)
jsonToNValue Value
v
 where
  jsonToNValue :: Value -> m (NValue t f m)
jsonToNValue = \case
    A.Object m :: Object
m -> (HashMap Text (NValue t f m)
 -> HashMap Text SourcePos -> NValue t f m)
-> HashMap Text SourcePos
-> HashMap Text (NValue t f m)
-> NValue t f m
forall a b c. (a -> b -> c) -> b -> a -> c
flip HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
nvSet HashMap Text SourcePos
forall k v. HashMap k v
M.empty (HashMap Text (NValue t f m) -> NValue t f m)
-> m (HashMap Text (NValue t f m)) -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Value -> m (NValue t f m))
-> Object -> 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 Value -> m (NValue t f m)
jsonToNValue Object
m
    A.Array  l :: Array
l -> [NValue t f m] -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
[NValue t f m] -> NValue t f m
nvList ([NValue t f m] -> NValue t f m)
-> m [NValue t f m] -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Value -> m (NValue t f m)) -> [Value] -> m [NValue t f m]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Value -> m (NValue t f m)
jsonToNValue (Array -> [Value]
forall a. Vector a -> [a]
V.toList Array
l)
    A.String s :: Text
s -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr (NixString -> NValue t f m) -> NixString -> NValue t f m
forall a b. (a -> b) -> a -> b
$ Text -> NixString
hackyMakeNixStringWithoutContext Text
s
    A.Number n :: Scientific
n -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant (NAtom -> NValue t f m) -> NAtom -> NValue t f m
forall a b. (a -> b) -> a -> b
$ case Scientific -> Either Float Integer
forall r i. (RealFloat r, Integral i) => Scientific -> Either r i
floatingOrInteger Scientific
n of
      Left  r :: Float
r -> Float -> NAtom
NFloat Float
r
      Right i :: Integer
i -> Integer -> NAtom
NInt Integer
i
    A.Bool   b :: Bool
b -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant (NAtom -> NValue t f m) -> NAtom -> NValue t f m
forall a b. (a -> b) -> a -> b
$ Bool -> NAtom
NBool Bool
b
    A.Null     -> NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant NAtom
NNull

prim_toJSON :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
prim_toJSON :: NValue t f m -> m (NValue t f m)
prim_toJSON x :: NValue t f m
x = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
x ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ (NixString -> NValue t f m) -> m NixString -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr (m NixString -> m (NValue t f m))
-> (NValue t f m -> m NixString)
-> NValue t f m
-> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NValue t f m -> m NixString
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> m NixString
nvalueToJSONNixString

toXML_ :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
toXML_ :: NValue t f m -> m (NValue t f m)
toXML_ v :: NValue t f m
v = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
v ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ (NValue t f m -> NValue t f m)
-> m (NValue t f m) -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr (NixString -> NValue t f m)
-> (NValue t f m -> NixString) -> NValue t f m -> NValue t f m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NValue t f m -> NixString
forall t (f :: * -> *) (m :: * -> *).
MonadDataContext f m =>
NValue t f m -> NixString
toXML) (m (NValue t f m) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NValue t f m -> m (NValue t f m)
forall e (m :: * -> *) t (f :: * -> *).
(Framed e m, MonadThunk t m (NValue t f m),
 MonadDataErrorContext t f m, HasCitations m (NValue t f m) t,
 HasCitations1 m (NValue t f m) f, Ord (ThunkId m)) =>
NValue t f m -> m (NValue t f m)
normalForm

typeOf :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
typeOf :: NValue t f m -> m (NValue t f m)
typeOf v :: NValue t f m
v = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
v ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (NixString -> m (NValue t f m))
-> (NValue t f m -> NixString) -> NValue t f m -> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> NixString
principledMakeNixStringWithoutContext (Text -> NixString)
-> (NValue t f m -> Text) -> NValue t f m -> NixString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
  NVConstant a :: NAtom
a -> case NAtom
a of
    NURI   _ -> "string"
    NInt   _ -> "int"
    NFloat _ -> "float"
    NBool  _ -> "bool"
    NNull    -> "null"
  NVStr  _      -> "string"
  NVList _      -> "list"
  NVSet _ _     -> "set"
  NVClosure{}   -> "lambda"
  NVPath _      -> "path"
  NVBuiltin _ _ -> "lambda"
  _             -> FilePath -> Text
forall a. HasCallStack => FilePath -> a
error "Pattern synonyms obscure complete patterns"

tryEval
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
tryEval :: NValue t f m -> m (NValue t f m)
tryEval e :: NValue t f m
e = m (NValue t f m)
-> (SomeException -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
m a -> (e -> m a) -> m a
catch (NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
e (NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (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)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NValue t f m -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NValue t f m -> NValue t f m
onSuccess)) (NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> (SomeException -> NValue t f m)
-> SomeException
-> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SomeException -> NValue t f m
onError)
 where
  onSuccess :: NValue t f m -> NValue t f m
onSuccess v :: NValue t f m
v = (HashMap Text (NValue t f m)
 -> HashMap Text SourcePos -> NValue t f m)
-> HashMap Text SourcePos
-> HashMap Text (NValue t f m)
-> NValue t f m
forall a b c. (a -> b -> c) -> b -> a -> c
flip HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
nvSet HashMap Text SourcePos
forall k v. HashMap k v
M.empty (HashMap Text (NValue t f m) -> NValue t f m)
-> HashMap Text (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
    [("success", NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant (Bool -> NAtom
NBool Bool
True)), ("value", NValue t f m
v)]

  onError :: SomeException -> NValue t f m
  onError :: SomeException -> NValue t f m
onError _ = (HashMap Text (NValue t f m)
 -> HashMap Text SourcePos -> NValue t f m)
-> HashMap Text SourcePos
-> HashMap Text (NValue t f m)
-> NValue t f m
forall a b c. (a -> b -> c) -> b -> a -> c
flip HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
nvSet HashMap Text SourcePos
forall k v. HashMap k v
M.empty (HashMap Text (NValue t f m) -> NValue t f m)
-> HashMap Text (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
    [ ("success", NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant (Bool -> NAtom
NBool Bool
False))
    , ("value"  , NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant (Bool -> NAtom
NBool Bool
False))
    ]

trace_
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
trace_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
trace_ msg :: NValue t f m
msg action :: NValue t f m
action = do
  MonadEffects t f m => FilePath -> m ()
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
FilePath -> m ()
traceEffect @t @f @m
    (FilePath -> m ()) -> (NixString -> FilePath) -> NixString -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   Text -> FilePath
Text.unpack
    (Text -> FilePath) -> (NixString -> Text) -> NixString -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
.   NixString -> Text
principledStringIgnoreContext
    (NixString -> m ()) -> m NixString -> m ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue NValue t f m
msg
  NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure NValue t f m
action

-- TODO: remember error context
addErrorContext
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
addErrorContext :: NValue t f m -> NValue t f m -> m (NValue t f m)
addErrorContext _ action :: NValue t f m
action = NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure NValue t f m
action

exec_
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
exec_ :: NValue t f m -> m (NValue t f m)
exec_ xs :: NValue t f m
xs = do
  [NValue t f m]
ls <- NValue t f m -> m [NValue t f m]
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue @[NValue t f m] NValue t f m
xs
  [NixString]
xs <- (NValue t f m -> m NixString) -> [NValue t f m] -> m [NixString]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse ((NValue t f m -> NValue t f m -> m (NValue t f m))
-> CopyToStoreMode -> CoercionLevel -> NValue t f m -> m NixString
forall e (m :: * -> *) t (f :: * -> *).
(Framed e m, MonadStore m, MonadThrow m,
 MonadDataErrorContext t f m, MonadValue (NValue t f m) m) =>
(NValue t f m -> NValue t f m -> m (NValue t f m))
-> CopyToStoreMode -> CoercionLevel -> NValue t f m -> m NixString
coerceToString NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
callFunc CopyToStoreMode
DontCopyToStore CoercionLevel
CoerceStringy) [NValue t f m]
ls
  -- TODO Still need to do something with the context here
  -- See prim_exec in nix/src/libexpr/primops.cc
  -- Requires the implementation of EvalState::realiseContext
  [FilePath] -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
(MonadNix e t f m, MonadInstantiate m) =>
[FilePath] -> m (NValue t f m)
exec ((NixString -> FilePath) -> [NixString] -> [FilePath]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> FilePath
Text.unpack (Text -> FilePath) -> (NixString -> Text) -> NixString -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NixString -> Text
hackyStringIgnoreContext) [NixString]
xs)

fetchurl
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
fetchurl :: NValue t f m -> m (NValue t f m)
fetchurl v :: NValue t f m
v = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
v ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \case
  NVSet s :: AttrSet (NValue t f m)
s _ -> Text -> AttrSet (NValue t f m) -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
Text -> AttrSet (NValue t f m) -> m (NValue t f m)
attrsetGet "url" AttrSet (NValue t f m)
s m (NValue t f m)
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand (NValue t f m
 -> (NValue t f m -> m (NValue t f m)) -> 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 => f (a -> b) -> a -> f b
?? (Maybe (NValue t f m) -> NValue t f m -> m (NValue t f m)
go (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 "sha256" AttrSet (NValue t f m)
s))
  v :: NValue t f m
v@NVStr{} -> Maybe (NValue t f m) -> NValue t f m -> m (NValue t f m)
go Maybe (NValue t f m)
forall a. Maybe a
Nothing NValue t f m
v
  v :: NValue t f m
v ->
    ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
      (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
      (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "builtins.fetchurl: Expected URI or set, got "
      FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
v
 where
  go :: Maybe (NValue t f m) -> NValue t f m -> m (NValue t f m)
  go :: Maybe (NValue t f m) -> NValue t f m -> m (NValue t f m)
go _msha :: Maybe (NValue t f m)
_msha = \case
    NVStr ns :: NixString
ns -> NixString -> m Text
forall e (m :: * -> *).
(MonadReader e m, Has e Frames, MonadThrow m) =>
NixString -> m Text
noContextAttrs NixString
ns m Text
-> (Text -> m (Either ErrorCall StorePath))
-> m (Either ErrorCall StorePath)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Text -> m (Either ErrorCall StorePath)
forall (m :: * -> *).
MonadHttp m =>
Text -> m (Either ErrorCall StorePath)
getURL m (Either ErrorCall StorePath)
-> (Either ErrorCall StorePath -> m (NValue t f m))
-> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case -- msha
      Left  e :: ErrorCall
e -> ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError ErrorCall
e
      Right p :: StorePath
p -> StorePath -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue StorePath
p
    v :: NValue t f m
v ->
      ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
        (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
        (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "builtins.fetchurl: Expected URI or string, got "
        FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
v

  noContextAttrs :: NixString -> m Text
noContextAttrs ns :: NixString
ns = case NixString -> Maybe Text
principledGetStringNoContext NixString
ns of
    Nothing ->
      ErrorCall -> m Text
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m Text) -> ErrorCall -> m Text
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "builtins.fetchurl: unsupported arguments to url"
    Just t :: Text
t -> Text -> m Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
t

partition_
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
partition_ :: NValue t f m -> NValue t f m -> m (NValue t f m)
partition_ f :: NValue t f m
f = forall a (m :: * -> *) v. FromValue a m v => v -> m a
forall (m :: * -> *) v.
FromValue [NValue t f m] m v =>
v -> m [NValue t f m]
fromValue @[NValue t f m] (NValue t f m -> m [NValue t f m])
-> ([NValue t f m] -> m (NValue t f m))
-> NValue t f m
-> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> \l :: [NValue t f m]
l -> do
  let match :: NValue t f m -> m (Bool, NValue t f m)
match t :: NValue t f m
t = NValue t f m
f NValue t f m -> NValue t f m -> m (NValue t f m)
forall e t (f :: * -> *) (m :: * -> *).
MonadNix e t f m =>
NValue t f m -> NValue t f m -> m (NValue t f m)
`callFunc` NValue t f m
t m (NValue t f m)
-> (NValue t f m -> m (Bool, NValue t f m))
-> m (Bool, NValue t f m)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Bool -> (Bool, NValue t f m)) -> m Bool -> m (Bool, NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (, NValue t f m
t) (m Bool -> m (Bool, NValue t f m))
-> (NValue t f m -> m Bool)
-> NValue t f m
-> m (Bool, NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NValue t f m -> m Bool
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue
  [(Bool, NValue t f m)]
selection <- (NValue t f m -> m (Bool, NValue t f m))
-> [NValue t f m] -> m [(Bool, NValue t f m)]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse NValue t f m -> m (Bool, NValue t f m)
match [NValue t f m]
l
  let (right :: [(Bool, NValue t f m)]
right, wrong :: [(Bool, NValue t f m)]
wrong) = ((Bool, NValue t f m) -> Bool)
-> [(Bool, NValue t f m)]
-> ([(Bool, NValue t f m)], [(Bool, NValue t f m)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (Bool, NValue t f m) -> Bool
forall a b. (a, b) -> a
fst [(Bool, NValue t f m)]
selection
  let makeSide :: [(a, NValue t f m)] -> NValue t f m
makeSide       = [NValue t f m] -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
[NValue t f m] -> NValue t f m
nvList ([NValue t f m] -> NValue t f m)
-> ([(a, NValue t f m)] -> [NValue t f m])
-> [(a, NValue t f m)]
-> NValue t f m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a, NValue t f m) -> NValue t f m)
-> [(a, NValue t f m)] -> [NValue t f m]
forall a b. (a -> b) -> [a] -> [b]
map (a, NValue t f m) -> NValue t f m
forall a b. (a, b) -> b
snd
  forall a (m :: * -> *) v. ToValue a m v => a -> m v
forall (m :: * -> *) v.
ToValue (AttrSet (NValue t f m)) m v =>
AttrSet (NValue t f m) -> m v
toValue @(AttrSet (NValue t f m))
    (AttrSet (NValue t f m) -> m (NValue t f m))
-> AttrSet (NValue t f m) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ [(Text, NValue t f m)] -> AttrSet (NValue t f m)
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
M.fromList [("right", [(Bool, NValue t f m)] -> NValue t f m
forall a t (m :: * -> *). [(a, NValue t f m)] -> NValue t f m
makeSide [(Bool, NValue t f m)]
right), ("wrong", [(Bool, NValue t f m)] -> NValue t f m
forall a t (m :: * -> *). [(a, NValue t f m)] -> NValue t f m
makeSide [(Bool, NValue t f m)]
wrong)]

currentSystem :: MonadNix e t f m => m (NValue t f m)
currentSystem :: m (NValue t f m)
currentSystem = do
  Text
os   <- m Text
forall (m :: * -> *). MonadEnv m => m Text
getCurrentSystemOS
  Text
arch <- m Text
forall (m :: * -> *). MonadEnv m => m Text
getCurrentSystemArch
  NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ NixString -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NixString -> NValue t f m
nvStr (NixString -> NValue t f m) -> NixString -> NValue t f m
forall a b. (a -> b) -> a -> b
$ Text -> NixString
principledMakeNixStringWithoutContext (Text
arch Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> "-" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
os)

currentTime_ :: MonadNix e t f m => m (NValue t f m)
currentTime_ :: m (NValue t f m)
currentTime_ = do
  Options
opts :: Options <- (e -> Options) -> m Options
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (FoldLike Options e e Options Options -> e -> Options
forall a s t b. FoldLike a s t a b -> s -> a
view FoldLike Options e e Options Options
forall a b. Has a b => Lens' a b
hasLens)
  forall a (m :: * -> *) v. ToValue a m v => a -> m v
forall (m :: * -> *) v. ToValue Integer m v => Integer -> m v
toValue @Integer (Integer -> m (NValue t f m)) -> Integer -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ POSIXTime -> Integer
forall a b. (RealFrac a, Integral b) => a -> b
round (POSIXTime -> Integer) -> POSIXTime -> Integer
forall a b. (a -> b) -> a -> b
$ UTCTime -> POSIXTime
Time.utcTimeToPOSIXSeconds (Options -> UTCTime
currentTime Options
opts)

derivationStrict_ :: MonadNix e t f m => NValue t f m -> m (NValue t f m)
derivationStrict_ :: NValue t f m -> m (NValue t f m)
derivationStrict_ = NValue t f m -> m (NValue t f m)
forall t (f :: * -> *) (m :: * -> *).
MonadEffects t f m =>
NValue t f m -> m (NValue t f m)
derivationStrict

getRecursiveSize :: (MonadIntrospect m, Applicative f) => a -> m (NValue t f m)
getRecursiveSize :: a -> m (NValue t f m)
getRecursiveSize = (Word -> NValue t f m) -> m Word -> m (NValue t f m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (NAtom -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
NAtom -> NValue t f m
nvConstant (NAtom -> NValue t f m) -> (Word -> NAtom) -> Word -> NValue t f m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer -> NAtom
NInt (Integer -> NAtom) -> (Word -> Integer) -> Word -> NAtom
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral) (m Word -> m (NValue t f m))
-> (a -> m Word) -> a -> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> m Word
forall (m :: * -> *) a. MonadIntrospect m => a -> m Word
recursiveSize

getContext
  :: forall e t f m . MonadNix e t f m => NValue t f m -> m (NValue t f m)
getContext :: NValue t f m -> m (NValue t f m)
getContext x :: NValue t f m
x = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
x ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \case
  (NVStr ns :: NixString
ns) -> do
    let context :: HashMap Text NixLikeContextValue
context =
          NixLikeContext -> HashMap Text NixLikeContextValue
getNixLikeContext (NixLikeContext -> HashMap Text NixLikeContextValue)
-> NixLikeContext -> HashMap Text NixLikeContextValue
forall a b. (a -> b) -> a -> b
$ HashSet StringContext -> NixLikeContext
toNixLikeContext (HashSet StringContext -> NixLikeContext)
-> HashSet StringContext -> NixLikeContext
forall a b. (a -> b) -> a -> b
$ NixString -> HashSet StringContext
principledGetContext NixString
ns
    HashMap Text (NValue t f m)
valued :: M.HashMap Text (NValue t f m) <- HashMap Text (m (NValue t f m)) -> m (HashMap Text (NValue t f m))
forall (t :: * -> *) (f :: * -> *) a.
(Traversable t, Applicative f) =>
t (f a) -> f (t a)
sequenceA (HashMap Text (m (NValue t f m))
 -> m (HashMap Text (NValue t f m)))
-> HashMap Text (m (NValue t f m))
-> m (HashMap Text (NValue t f m))
forall a b. (a -> b) -> a -> b
$ (NixLikeContextValue -> m (NValue t f m))
-> HashMap Text NixLikeContextValue
-> HashMap Text (m (NValue t f m))
forall v1 v2 k. (v1 -> v2) -> HashMap k v1 -> HashMap k v2
M.map NixLikeContextValue -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue HashMap Text NixLikeContextValue
context
    NValue t f m -> m (NValue t f m)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ (HashMap Text (NValue t f m)
 -> HashMap Text SourcePos -> NValue t f m)
-> HashMap Text SourcePos
-> HashMap Text (NValue t f m)
-> NValue t f m
forall a b c. (a -> b -> c) -> b -> a -> c
flip HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
forall (f :: * -> *) t (m :: * -> *).
Applicative f =>
HashMap Text (NValue t f m)
-> HashMap Text SourcePos -> NValue t f m
nvSet HashMap Text SourcePos
forall k v. HashMap k v
M.empty (HashMap Text (NValue t f m) -> NValue t f m)
-> HashMap Text (NValue t f m) -> NValue t f m
forall a b. (a -> b) -> a -> b
$ HashMap Text (NValue t f m)
valued
  x :: NValue t f m
x ->
    ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "Invalid type for builtins.getContext: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
x

appendContext
  :: forall e t f m
   . MonadNix e t f m
  => NValue t f m
  -> NValue t f m
  -> m (NValue t f m)
appendContext :: NValue t f m -> NValue t f m -> m (NValue t f m)
appendContext x :: NValue t f m
x y :: NValue t f m
y = NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
x ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \x' :: NValue t f m
x' -> NValue t f m
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
y ((NValue t f m -> m (NValue t f m)) -> m (NValue t f m))
-> (NValue t f m -> m (NValue t f m)) -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ \y' :: NValue t f m
y' -> case (NValue t f m
x', NValue t f m
y') of
  (NVStr ns :: NixString
ns, NVSet attrs :: AttrSet (NValue t f m)
attrs _) -> do
    HashMap Text NixLikeContextValue
newContextValues <- AttrSet (NValue t f m)
-> (NValue t f m -> m NixLikeContextValue)
-> m (HashMap Text NixLikeContextValue)
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM AttrSet (NValue t f m)
attrs ((NValue t f m -> m NixLikeContextValue)
 -> m (HashMap Text NixLikeContextValue))
-> (NValue t f m -> m NixLikeContextValue)
-> m (HashMap Text NixLikeContextValue)
forall a b. (a -> b) -> a -> b
$ \attr :: NValue t f m
attr -> NValue t f m
-> (NValue t f m -> m NixLikeContextValue) -> m NixLikeContextValue
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
attr ((NValue t f m -> m NixLikeContextValue) -> m NixLikeContextValue)
-> (NValue t f m -> m NixLikeContextValue) -> m NixLikeContextValue
forall a b. (a -> b) -> a -> b
$ \case
      NVSet attrs :: AttrSet (NValue t f m)
attrs _ -> do
        -- TODO: Fail for unexpected keys.
        Bool
path <- m Bool
-> (NValue t f m -> m Bool) -> Maybe (NValue t f m) -> m Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False) (NValue t f m -> (NValue t f m -> m Bool) -> m Bool
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand (NValue t f m -> (NValue t f m -> m Bool) -> m Bool)
-> (NValue t f m -> m Bool) -> NValue t f m -> m Bool
forall (f :: * -> *) a b. Functor f => f (a -> b) -> a -> f b
?? NValue t f m -> m Bool
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue)
          (Maybe (NValue t f m) -> m Bool) -> Maybe (NValue t f m) -> m Bool
forall a b. (a -> b) -> a -> b
$ 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 "path" AttrSet (NValue t f m)
attrs
        Bool
allOutputs <- m Bool
-> (NValue t f m -> m Bool) -> Maybe (NValue t f m) -> m Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False) (NValue t f m -> (NValue t f m -> m Bool) -> m Bool
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand (NValue t f m -> (NValue t f m -> m Bool) -> m Bool)
-> (NValue t f m -> m Bool) -> NValue t f m -> m Bool
forall (f :: * -> *) a b. Functor f => f (a -> b) -> a -> f b
?? NValue t f m -> m Bool
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue)
          (Maybe (NValue t f m) -> m Bool) -> Maybe (NValue t f m) -> m Bool
forall a b. (a -> b) -> a -> b
$ 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 "allOutputs" AttrSet (NValue t f m)
attrs
        [Text]
outputs <- case 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 "outputs" AttrSet (NValue t f m)
attrs of
          Nothing -> [Text] -> m [Text]
forall (m :: * -> *) a. Monad m => a -> m a
return []
          Just os :: NValue t f m
os -> NValue t f m -> (NValue t f m -> m [Text]) -> m [Text]
forall v (m :: * -> *) r. MonadValue v m => v -> (v -> m r) -> m r
demand NValue t f m
os ((NValue t f m -> m [Text]) -> m [Text])
-> (NValue t f m -> m [Text]) -> m [Text]
forall a b. (a -> b) -> a -> b
$ \case
            NVList vs :: [NValue t f m]
vs ->
              [NValue t f m] -> (NValue t f m -> m Text) -> m [Text]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [NValue t f m]
vs ((NValue t f m -> m Text) -> m [Text])
-> (NValue t f m -> m Text) -> m [Text]
forall a b. (a -> b) -> a -> b
$ (NixString -> Text) -> m NixString -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap NixString -> Text
principledStringIgnoreContext (m NixString -> m Text)
-> (NValue t f m -> m NixString) -> NValue t f m -> m Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NValue t f m -> m NixString
forall a (m :: * -> *) v. FromValue a m v => v -> m a
fromValue
            x :: NValue t f m
x ->
              ErrorCall -> m [Text]
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
                (ErrorCall -> m [Text]) -> ErrorCall -> m [Text]
forall a b. (a -> b) -> a -> b
$ FilePath -> ErrorCall
ErrorCall
                (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$ "Invalid types for context value outputs in builtins.appendContext: "
                FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
x
        NixLikeContextValue -> m NixLikeContextValue
forall (m :: * -> *) a. Monad m => a -> m a
return (NixLikeContextValue -> m NixLikeContextValue)
-> NixLikeContextValue -> m NixLikeContextValue
forall a b. (a -> b) -> a -> b
$ Bool -> Bool -> [Text] -> NixLikeContextValue
NixLikeContextValue Bool
path Bool
allOutputs [Text]
outputs
      x :: NValue t f m
x ->
        ErrorCall -> m NixLikeContextValue
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
          (ErrorCall -> m NixLikeContextValue)
-> ErrorCall -> m NixLikeContextValue
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
          (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "Invalid types for context value in builtins.appendContext: "
          FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ NValue t f m -> FilePath
forall a. Show a => a -> FilePath
show NValue t f m
x
    NixString -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue
      (NixString -> m (NValue t f m)) -> NixString -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ Text -> HashSet StringContext -> NixString
principledMakeNixString (NixString -> Text
principledStringIgnoreContext NixString
ns)
      (HashSet StringContext -> NixString)
-> HashSet StringContext -> NixString
forall a b. (a -> b) -> a -> b
$ NixLikeContext -> HashSet StringContext
fromNixLikeContext
      (NixLikeContext -> HashSet StringContext)
-> NixLikeContext -> HashSet StringContext
forall a b. (a -> b) -> a -> b
$ HashMap Text NixLikeContextValue -> NixLikeContext
NixLikeContext
      (HashMap Text NixLikeContextValue -> NixLikeContext)
-> HashMap Text NixLikeContextValue -> NixLikeContext
forall a b. (a -> b) -> a -> b
$ (NixLikeContextValue -> NixLikeContextValue -> NixLikeContextValue)
-> HashMap Text NixLikeContextValue
-> HashMap Text NixLikeContextValue
-> HashMap Text NixLikeContextValue
forall k v.
(Eq k, Hashable k) =>
(v -> v -> v) -> HashMap k v -> HashMap k v -> HashMap k v
M.unionWith NixLikeContextValue -> NixLikeContextValue -> NixLikeContextValue
forall a. Semigroup a => a -> a -> a
(<>) HashMap Text NixLikeContextValue
newContextValues
      (HashMap Text NixLikeContextValue
 -> HashMap Text NixLikeContextValue)
-> HashMap Text NixLikeContextValue
-> HashMap Text NixLikeContextValue
forall a b. (a -> b) -> a -> b
$ NixLikeContext -> HashMap Text NixLikeContextValue
getNixLikeContext
      (NixLikeContext -> HashMap Text NixLikeContextValue)
-> NixLikeContext -> HashMap Text NixLikeContextValue
forall a b. (a -> b) -> a -> b
$ HashSet StringContext -> NixLikeContext
toNixLikeContext
      (HashSet StringContext -> NixLikeContext)
-> HashSet StringContext -> NixLikeContext
forall a b. (a -> b) -> a -> b
$ NixString -> HashSet StringContext
principledGetContext NixString
ns
  (x :: NValue t f m
x, y :: NValue t f m
y) ->
    ErrorCall -> m (NValue t f m)
forall s e (m :: * -> *) a.
(Framed e m, Exception s, MonadThrow m) =>
s -> m a
throwError
      (ErrorCall -> m (NValue t f m)) -> ErrorCall -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$  FilePath -> ErrorCall
ErrorCall
      (FilePath -> ErrorCall) -> FilePath -> ErrorCall
forall a b. (a -> b) -> a -> b
$  "Invalid types for builtins.appendContext: "
      FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ (NValue t f m, NValue t f m) -> FilePath
forall a. Show a => a -> FilePath
show (NValue t f m
x, NValue t f m
y)

newtype Prim m a = Prim { Prim m a -> m a
runPrim :: m a }

-- | Types that support conversion to nix in a particular monad
class ToBuiltin t f m a | a -> m where
    toBuiltin :: String -> a -> m (NValue t f m)

instance (MonadNix e t f m, ToValue a m (NValue t f m))
      => ToBuiltin t f m (Prim m a) where
  toBuiltin :: FilePath -> Prim m a -> m (NValue t f m)
toBuiltin _ p :: Prim m a
p = a -> m (NValue t f m)
forall a (m :: * -> *) v. ToValue a m v => a -> m v
toValue (a -> m (NValue t f m)) -> m a -> m (NValue t f m)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Prim m a -> m a
forall (m :: * -> *) a. Prim m a -> m a
runPrim Prim m a
p

instance ( MonadNix e t f m
         , FromValue a m (Deeper (NValue t f m))
         , ToBuiltin t f m b
         )
      => ToBuiltin t f m (a -> b) where
  toBuiltin :: FilePath -> (a -> b) -> m (NValue t f m)
toBuiltin name :: FilePath
name f :: a -> b
f =
    NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a. Monad m => a -> m a
return (NValue t f m -> m (NValue t f m))
-> NValue t f m -> m (NValue t f m)
forall a b. (a -> b) -> a -> b
$ FilePath -> (NValue t f m -> m (NValue t f m)) -> NValue t f m
forall (f :: * -> *) (m :: * -> *) t.
(Applicative f, Functor m) =>
FilePath -> (NValue t f m -> m (NValue t f m)) -> NValue t f m
nvBuiltin FilePath
name (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)
-> (a -> m (NValue t f m)) -> NValue t f m -> m (NValue t f m)
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> FilePath -> b -> m (NValue t f m)
forall t (f :: * -> *) (m :: * -> *) a.
ToBuiltin t f m a =>
FilePath -> a -> m (NValue t f m)
toBuiltin FilePath
name (b -> m (NValue t f m)) -> (a -> b) -> a -> m (NValue t f m)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f)