Safe Haskell | None |
---|---|
Language | Haskell2010 |
The nix expression type and supporting types.
- type VarName = Text
- data NExprF r
- = NConstant !NAtom
- | NStr !(NString r)
- | NSym !VarName
- | NList ![r]
- | NSet ![Binding r]
- | NRecSet ![Binding r]
- | NLiteralPath !FilePath
- | NEnvPath !FilePath
- | NUnary !NUnaryOp !r
- | NBinary !NBinaryOp !r !r
- | NSelect !r !(NAttrPath r) !(Maybe r)
- | NHasAttr !r !(NAttrPath r)
- | NAbs !(Params r) !r
- | NLet ![Binding r] !r
- | NIf !r !r !r
- | NWith !r !r
- | NAssert !r !r
- type NExpr = Fix NExprF
- data Binding r
- data Params r
- type ParamSet r = [(VarName, Maybe r)]
- data Antiquoted (v :: *) (r :: *)
- = Plain !v
- | EscapedNewline
- | Antiquoted !r
- data NString r
- = DoubleQuoted ![Antiquoted Text r]
- | Indented !Int ![Antiquoted Text r]
- data NKeyName r
- = DynamicKey !(Antiquoted (NString r) r)
- | StaticKey !VarName
- type NAttrPath r = NonEmpty (NKeyName r)
- data NUnaryOp
- data NBinaryOp
- paramName :: Params r -> Maybe VarName
- _NAssert :: Applicative f => ((r, r) -> f (r, r)) -> NExprF r -> f (NExprF r)
- _NWith :: Applicative f => ((r, r) -> f (r, r)) -> NExprF r -> f (NExprF r)
- _NIf :: Applicative f => ((r, r, r) -> f (r, r, r)) -> NExprF r -> f (NExprF r)
- _NLet :: Applicative f => (([Binding r], r) -> f ([Binding r], r)) -> NExprF r -> f (NExprF r)
- _NAbs :: Applicative f => ((Params r, r) -> f (Params r, r)) -> NExprF r -> f (NExprF r)
- _NHasAttr :: Applicative f => ((r, NAttrPath r) -> f (r, NAttrPath r)) -> NExprF r -> f (NExprF r)
- _NSelect :: Applicative f => ((r, NAttrPath r, Maybe r) -> f (r, NAttrPath r, Maybe r)) -> NExprF r -> f (NExprF r)
- _NBinary :: Applicative f => ((NBinaryOp, r, r) -> f (NBinaryOp, r, r)) -> NExprF r -> f (NExprF r)
- _NUnary :: Applicative f => ((NUnaryOp, r) -> f (NUnaryOp, r)) -> NExprF r -> f (NExprF r)
- _NEnvPath :: Applicative f => (FilePath -> f FilePath) -> NExprF r -> f (NExprF r)
- _NLiteralPath :: Applicative f => (FilePath -> f FilePath) -> NExprF r -> f (NExprF r)
- _NRecSet :: Applicative f => ([Binding r] -> f [Binding r]) -> NExprF r -> f (NExprF r)
- _NSet :: Applicative f => ([Binding r] -> f [Binding r]) -> NExprF r -> f (NExprF r)
- _NList :: Applicative f => ([r] -> f [r]) -> NExprF r -> f (NExprF r)
- _NSym :: Applicative f => (VarName -> f VarName) -> NExprF r -> f (NExprF r)
- _NStr :: Applicative f => (NString r -> f (NString r)) -> NExprF r -> f (NExprF r)
- _NConstant :: Applicative f => (NAtom -> f NAtom) -> NExprF r -> f (NExprF r)
- _Inherit :: Applicative f => ((Maybe r, [NKeyName r], SourcePos) -> f (Maybe r, [NKeyName r], SourcePos)) -> Binding r -> f (Binding r)
- _NamedVar :: Applicative f => ((NAttrPath r, r, SourcePos) -> f (NAttrPath r, r, SourcePos)) -> Binding r -> f (Binding r)
- _ParamSet :: Applicative f => ((ParamSet r1, Bool, Maybe VarName) -> f (ParamSet r2, Bool, Maybe VarName)) -> Params r1 -> f (Params r2)
- _Param :: Applicative f => (VarName -> f VarName) -> Params r -> f (Params r)
- _Antiquoted :: Applicative f => (t -> f r) -> Antiquoted v t -> f (Antiquoted v r)
- _EscapedNewline :: Applicative f => (() -> f ()) -> Antiquoted v r -> f (Antiquoted v r)
- _Plain :: Applicative f => (t -> f v) -> Antiquoted t r -> f (Antiquoted v r)
- _Indented :: Applicative f => ((Int, [Antiquoted Text r]) -> f (Int, [Antiquoted Text r])) -> NString r -> f (NString r)
- _DoubleQuoted :: Applicative f => ([Antiquoted Text r] -> f [Antiquoted Text r]) -> NString r -> f (NString r)
- _StaticKey :: Applicative f => (VarName -> f VarName) -> NKeyName r -> f (NKeyName r)
- _DynamicKey :: Applicative f => (Antiquoted (NString r1) r1 -> f (Antiquoted (NString r2) r2)) -> NKeyName r1 -> f (NKeyName r2)
- _NNot :: Applicative f => (() -> f ()) -> NUnaryOp -> f NUnaryOp
- _NNeg :: Applicative f => (() -> f ()) -> NUnaryOp -> f NUnaryOp
- _NApp :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NConcat :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NDiv :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NMult :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NMinus :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NPlus :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NUpdate :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NImpl :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NOr :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NAnd :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NGte :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NGt :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NLte :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NLt :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NNEq :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- _NEq :: Applicative f => (() -> f ()) -> NBinaryOp -> f NBinaryOp
- class NExprAnn ann g | g -> ann where
- ekey :: NExprAnn ann g => NonEmpty Text -> SourcePos -> Lens' (Fix g) (Maybe (Fix g))
- stripPositionInfo :: NExpr -> NExpr
- nullPos :: SourcePos
Documentation
The main nix expression type. This is polymorphic so that it can be made
a functor, which allows us to traverse expressions and map functions over
them. The actual NExpr
type is a fixed point of this functor, defined
below.
NConstant !NAtom | Constants: ints, bools, URIs, and null. |
NStr !(NString r) | A string, with interpolated expressions. |
NSym !VarName | A variable. For example, in the expression |
NList ![r] | A list literal. |
NSet ![Binding r] | An attribute set literal, not recursive. |
NRecSet ![Binding r] | An attribute set literal, recursive. |
NLiteralPath !FilePath | A path expression, which is evaluated to a store path. The path here can be relative, in which case it's evaluated relative to the file in which it appears. |
NEnvPath !FilePath | A path which refers to something in the Nix search path (the NIX_PATH
environment variable. For example, |
NUnary !NUnaryOp !r | Application of a unary operator to an expression. |
NBinary !NBinaryOp !r !r | Application of a binary operator to two expressions. |
NSelect !r !(NAttrPath r) !(Maybe r) | Dot-reference into an attribute set, optionally providing an alternative if the key doesn't exist. |
NHasAttr !r !(NAttrPath r) | Ask if a set contains a given attribute path. |
NAbs !(Params r) !r | A function literal (lambda abstraction). |
NLet ![Binding r] !r | Evaluate the second argument after introducing the bindings. |
NIf !r !r !r | If-then-else statement. |
NWith !r !r | Evaluate an attribute set, bring its bindings into scope, and evaluate the second argument. |
NAssert !r !r | Assert that the first returns true before evaluating the second. |
type NExpr = Fix NExprF Source #
The monomorphic expression type is a fixed point of the polymorphic one.
A single line of the bindings section of a let expression or of a set.
NamedVar !(NAttrPath r) !r !SourcePos | An explicit naming, such as |
Inherit !(Maybe r) ![NKeyName r] !SourcePos | Using a name already in scope, such as |
Functor Binding Source # | |
Foldable Binding Source # | |
Traversable Binding Source # | |
Eq1 Binding Source # | |
Show1 Binding Source # | |
NFData1 Binding Source # | |
Hashable1 Binding Source # | |
Eq r => Eq (Binding r) Source # | |
Data r => Data (Binding r) Source # | |
Ord r => Ord (Binding r) Source # | |
Show r => Show (Binding r) Source # | |
Generic (Binding r) Source # | |
Hashable r => Hashable (Binding r) Source # | |
ToJSON a => ToJSON (Binding a) Source # | |
FromJSON a => FromJSON (Binding a) Source # | |
Binary a => Binary (Binding a) Source # | |
NFData r => NFData (Binding r) Source # | |
Serialise r => Serialise (Binding r) Source # | |
Generic1 * Binding Source # | |
type Rep (Binding r) Source # | |
type Rep1 * Binding Source # | |
Params
represents all the ways the formal parameters to a
function can be represented.
Param !VarName | For functions with a single named argument, such as |
ParamSet !(ParamSet r) !Bool !(Maybe VarName) | Explicit parameters (argument must be a set). Might specify a name to bind to the set in the function body. The bool indicates whether it is variadic or not. |
Functor Params Source # | |
Foldable Params Source # | |
Traversable Params Source # | |
ToJSON1 Params Source # | |
FromJSON1 Params Source # | |
Eq1 Params Source # | |
Ord1 Params Source # | |
Read1 Params Source # | |
Show1 Params Source # | |
NFData1 Params Source # | |
Hashable1 Params Source # | |
Eq r => Eq (Params r) Source # | |
Data r => Data (Params r) Source # | |
Ord r => Ord (Params r) Source # | |
Show r => Show (Params r) Source # | |
IsString (Params r) Source # | |
Generic (Params r) Source # | |
Hashable r => Hashable (Params r) Source # | |
ToJSON a => ToJSON (Params a) Source # | |
FromJSON a => FromJSON (Params a) Source # | |
Binary a => Binary (Params a) Source # | |
NFData r => NFData (Params r) Source # | |
Serialise r => Serialise (Params r) Source # | |
Generic1 * Params Source # | |
type Rep (Params r) Source # | |
type Rep1 * Params Source # | |
data Antiquoted (v :: *) (r :: *) Source #
Antiquoted
represents an expression that is either
antiquoted (surrounded by ${...}) or plain (not antiquoted).
Plain !v | |
EscapedNewline | |
Antiquoted !r |
An NString
is a list of things that are either a plain string
or an antiquoted expression. After the antiquotes have been evaluated,
the final string is constructed by concating all the parts.
DoubleQuoted ![Antiquoted Text r] | Strings wrapped with double-quotes (") can contain literal newline characters, but the newlines are preserved and no indentation is stripped. |
Indented !Int ![Antiquoted Text r] | Strings wrapped with two single quotes ('') can contain newlines, and their indentation will be stripped, but the amount stripped is remembered. |
Functor NString Source # | |
Foldable NString Source # | |
Traversable NString Source # | |
ToJSON1 NString Source # | |
FromJSON1 NString Source # | |
Eq1 NString Source # | |
Ord1 NString Source # | |
Read1 NString Source # | |
Show1 NString Source # | |
NFData1 NString Source # | |
Hashable1 NString Source # | |
Eq r => Eq (NString r) Source # | |
Data r => Data (NString r) Source # | |
Ord r => Ord (NString r) Source # | |
Read r => Read (NString r) Source # | |
Show r => Show (NString r) Source # | |
IsString (NString r) Source # | For the the |
Generic (NString r) Source # | |
Hashable r => Hashable (NString r) Source # | |
ToJSON a => ToJSON (NString a) Source # | |
FromJSON a => FromJSON (NString a) Source # | |
Binary a => Binary (NString a) Source # | |
NFData r => NFData (NString r) Source # | |
Serialise r => Serialise (NString r) Source # | |
Generic1 * NString Source # | |
type Rep (NString r) Source # | |
type Rep1 * NString Source # | |
A KeyName
is something that can appear on the left side of an
equals sign. For example, a
is a KeyName
in { a = 3; }
, let a = 3;
in ...
, {}.a
or {} ? a
.
Nix supports both static keynames (just an identifier) and dynamic
identifiers. Dynamic identifiers can be either a string (e.g.:
{ "a" = 3; }
) or an antiquotation (e.g.: let a = "example";
in { ${a} = 3; }.example
).
Note: There are some places where a dynamic keyname is not allowed. In particular, those include:
- The RHS of a
binding
insidelet
:let ${"a"} = 3; in ...
produces a syntax error. - The attribute names of an
inherit
:inherit ${"a"};
is forbidden.
Note: In Nix, a simple string without antiquotes such as "foo"
is
allowed even if the context requires a static keyname, but the
parser still considers it a DynamicKey
for simplicity.
DynamicKey !(Antiquoted (NString r) r) | |
StaticKey !VarName |
Functor NKeyName Source # | |
Foldable NKeyName Source # | |
Traversable NKeyName Source # | |
Eq1 NKeyName Source # | |
Show1 NKeyName Source # | |
NFData1 NKeyName Source # | |
Hashable1 NKeyName Source # | |
Generic1 * NKeyName Source # | |
Eq r => Eq (NKeyName r) Source # | |
Data r => Data (NKeyName r) Source # | |
Ord r => Ord (NKeyName r) Source # | |
Read r => Read (NKeyName r) Source # | |
Show r => Show (NKeyName r) Source # | |
IsString (NKeyName r) Source # | Most key names are just static text, so this instance is convenient. |
Generic (NKeyName r) Source # | |
Hashable r => Hashable (NKeyName r) Source # | |
ToJSON a => ToJSON (NKeyName a) Source # | |
FromJSON a => FromJSON (NKeyName a) Source # | |
Binary a => Binary (NKeyName a) Source # | |
NFData r => NFData (NKeyName r) Source # | |
Serialise r => Serialise (NKeyName r) Source # | |
type Rep1 * NKeyName Source # | |
type Rep (NKeyName r) Source # | |
type NAttrPath r = NonEmpty (NKeyName r) Source #
A selector (for example in a let
or an attribute set) is made up
of strung-together key names.
There are two unary operations: logical not and integer negation.
Binary operators expressible in the nix language.
NEq | Equality (==) |
NNEq | Inequality (!=) |
NLt | Less than (<) |
NLte | Less than or equal (<=) |
NGt | Greater than (>) |
NGte | Greater than or equal (>=) |
NAnd | Logical and (&&) |
NOr | Logical or (||) |
NImpl | Logical implication (->) |
NUpdate | Joining two attribut sets (//) |
NPlus | Addition (+) |
NMinus | Subtraction (-) |
NMult | Multiplication (*) |
NDiv | Division (/) |
NConcat | List concatenation (++) |
NApp | Apply a function to an argument. |
paramName :: Params r -> Maybe VarName Source #
Get the name out of the parameter (there might be none).
defaultOptions ''NExprF)
defaultOptions ''Binding)
_NLet :: Applicative f => (([Binding r], r) -> f ([Binding r], r)) -> NExprF r -> f (NExprF r) Source #
_NHasAttr :: Applicative f => ((r, NAttrPath r) -> f (r, NAttrPath r)) -> NExprF r -> f (NExprF r) Source #
_NSelect :: Applicative f => ((r, NAttrPath r, Maybe r) -> f (r, NAttrPath r, Maybe r)) -> NExprF r -> f (NExprF r) Source #
_NBinary :: Applicative f => ((NBinaryOp, r, r) -> f (NBinaryOp, r, r)) -> NExprF r -> f (NExprF r) Source #
_NLiteralPath :: Applicative f => (FilePath -> f FilePath) -> NExprF r -> f (NExprF r) Source #
_NConstant :: Applicative f => (NAtom -> f NAtom) -> NExprF r -> f (NExprF r) Source #
_Inherit :: Applicative f => ((Maybe r, [NKeyName r], SourcePos) -> f (Maybe r, [NKeyName r], SourcePos)) -> Binding r -> f (Binding r) Source #
_NamedVar :: Applicative f => ((NAttrPath r, r, SourcePos) -> f (NAttrPath r, r, SourcePos)) -> Binding r -> f (Binding r) Source #
_ParamSet :: Applicative f => ((ParamSet r1, Bool, Maybe VarName) -> f (ParamSet r2, Bool, Maybe VarName)) -> Params r1 -> f (Params r2) Source #
_Antiquoted :: Applicative f => (t -> f r) -> Antiquoted v t -> f (Antiquoted v r) Source #
_EscapedNewline :: Applicative f => (() -> f ()) -> Antiquoted v r -> f (Antiquoted v r) Source #
_Plain :: Applicative f => (t -> f v) -> Antiquoted t r -> f (Antiquoted v r) Source #
_Indented :: Applicative f => ((Int, [Antiquoted Text r]) -> f (Int, [Antiquoted Text r])) -> NString r -> f (NString r) Source #
_DoubleQuoted :: Applicative f => ([Antiquoted Text r] -> f [Antiquoted Text r]) -> NString r -> f (NString r) Source #
_StaticKey :: Applicative f => (VarName -> f VarName) -> NKeyName r -> f (NKeyName r) Source #
_DynamicKey :: Applicative f => (Antiquoted (NString r1) r1 -> f (Antiquoted (NString r2) r2)) -> NKeyName r1 -> f (NKeyName r2) Source #
''Fix)
stripPositionInfo :: NExpr -> NExpr Source #