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

+25 -41
+10 -1
nixos/tests/misc.nix
··· 1 # Miscellaneous small tests that don't warrant their own VM run. 2 3 - import ./make-test.nix ({ pkgs, ...} : { 4 name = "misc"; 5 meta = with pkgs.stdenv.lib.maintainers; { 6 maintainers = [ eelco chaoflow ]; 7 }; 8 9 machine = 10 { config, lib, pkgs, ... }: ··· 27 security.sudo = { enable = true; wheelNeedsPassword = false; }; 28 boot.kernel.sysctl."vm.swappiness" = 1; 29 boot.kernelParams = [ "vsyscall=emulate" ]; 30 }; 31 32 testScript = 33 '' 34 subtest "nixos-version", sub { 35 $machine->succeed("[ `nixos-version | wc -w` = 2 ]"); 36 };
··· 1 # Miscellaneous small tests that don't warrant their own VM run. 2 3 + import ./make-test.nix ({ pkgs, ...} : rec { 4 name = "misc"; 5 meta = with pkgs.stdenv.lib.maintainers; { 6 maintainers = [ eelco chaoflow ]; 7 }; 8 + 9 + foo = pkgs.writeText "foo" "Hello World"; 10 11 machine = 12 { config, lib, pkgs, ... }: ··· 29 security.sudo = { enable = true; wheelNeedsPassword = false; }; 30 boot.kernel.sysctl."vm.swappiness" = 1; 31 boot.kernelParams = [ "vsyscall=emulate" ]; 32 + system.extraDependencies = [ foo ]; 33 }; 34 35 testScript = 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 + 43 subtest "nixos-version", sub { 44 $machine->succeed("[ `nixos-version | wc -w` = 2 ]"); 45 };
+15 -40
pkgs/build-support/closure-info.nix
··· 8 9 { rootPaths }: 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 15 16 - # Nix >= 1.12: Include NAR hash / size info. 17 18 - stdenv.mkDerivation { 19 - name = "closure-info"; 20 21 - __structuredAttrs = true; 22 23 - exportReferencesGraph.closure = rootPaths; 24 25 - PATH = "${coreutils}/bin:${jq}/bin"; 26 27 - builder = builtins.toFile "builder" 28 - '' 29 - if [ -e .attrs.sh ]; then . .attrs.sh; fi 30 31 - out=''${outputs[out]} 32 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 - }
··· 8 9 { rootPaths }: 10 11 + assert builtins.langVersion >= 5; 12 13 + stdenv.mkDerivation { 14 + name = "closure-info"; 15 16 + __structuredAttrs = true; 17 18 + exportReferencesGraph.closure = rootPaths; 19 20 + PATH = "${coreutils}/bin:${jq}/bin"; 21 22 + builder = builtins.toFile "builder" 23 + '' 24 + if [ -e .attrs.sh ]; then . .attrs.sh; fi 25 26 + out=''${outputs[out]} 27 28 + mkdir $out 29 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 + }