summary refs log blame commit diff
path: root/pkgs/build-support/closure-info.nix
blob: 54b1fe59b66d3773106bb4afc062c28740e99119 (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                                      
                                 
 

                        
 
                           
 
                                            
 
                                      
 


                                               
 
                           
 
                
 



                                                                                                                                                                              
# 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, coreutils, jq, perl, pathsFromGraph }:

{ rootPaths }:

assert builtins.langVersion >= 5;

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

  __structuredAttrs = true;

  exportReferencesGraph.closure = rootPaths;

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

  builder = builtins.toFile "builder"
    ''
      if [ -e .attrs.sh ]; then . .attrs.sh; fi

      out=''${outputs[out]}

      mkdir $out

      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
    '';
}