at 23.11-beta 2.5 kB view raw
1import ./make-test-python.nix ({ lib, pkgs, ... }: 2 3{ 4 name = "binary-cache"; 5 meta.maintainers = with lib.maintainers; [ thomasjm ]; 6 7 nodes.machine = 8 { pkgs, ... }: { 9 imports = [ ../modules/installer/cd-dvd/channel.nix ]; 10 environment.systemPackages = [ pkgs.python3 ]; 11 system.extraDependencies = [ pkgs.hello.inputDerivation ]; 12 nix.extraOptions = '' 13 experimental-features = nix-command 14 ''; 15 }; 16 17 testScript = '' 18 # Build the cache, then remove it from the store 19 cachePath = machine.succeed("nix-build --no-out-link -E 'with import <nixpkgs> {}; mkBinaryCache { rootPaths = [hello]; }'").strip() 20 machine.succeed("cp -r %s/. /tmp/cache" % cachePath) 21 machine.succeed("nix-store --delete " + cachePath) 22 23 # Sanity test of cache structure 24 status, stdout = machine.execute("ls /tmp/cache") 25 cache_files = stdout.split() 26 assert ("nix-cache-info" in cache_files) 27 assert ("nar" in cache_files) 28 29 # Nix store ping should work 30 machine.succeed("nix store ping --store file:///tmp/cache") 31 32 # Cache should contain a .narinfo referring to "hello" 33 grepLogs = machine.succeed("grep -l 'StorePath: /nix/store/[[:alnum:]]*-hello-.*' /tmp/cache/*.narinfo") 34 35 # Get the store path referenced by the .narinfo 36 narInfoFile = grepLogs.strip() 37 narInfoContents = machine.succeed("cat " + narInfoFile) 38 import re 39 match = re.match(r"^StorePath: (/nix/store/[a-z0-9]*-hello-.*)$", narInfoContents, re.MULTILINE) 40 if not match: raise Exception("Couldn't find hello store path in cache") 41 storePath = match[1] 42 43 # Delete the store path 44 machine.succeed("nix-store --delete " + storePath) 45 machine.succeed("[ ! -d %s ] || exit 1" % storePath) 46 47 # Should be able to build hello using the cache 48 logs = machine.succeed("nix-build -A hello '<nixpkgs>' --option require-sigs false --option trusted-substituters file:///tmp/cache --option substituters file:///tmp/cache 2>&1") 49 logLines = logs.split("\n") 50 if not "this path will be fetched" in logLines[0]: raise Exception("Unexpected first log line") 51 def shouldBe(got, desired): 52 if got != desired: raise Exception("Expected '%s' but got '%s'" % (desired, got)) 53 shouldBe(logLines[1], " " + storePath) 54 shouldBe(logLines[2], "copying path '%s' from 'file:///tmp/cache'..." % storePath) 55 shouldBe(logLines[3], storePath) 56 57 # Store path should exist in the store now 58 machine.succeed("[ -d %s ] || exit 1" % storePath) 59 ''; 60})