Debian Codegraph @

tests/indent/nix.nix

raw symbols SCIP
1 {
2 # Simple bindings.
3 a = 1;
4 b = "two";
5 c = a + 1;
6
7 # Nested attrsets.
8 nested = {
9 c = 3;
10 deep = {
11 d = 4;
12 deeper = {
13 e = 5;
14 };
15 };
16 };
17
18 # Lists, including nested.
19 list = [
20 1
21 2
22 [
23 3
24 4
25 ]
26 ];
27
28 # rec attrset.
29 recursive = rec {
30 x = 1;
31 y = x + 1;
32 };
33
34 # let ... in: bindings indent, `in` and the body sit at the `let` column.
35 computed =
36 let
37 x = 1;
38 y = 2;
39 in
40 x + y;
41
42 # Nested let.
43 nestedLet =
44 let
45 outer =
46 let
47 inner = 1;
48 in
49 inner;
50 in
51 outer;
52
53 # Functions.
54 id = x: x;
55 add = a: b: a + b;
56
57 # Pattern parameter.
58 pattern =
59 {
60 foo,
61 bar,
62 ...
63 }:
64 foo + bar;
65
66 # Pattern with `@` binding.
67 patternAt =
68 {
69 foo,
70 bar,
71 }@args:
72 foo + bar + args.foo;
73
74 # if / then / else, including else-if chains.
75 sign =
76 if a > 0 then
77 "positive"
78 else if a < 0 then
79 "negative"
80 else
81 "zero";
82
83 # with.
84 withExpr =
85 with builtins;
86 length [
87 1
88 2
89 ];
90
91 # assert.
92 checked =
93 assert a > 0;
94 a;
95
96 # Function application across lines.
97 applied =
98 builtins.map
99 (x: x + 1)
100 [
101 1
102 2
103 ];
104
105 # Operator continuation via the binding value.
106 merged =
107 {
108 a = 1;
109 }
110 // {
111 b = 2;
112 };
113
114 hasAttr = { a = 1; } ? a;
115
116 # Parenthesized expression across lines.
117 grouped = (
118 1
119 + 2
120 + 3
121 );
122
123 # Indented string with a non-script name: not injected, so its interior is
124 # preserved verbatim by @opaque (author indentation kept as-is).
125 notes = ''
126 first line
127 a deeper line, preserved verbatim
128 back to the base
129 '';
130
131 # A realistic derivation.
132 package = stdenv.mkDerivation rec {
133 pname = "hello";
134 version = "1.0";
135
136 src = fetchurl {
137 url = "https://example.com/${pname}-${version}.tar.gz";
138 sha256 = "0000";
139 };
140
141 buildInputs = [
142 cmake
143 ninja
144 ];
145
146 buildPhase = ''
147 make
148 make install
149 '';
150
151 meta = {
152 description = "A program";
153 license = licenses.mit;
154 };
155 };
156
157 # inherit variants.
158 inherit a b;
159 inherit (builtins) length map;
160 }