Nix Language - Data types
/etc
./foo.png
~/.config
{ foo.bar = 1; } { foo = { bar = 1; }; }
rec {}
Primitives
String
“hello ${{a=“1”; b=“2”;}.b}” “1 2 ${toString 3}” “${pkgs.bash}/bin/sh”
“foo bar” ’' foo bar ’' “foo\nbar\n”
- string interpolation ${} ‘’${} ‘’\n
Number
123 .23e13
Path
/bin/sh ./builder.sh (relative to the directory of the Nix expression that contained it) ~/foo at least one slash must appear before any interpolated expresssion. <>
Boolean
true and false
Null
null
List
[ 123 “jfalkdjf” ./foo.nix (f {x=y;}) ]
builtins.elemAt
Attribute Set
A collection of name-value-pairs (called attributes)
identifier: [a-zA-Z_][a-zA-Z0-9_'-]*
name : identifier | string
attrset : {[name = expr;]...}
.
operator or
keyword
{ a = "Foo"; b = "Bar"; }.c.d.e.f.g or "Xyzzy"
Attr names string interpolation:
let bar = "foo"; in
{ foo = 123; }.${bar}
let bar = "foo"; in
{ ${bar} = 123; }.foo
{ ${if foo then "bar" else null} = true; }
__functor
let add = { __functor = self: x: x + self.x; };
inc = add // { x = 1; };
in inc 1
Recursive sets
rec-attrset: rec { [ name = expr ; ]… }
rec {
x = y;
y = x;
}.x
`infinite recursion encountered`