Skip to content

Commit 024eb9a

Browse files
Samuel Leathersroberth
Samuel Leathers
authored andcommittedOct 2, 2018
trivial builders: adding usage documentation for functions
1 parent 1643967 commit 024eb9a

File tree

1 file changed

+142
-13
lines changed

1 file changed

+142
-13
lines changed
 

Diff for: ‎pkgs/build-support/trivial-builders.nix

+142-13
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,40 @@ in
1212

1313
rec {
1414

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+
*/
1825
runCommand = runCommandNoCC;
1926
runCommandNoCC = runCommand' stdenvNoCC;
2027
runCommandCC = runCommand' stdenv;
2128

2229

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+
*/
2449
writeTextFile =
2550
{ name # the name of the derivation
2651
, text
@@ -51,13 +76,69 @@ rec {
5176
'';
5277

5378

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+
*/
5590
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+
*/
56103
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+
*/
57115
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+
*/
58128
writeScriptBin = name: text: writeTextFile {inherit name text; executable = true; destination = "/bin/${name}";};
59129

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+
*/
61142
writeShellScriptBin = name : text :
62143
writeTextFile {
63144
inherit name;
@@ -90,7 +171,18 @@ rec {
90171
$CC -x c code.c -o "$n"
91172
'';
92173

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+
*/
94186
symlinkJoin =
95187
args_@{ name
96188
, paths
@@ -112,7 +204,23 @@ rec {
112204
'';
113205

114206

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+
*/
116224
makeSetupHook = { name ? "hook", deps ? [], substitutions ? {} }: script:
117225
runCommand name substitutions
118226
(''
@@ -126,6 +234,7 @@ rec {
126234

127235

128236
# Write the references (i.e. the runtime dependencies in the Nix store) of `path' to a file.
237+
129238
writeReferencesToFile = path: runCommand "runtime-deps"
130239
{
131240
exportReferencesGraph = ["graph" path];
@@ -141,8 +250,17 @@ rec {
141250
'';
142251

143252

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+
*/
146264
linkFarm = name: entries: runCommand name { preferLocalBuild = true; }
147265
("mkdir -p $out; cd $out; \n" +
148266
(lib.concatMapStrings (x: ''
@@ -151,9 +269,20 @@ rec {
151269
'') entries));
152270

153271

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+
*/
157286
requireFile = { name ? null
158287
, sha256 ? null
159288
, sha1 ? null

0 commit comments

Comments
 (0)
Please sign in to comment.