12
12
13
13
rec {
14
14
15
- # Run the shell command `buildCommand' to produce a store path named
16
- # `name'. The attributes in `env' are added to the environment
17
- # prior to running the command.
15
+ /* Run the shell command `buildCommand' to produce a store path named
16
+ * `name'. The attributes in `env' are added to the environment
17
+ * prior to running the command. By default `runCommand' runs using
18
+ * stdenv with no compiler environment. `runCommandCC`
19
+ *
20
+ * Examples:
21
+ * runCommand "name" {envVariable = true;} ''echo hello''
22
+ * runCommandNoCC "name" {envVariable = true;} ''echo hello'' # equivalent to prior
23
+ * runCommandCC "name" {} ''gcc -o myfile myfile.c; cp myfile $out'';
24
+ */
18
25
runCommand = runCommandNoCC ;
19
26
runCommandNoCC = runCommand' stdenvNoCC ;
20
27
runCommandCC = runCommand' stdenv ;
21
28
22
29
23
- # Create a single file.
30
+ /* Writes a text file to the nix store.
31
+ * The contents of text is added to the file in the store.
32
+ *
33
+ * Examples:
34
+ * # Writes my-file to /nix/store/<store path>
35
+ * writeTextFile "my-file"
36
+ * ''
37
+ * Contents of File
38
+ * '';
39
+ *
40
+ * # Writes executable my-file to /nix/store/<store path>/bin/my-file
41
+ * writeTextFile "my-file"
42
+ * ''
43
+ * Contents of File
44
+ * ''
45
+ * true
46
+ * "/bin/my-file";
47
+ * true
48
+ */
24
49
writeTextFile =
25
50
{ name # the name of the derivation
26
51
, text
@@ -51,13 +76,69 @@ rec {
51
76
'' ;
52
77
53
78
54
- # Shorthands for `writeTextFile'.
79
+ /*
80
+ * Writes a text file to nix store with no optional parameters available.
81
+ *
82
+ * Example:
83
+ * # Writes contents of file to /nix/store/<store path>
84
+ * writeText "my-file"
85
+ * ''
86
+ * Contents of File
87
+ * '';
88
+ *
89
+ */
55
90
writeText = name : text : writeTextFile { inherit name text ; } ;
91
+ /*
92
+ * Writes a text file to nix store in a specific directory with no
93
+ * optional parameters available. Name passed is the destination.
94
+ *
95
+ * Example:
96
+ * # Writes contents of file to /nix/store/<store path>/<name>
97
+ * writeTextDir "share/my-file"
98
+ * ''
99
+ * Contents of File
100
+ * '';
101
+ *
102
+ */
56
103
writeTextDir = name : text : writeTextFile { inherit name text ; destination = "/${ name } " ; } ;
104
+ /*
105
+ * Writes a text file to /nix/store/<store path> and marks the file as executable.
106
+ *
107
+ * Example:
108
+ * # Writes my-file to /nix/store/<store path>/bin/my-file and makes executable
109
+ * writeScript "my-file"
110
+ * ''
111
+ * Contents of File
112
+ * '';
113
+ *
114
+ */
57
115
writeScript = name : text : writeTextFile { inherit name text ; executable = true ; } ;
116
+ /*
117
+ * Writes a text file to /nix/store/<store path>/bin/<name> and
118
+ * marks the file as executable.
119
+ *
120
+ * Example:
121
+ * # Writes my-file to /nix/store/<store path>/bin/my-file and makes executable.
122
+ * writeScript "my-file"
123
+ * ''
124
+ * Contents of File
125
+ * '';
126
+ *
127
+ */
58
128
writeScriptBin = name : text : writeTextFile { inherit name text ; executable = true ; destination = "/bin/${ name } " ; } ;
59
129
60
- # Create a Shell script, check its syntax
130
+ /*
131
+ * Writes a Shell script and check its syntax. Automatically includes interpreter
132
+ * above the contents passed.
133
+ *
134
+ * Example:
135
+ * # Writes my-file to /nix/store/<store path>/bin/my-file and makes executable.
136
+ * writeScript "my-file"
137
+ * ''
138
+ * Contents of File
139
+ * '';
140
+ *
141
+ */
61
142
writeShellScriptBin = name : text :
62
143
writeTextFile {
63
144
inherit name ;
@@ -90,7 +171,18 @@ rec {
90
171
$CC -x c code.c -o "$n"
91
172
'' ;
92
173
93
- # Create a forest of symlinks to the files in `paths'.
174
+ /*
175
+ * Create a forest of symlinks to the files in `paths'.
176
+ *
177
+ * Examples:
178
+ * # adds symlinks of hello to current build.
179
+ * { symlinkJoin, hello }:
180
+ * symlinkJoin { name = "myhello"; paths = [ hello ]; }
181
+ *
182
+ * # adds symlinks of hello to current build and prints "links added"
183
+ * { symlinkJoin, hello }:
184
+ * symlinkJoin { name = "myhello"; paths = [ hello ]; postBuild = "echo links added"; }
185
+ */
94
186
symlinkJoin =
95
187
args_ @{ name
96
188
, paths
@@ -112,7 +204,23 @@ rec {
112
204
'' ;
113
205
114
206
115
- # Make a package that just contains a setup hook with the given contents.
207
+ /*
208
+ * Make a package that just contains a setup hook with the given contents.
209
+ * This setup hook will be invoked by any package that includes this package
210
+ * as a buildInput. Optionally takes a list of substitutions that should be
211
+ * applied to the resulting script.
212
+ *
213
+ * Examples:
214
+ * # setup hook that depends on the hello package and runs ./myscript.sh
215
+ * myhellohook = makeSetupHook { deps = [ hello ]; } ./myscript.sh;
216
+ *
217
+ * # wrotes a setup hook where @bash@ myscript.sh is substituted for the
218
+ * # bash interpreter.
219
+ * myhellohookSub = makeSetupHook {
220
+ * deps = [ hello ];
221
+ * substitutions = { bash = "${pkgs.bash}/bin/bash"; };
222
+ * } ./myscript.sh;
223
+ */
116
224
makeSetupHook = { name ? "hook" , deps ? [ ] , substitutions ? { } } : script :
117
225
runCommand name substitutions
118
226
( ''
@@ -126,6 +234,7 @@ rec {
126
234
127
235
128
236
# Write the references (i.e. the runtime dependencies in the Nix store) of `path' to a file.
237
+
129
238
writeReferencesToFile = path : runCommand "runtime-deps"
130
239
{
131
240
exportReferencesGraph = [ "graph" path ] ;
@@ -141,8 +250,17 @@ rec {
141
250
'' ;
142
251
143
252
144
- # Quickly create a set of symlinks to derivations.
145
- # entries is a list of attribute sets like { name = "name" ; path = "/nix/store/..."; }
253
+ /*
254
+ * Quickly create a set of symlinks to derivations.
255
+ * entries is a list of attribute sets like
256
+ * { name = "name" ; path = "/nix/store/..."; }
257
+ *
258
+ * Example:
259
+ *
260
+ * # Symlinks hello path in store to current $out/hello
261
+ * linkFarm "hello" entries = [ { name = "hello"; path = pkgs.hello; } ];
262
+ *
263
+ */
146
264
linkFarm = name : entries : runCommand name { preferLocalBuild = true ; }
147
265
( "mkdir -p $out; cd $out; \n " +
148
266
( lib . concatMapStrings ( x : ''
@@ -151,9 +269,20 @@ rec {
151
269
'' ) entries ) ) ;
152
270
153
271
154
- # Print an error message if the file with the specified name and
155
- # hash doesn't exist in the Nix store. Do not use this function; it
156
- # produces packages that cannot be built automatically.
272
+ /* Print an error message if the file with the specified name and
273
+ * hash doesn't exist in the Nix store. This function should only
274
+ * be used by non-redistributable software with an unfree license
275
+ * that we need to require the user to download manually. It produces
276
+ * packages that cannot be built automatically.
277
+ *
278
+ * Examples:
279
+ *
280
+ * requireFile {
281
+ * name = "my-file";
282
+ * url = "http://example.com/download/";
283
+ * sha256 = "ffffffffffffffffffffffffffffffffffffffffffffffffffff";
284
+ * }
285
+ */
157
286
requireFile = { name ? null
158
287
, sha256 ? null
159
288
, sha1 ? null
0 commit comments