git.iko.soy/typeable/nixpkgs
on master help sign in
writeReferencesToFile: docs and tests
commited4523186e452d185d8ba1d1eabe07ace33a4f87 authorRobert Hensing <robert@roberthensing.nl> dateSat 15 May 2021, 15:10 (6 years ago) parentcc60f81
2 files changed+42
doc/builders/trivial-builders.chapter.md+26 pkgs/build-support/trivial-builders/test.sh+16
doc/builders/trivial-builders.chapter.md+26
@@ -51,6 +51,32 @@ Many more commands wrap `writeTextFile` including `writeText`, `writeTextDir`, `
5151
5252This can be used to put many derivations into the same directory structure. It works by creating a new derivation and adding symlinks to each of the paths listed. It expects two arguments, `name`, and `paths`. `name` is the name used in the Nix store path for the created derivation. `paths` is a list of paths that will be symlinked. These paths can be to Nix store derivations or any other subdirectory contained within.
5353
54+## `writeReferencesToFile` {#trivial-builder-writeReferencesToFile}
55+
56+Writes the closure of transitive dependencies to a file.
57+
58+This produces the equivalent of `nix-store -q --requisites`.
59+
60+For example,
61+
62+```nix
63+writeReferencesToFile (writeScriptBin "hi" ''${hello}/bin/hello'')
64+```
65+
66+produces an output path `/nix/store/<hash>-runtime-deps` containing
67+
68+```nix
69+/nix/store/<hash>-hello-2.10
70+/nix/store/<hash>-hi
71+/nix/store/<hash>-libidn2-2.3.0
72+/nix/store/<hash>-libunistring-0.9.10
73+/nix/store/<hash>-glibc-2.32-40
74+```
75+
76+You can see that this includes `hi`, the original input path,
77+`hello`, which is a direct reference, but also
78+the other paths that are indirectly required to run `hello`.
79+
5480## `writeDirectReferencesToFile` {#trivial-builder-writeDirectReferencesToFile}
5581
5682Writes the set of references to the output file, that is, their immediate dependencies.
pkgs/build-support/trivial-builders/test.sh+16
@@ -38,4 +38,20 @@ testDirectReferences 'writeText "hi" "hello"'
3838testDirectReferences 'writeText "hi" "hello ${hello}"'
3939testDirectReferences 'writeText "hi" "hello ${hello} ${figlet}"'
4040
41+
42+
43+testClosure() {
44+ expr="$1"
45+ diff -U3 \
46+ <(sort <$(nix-build --no-out-link --expr "with import ../../.. {}; writeReferencesToFile ($expr)")) \
47+ <(nix-store -q --requisites $(nix-build --no-out-link --expr "with import ../../.. {}; ($expr)") | sort)
48+}
49+
50+testClosure 'hello'
51+testClosure 'figlet'
52+testClosure 'writeText "hi" "hello"'
53+testClosure 'writeText "hi" "hello ${hello}"'
54+testClosure 'writeText "hi" "hello ${hello} ${figlet}"'
55+
56+
4157echo 'OK!'