summary refs log tree commit diff
path: root/pkgs/build-support/closure-info.nix
blob: 6b3ff6fd62b05492735f452310f2c5cae245f3fa (plain) (blame)
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
# This derivation builds two files containing information about the
# closure of 'rootPaths': $out/store-paths contains the paths in the
# closure, and $out/registration contains a file suitable for use with
# "nix-store --load-db" and "nix-store --register-validity
# --hash-given".

{ stdenv, buildPackages }:

{ rootPaths }:

assert builtins.langVersion >= 5;

stdenv.mkDerivation {
  name = "closure-info";

  __structuredAttrs = true;

  exportReferencesGraph.closure = rootPaths;

  preferLocalBuild = true;

  PATH = "${buildPackages.coreutils}/bin:${buildPackages.jq}/bin";

  builder = builtins.toFile "builder"
    ''
      . .attrs.sh

      out=''${outputs[out]}

      mkdir $out

      jq -r ".closure | map(.narSize) | add" < .attrs.json > $out/total-nar-size
      jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < .attrs.json | head -n -1 > $out/registration
      jq -r .closure[].path < .attrs.json > $out/store-paths
    '';
}