Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{
2 stdenvNoCC,
3 coreutils,
4 jq,
5}:
6
7/**
8 Produces metadata about the closure of the given root paths.
9
10 1. Total NAR size in `$out/total-nar-size`.
11 2. Registration, suitable for `nix-store --load-db`, in `$out/registration`.
12 Can also be used with `nix-store --register-validity --hash-given`.
13 3. All store paths for the closure in `$out/store-paths`.
14
15 # Inputs
16
17 `rootPaths` ([Path])
18
19 : List of root paths to include in the closure information.
20
21 # Type
22
23 ```
24 closureInfo :: { rootPaths :: [Path]; } -> Derivation
25 ```
26
27 # Examples
28 :::{.example}
29 ## `pkgs.closureInfo` usage example
30 ```
31 pkgs.closureInfo {
32 rootPaths = [ pkgs.hello pkgs.bc pkgs.dwarf2json ];
33 }
34 =>
35 «derivation /nix/store/...-closure-info.drv»
36 ```
37
38 :::
39*/
40{ rootPaths }:
41
42assert builtins.langVersion >= 5;
43
44stdenvNoCC.mkDerivation {
45 name = "closure-info";
46
47 __structuredAttrs = true;
48
49 exportReferencesGraph.closure = rootPaths;
50
51 preferLocalBuild = true;
52
53 nativeBuildInputs = [
54 coreutils
55 jq
56 ];
57
58 empty = rootPaths == [ ];
59
60 buildCommand = ''
61 out=''${outputs[out]}
62
63 mkdir $out
64
65 if [[ -n "$empty" ]]; then
66 echo 0 > $out/total-nar-size
67 touch $out/registration $out/store-paths
68 else
69 jq -r ".closure | map(.narSize) | add" < "$NIX_ATTRS_JSON_FILE" > $out/total-nar-size
70 jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < "$NIX_ATTRS_JSON_FILE" | head -n -1 > $out/registration
71 jq -r '.closure[].path' < "$NIX_ATTRS_JSON_FILE" > $out/store-paths
72 fi
73
74 '';
75}