File: nix

package info (click to toggle)
ruby-rouge 4.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,836 kB
  • sloc: ruby: 38,168; sed: 2,071; perl: 152; makefile: 8
file content (260 lines) | stat: -rw-r--r-- 3,622 bytes parent folder | download | duplicates (4)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# inline comments
# another inline comment

# inline comment after empty line

  # inline comment after white-space

12 # EOL comment

/* multi-line
 * comment
 */

0

47

null

true

false

ab = q

42 == 24

12 + 3 / 2 * 1

a < 42 || b <= 10

b > 10 && 42 >= 12

"this is a string"

"antiquotation ${toString (x + 7)}"

"escaped chars \n \r \t \q \${q}"

''escaped chars ''\n ''\r ''\t ''\q ''' ''${q}''
++ ''raw chars " \n \r \t \q''

# Examples from https://nixos.org/nix/manual/#idm140737318143152

"--with-freetype2-library=${freetype}/lib"

"--with-freetype2-library=" + freetype + "/lib"

configureFlags = [
  "-system-zlib"
  "-system-libpng"
  "-system-libjpeg"
  (if threadSupport then "-thread" else "-no-thread")
] ++ stdenv.lib.optionals openglSupport [
  "-dlopen-opengl"
  "-L${mesa}/lib"
  "-I${mesa}/include"
  "-L${libXmu}/lib"
  "-I${libXmu}/include"
];

# indented string
indented = ''
  This is the first line.
  This is the second line.
    This is the third line.
'';

stdenv.mkDerivation {
  postInstall =
    ''
      mkdir $out/bin $out/etc
      cp foo $out/bin
      echo "Hello World" > $out/etc/foo.conf
      ${if enableBar then "cp bar $out/bin" else ""}
    '';
}

reference

_12 = "twelve"

__blah = _12

variableX = _12

variable-y = variableX # note that the '-' character may be part of the variable name

__variable__z_ = variable-y


# paths

/bin/sh

./builder.sh

../xyzzy/fnord.nix

~/foo

local/file

./. # current directory

/. # root directory

~ # not a path

. # not a path

/ # not a path

# uri

https://nixos.org/nixos/manual/index.html

git+https://nixos.org/nixos/manual/index.html

file:///tmp/nixos

# lists

[ 123 ./foo.nix "abc" (f { x = y; }) ]

[ 123 ./foo.nix "abc" f { x = y; } ]

# sets

{ x = 123;
  text = "Hello";
  y = f { bla = 456; };
}

{ a = "Foo"; b = "Bar"; }.a

{ a = "Foo"; b = "Bar"; }.c or "Xyzzy"

{ "foo ${bar}" = 123; "nix-1.0" = 456; }."foo ${bar}"

{ foo = 123; }.${bar} or 456

{ ${if foo then "bar" else null} = true; }

# recursive sets

rec {
  x = y;
  y = 123;
}.x

# let-expressions

let
  x = "foo";
  y = "bar";
in x + y

let x = 123; in
{ inherit x;
  y = 456;
}

# functions

pattern: body

let negate = x: !x;
    concat = x: y: x + y;
in if negate true then concat "foo" "bar" else ""

map (concat "foo") [ "bar" "bla" "abc" ]

{ x, y, z }: z + y + x

{ x, y, z, ... }: z + y + x

{ x, y ? "foo", z ? "bar" }: z + y + x

args@{ x, y, z, ... }: z + y + x + args.a

let concat = { x, y }: x + y;
in concat { x = "foo"; y = "bar"; }

let add = { __functor = self: x: x + self.x; };
    inc = add // { x = 1; };
in inc 1

# conditionals

if e1 then e2 else e3

# assertions

assert e1; e2

# with-expressions

with e1; e2

let as = { x = "foo"; y = "bar"; };
in with as; x + y

with (import ./definitions.nix); ...

# Operators
# https://nixos.org/nix/manual/#sec-language-operators

e . attrpath or def

e1 e2

e ? attrpath

e1 ++ e2

e1 + e2

! e

e1 // e2

e1 == e2

e1 != e2

e1 && e2

e1 || e2

e1 -> e2

with e1; e2

let as = { x = "foo"; y = "bar"; };
in with as; x + y

with (import ./definitions.nix); ...

{ stdenv, fetchurl, perl }: # 1

stdenv.mkDerivation { # 2
  name = "hello-2.1.1"; # 1: String
  # 2: Multiline string
  configureFlags  = "
  ";
  meta = {
    # 3: Indented string
    description = '' # part of the string
    A contrived example of a Nix expression, suitable for testing the lexer for
    Rouge.
    '';
  };
  builder = ./builder.sh; # 4
  src = fetchurl { # 5
    url = ftp://ftp.nluug.nl/pub/gnu/hello/hello-2.1.1.tar.gz;
    md5 = "70c9ccf9fac07f762c24f2df2290784d";
  };
  inherit perl; # 6
}