summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-02-07 15:47:19 +0100
committerEelco Dolstra <edolstra@gmail.com>2018-02-07 15:49:02 +0100
commit5193807750853a592bb7d0202a998d1f2c780cf2 (patch)
tree173f7d69241037ecad7c8e43d205d4b608a42b6d
parentcc0caac098b56b67300778c8a1738f8a16e08442 (diff)
downloadnixpkgs-5193807750853a592bb7d0202a998d1f2c780cf2.tar
nixpkgs-5193807750853a592bb7d0202a998d1f2c780cf2.tar.gz
nixpkgs-5193807750853a592bb7d0202a998d1f2c780cf2.tar.bz2
nixpkgs-5193807750853a592bb7d0202a998d1f2c780cf2.tar.lz
nixpkgs-5193807750853a592bb7d0202a998d1f2c780cf2.tar.xz
nixpkgs-5193807750853a592bb7d0202a998d1f2c780cf2.tar.zst
nixpkgs-5193807750853a592bb7d0202a998d1f2c780cf2.zip
VM tests: Initialize the Nix database with correct NAR hashes/sizes
-rw-r--r--nixos/tests/misc.nix11
-rw-r--r--pkgs/build-support/closure-info.nix55
2 files changed, 25 insertions, 41 deletions
diff --git a/nixos/tests/misc.nix b/nixos/tests/misc.nix
index 6de17518214..4fd9466dc50 100644
--- a/nixos/tests/misc.nix
+++ b/nixos/tests/misc.nix
@@ -1,11 +1,13 @@
 # Miscellaneous small tests that don't warrant their own VM run.
 
-import ./make-test.nix ({ pkgs, ...} : {
+import ./make-test.nix ({ pkgs, ...} : rec {
   name = "misc";
   meta = with pkgs.stdenv.lib.maintainers; {
     maintainers = [ eelco chaoflow ];
   };
 
+  foo = pkgs.writeText "foo" "Hello World";
+
   machine =
     { config, lib, pkgs, ... }:
     with lib;
@@ -27,10 +29,17 @@ import ./make-test.nix ({ pkgs, ...} : {
       security.sudo = { enable = true; wheelNeedsPassword = false; };
       boot.kernel.sysctl."vm.swappiness" = 1;
       boot.kernelParams = [ "vsyscall=emulate" ];
+      system.extraDependencies = [ foo ];
     };
 
   testScript =
     ''
+      subtest "nix-db", sub {
+          my $json = $machine->succeed("nix path-info --json ${foo}");
+          $json =~ /"narHash":"sha256:0afw0d9j1hvwiz066z93jiddc33nxg6i6qyp26vnqyglpyfivlq5"/ or die "narHash not set";
+          $json =~ /"narSize":128/ or die "narSize not set";
+      };
+
       subtest "nixos-version", sub {
           $machine->succeed("[ `nixos-version | wc -w` = 2 ]");
       };
diff --git a/pkgs/build-support/closure-info.nix b/pkgs/build-support/closure-info.nix
index 4d178ac96c5..54b1fe59b66 100644
--- a/pkgs/build-support/closure-info.nix
+++ b/pkgs/build-support/closure-info.nix
@@ -8,51 +8,26 @@
 
 { rootPaths }:
 
-#if builtins.langVersion >= 5 then
-# FIXME: it doesn't work on Hydra, failing to find mkdir;
-#   perhaps .attrs.sh clobbers PATH with new nix?
-if false then
+assert builtins.langVersion >= 5;
 
-  # Nix >= 1.12: Include NAR hash / size info.
+stdenv.mkDerivation {
+  name = "closure-info";
 
-  stdenv.mkDerivation {
-    name = "closure-info";
+  __structuredAttrs = true;
 
-    __structuredAttrs = true;
+  exportReferencesGraph.closure = rootPaths;
 
-    exportReferencesGraph.closure = rootPaths;
+  PATH = "${coreutils}/bin:${jq}/bin";
 
-    PATH = "${coreutils}/bin:${jq}/bin";
+  builder = builtins.toFile "builder"
+    ''
+      if [ -e .attrs.sh ]; then . .attrs.sh; fi
 
-    builder = builtins.toFile "builder"
-      ''
-        if [ -e .attrs.sh ]; then . .attrs.sh; fi
+      out=''${outputs[out]}
 
-        out=''${outputs[out]}
+      mkdir $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
-      '';
-  }
-
-else
-
-  # Nix < 1.12
-
-  stdenv.mkDerivation {
-    name = "closure-info";
-
-    exportReferencesGraph =
-      map (x: [("closure-" + baseNameOf x) x]) rootPaths;
-
-    buildInputs = [ perl ];
-
-    buildCommand =
-      ''
-        mkdir $out
-        printRegistration=1 perl ${pathsFromGraph} closure-* > $out/registration
-        perl ${pathsFromGraph} closure-* > $out/store-paths
-      '';
-  }
+      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
+    '';
+}