The Nix quick reference cheat sheet that aims at providing help on writing basic nix code.
let
x = "single-line string";
y = ''
multi-line string
'';
in
let
x = -123;
y - 123;
in
let
x = -0.32;
y = 0.45;
in
let
x = true;
y = false;
in
let
x = null;
in
let
x = /absolute/path;
y = ./relative/path;
in
let
x = {
a = 1;
b = 2;
};
y = { c = 3; };
in
see Attribute Sets
let
x = [ 1 2.0 ];
y = [
1
"this is a string"
23.0
null
];
in
let
f = x: x + 1;
in
f 1 # -> returns 2
let
f = x: y: [ x y ];
in
f 1 2 # -> returns [ 1 2 ]
let
f = {x, y}: x + y;
in
f { x=1; y=2; } # -> returns 3
let
f = {x, y, ... }: x + y;
in
f { x=1; y=2; z=3; } # -> returns 3
let
f = {x, y ? 2 }: x + y;
in
f { x=1; } # -> returns 3
let
f = {x, y}@args: args.x + args.y;
in
f { x=1; y=2; } # -> returns 3