Unnamed repository; edit this file 'description' to name the repository.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{
  # Simple bindings.
  a = 1;
  b = "two";
  c = a + 1;

  # Nested attrsets.
  nested = {
    c = 3;
    deep = {
      d = 4;
      deeper = {
        e = 5;
      };
    };
  };

  # Lists, including nested.
  list = [
    1
    2
    [
      3
      4
    ]
  ];

  # rec attrset.
  recursive = rec {
    x = 1;
    y = x + 1;
  };

  # let ... in: bindings indent, `in` and the body sit at the `let` column.
  computed =
    let
      x = 1;
      y = 2;
    in
    x + y;

  # Nested let.
  nestedLet =
    let
      outer =
        let
          inner = 1;
        in
        inner;
    in
    outer;

  # Functions.
  id = x: x;
  add = a: b: a + b;

  # Pattern parameter.
  pattern =
    {
      foo,
      bar,
      ...
    }:
    foo + bar;

  # Pattern with `@` binding.
  patternAt =
    {
      foo,
      bar,
    }@args:
    foo + bar + args.foo;

  # if / then / else, including else-if chains.
  sign =
    if a > 0 then
      "positive"
    else if a < 0 then
      "negative"
    else
      "zero";

  # with.
  withExpr =
    with builtins;
    length [
      1
      2
    ];

  # assert.
  checked =
    assert a > 0;
    a;

  # Function application across lines.
  applied =
    builtins.map
      (x: x + 1)
      [
        1
        2
      ];

  # Operator continuation via the binding value.
  merged =
    {
      a = 1;
    }
    // {
      b = 2;
    };

  hasAttr = { a = 1; } ? a;

  # Parenthesized expression across lines.
  grouped = (
    1
    + 2
    + 3
  );

  # Indented string with a non-script name: not injected, so its interior is
  # preserved verbatim by @opaque (author indentation kept as-is).
  notes = ''
    first line
      a deeper line, preserved verbatim
    back to the base
  '';

  # A realistic derivation.
  package = stdenv.mkDerivation rec {
    pname = "hello";
    version = "1.0";

    src = fetchurl {
      url = "https://example.com/${pname}-${version}.tar.gz";
      sha256 = "0000";
    };

    buildInputs = [
      cmake
      ninja
    ];

    buildPhase = ''
      make
      make install
    '';

    meta = {
      description = "A program";
      license = licenses.mit;
    };
  };

  # inherit variants.
  inherit a b;
  inherit (builtins) length map;
}