VM tests: Initialize the Nix database with correct NAR hashes/sizes

+25 -41
+10 -1
nixos/tests/misc.nix
··· 1 1 # Miscellaneous small tests that don't warrant their own VM run. 2 2 3 - import ./make-test.nix ({ pkgs, ...} : { 3 + import ./make-test.nix ({ pkgs, ...} : rec { 4 4 name = "misc"; 5 5 meta = with pkgs.stdenv.lib.maintainers; { 6 6 maintainers = [ eelco chaoflow ]; 7 7 }; 8 + 9 + foo = pkgs.writeText "foo" "Hello World"; 8 10 9 11 machine = 10 12 { config, lib, pkgs, ... }: ··· 27 29 security.sudo = { enable = true; wheelNeedsPassword = false; }; 28 30 boot.kernel.sysctl."vm.swappiness" = 1; 29 31 boot.kernelParams = [ "vsyscall=emulate" ]; 32 + system.extraDependencies = [ foo ]; 30 33 }; 31 34 32 35 testScript = 33 36 '' 37 + subtest "nix-db", sub { 38 + my $json = $machine->succeed("nix path-info --json ${foo}"); 39 + $json =~ /"narHash":"sha256:0afw0d9j1hvwiz066z93jiddc33nxg6i6qyp26vnqyglpyfivlq5"/ or die "narHash not set"; 40 + $json =~ /"narSize":128/ or die "narSize not set"; 41 + }; 42 + 34 43 subtest "nixos-version", sub { 35 44 $machine->succeed("[ `nixos-version | wc -w` = 2 ]"); 36 45 };
+15 -40
pkgs/build-support/closure-info.nix
··· 8 8 9 9 { rootPaths }: 10 10 11 - #if builtins.langVersion >= 5 then 12 - # FIXME: it doesn't work on Hydra, failing to find mkdir; 13 - # perhaps .attrs.sh clobbers PATH with new nix? 14 - if false then 11 + assert builtins.langVersion >= 5; 15 12 16 - # Nix >= 1.12: Include NAR hash / size info. 13 + stdenv.mkDerivation { 14 + name = "closure-info"; 17 15 18 - stdenv.mkDerivation { 19 - name = "closure-info"; 16 + __structuredAttrs = true; 20 17 21 - __structuredAttrs = true; 18 + exportReferencesGraph.closure = rootPaths; 22 19 23 - exportReferencesGraph.closure = rootPaths; 20 + PATH = "${coreutils}/bin:${jq}/bin"; 24 21 25 - PATH = "${coreutils}/bin:${jq}/bin"; 22 + builder = builtins.toFile "builder" 23 + '' 24 + if [ -e .attrs.sh ]; then . .attrs.sh; fi 26 25 27 - builder = builtins.toFile "builder" 28 - '' 29 - if [ -e .attrs.sh ]; then . .attrs.sh; fi 26 + out=''${outputs[out]} 30 27 31 - out=''${outputs[out]} 28 + mkdir $out 32 29 33 - mkdir $out 34 - 35 - jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < .attrs.json | head -n -1 > $out/registration 36 - jq -r .closure[].path < .attrs.json > $out/store-paths 37 - ''; 38 - } 39 - 40 - else 41 - 42 - # Nix < 1.12 43 - 44 - stdenv.mkDerivation { 45 - name = "closure-info"; 46 - 47 - exportReferencesGraph = 48 - map (x: [("closure-" + baseNameOf x) x]) rootPaths; 49 - 50 - buildInputs = [ perl ]; 51 - 52 - buildCommand = 53 - '' 54 - mkdir $out 55 - printRegistration=1 perl ${pathsFromGraph} closure-* > $out/registration 56 - perl ${pathsFromGraph} closure-* > $out/store-paths 57 - ''; 58 - } 30 + jq -r '.closure | map([.path, .narHash, .narSize, "", (.references | length)] + .references) | add | map("\(.)\n") | add' < .attrs.json | head -n -1 > $out/registration 31 + jq -r .closure[].path < .attrs.json > $out/store-paths 32 + ''; 33 + }