Skip to content

Commit 31f1c93

Browse files
authored
mkBinaryCache: fix nixos/tests/binary-cache.nix (NixOS#370773)
2 parents 2ab4a08 + 6b261ea commit 31f1c93

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

nixos/tests/binary-cache.nix

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,37 @@ import ./make-test-python.nix (
99
{ pkgs, ... }:
1010
{
1111
imports = [ ../modules/installer/cd-dvd/channel.nix ];
12-
environment.systemPackages = [ pkgs.python3 ];
13-
system.extraDependencies = [ pkgs.hello.inputDerivation ];
12+
environment.systemPackages = with pkgs; [
13+
openssl
14+
python3
15+
];
16+
17+
# We encrypt the binary cache before putting it on the machine so Nix
18+
# doesn't bring any references along.
19+
environment.etc."binary-cache.tar.gz.encrypted".source =
20+
with pkgs;
21+
runCommand "binary-cache.tar.gz.encrypted"
22+
{
23+
allowReferences = [ ];
24+
nativeBuildInputs = [ openssl ];
25+
}
26+
''
27+
tar -czf tmp.tar.gz -C "${mkBinaryCache { rootPaths = [ hello ]; }}" .
28+
openssl enc -aes-256-cbc -salt -in tmp.tar.gz -out $out -k mysecretpassword
29+
'';
30+
1431
nix.extraOptions = ''
1532
experimental-features = nix-command
1633
'';
1734
};
1835

1936
testScript = ''
20-
# Build the cache, then remove it from the store
21-
cachePath = machine.succeed("nix-build --no-out-link -E 'with import <nixpkgs> {}; mkBinaryCache { rootPaths = [hello]; }'").strip()
22-
machine.succeed("cp -r %s/. /tmp/cache" % cachePath)
23-
machine.succeed("nix-store --delete " + cachePath)
37+
# Decrypt the cache into /tmp/binary-cache.tar.gz
38+
machine.succeed("openssl enc -d -aes-256-cbc -in /etc/binary-cache.tar.gz.encrypted -out /tmp/binary-cache.tar.gz -k mysecretpassword")
39+
40+
# Untar the cache into /tmp/cache
41+
machine.succeed("mkdir /tmp/cache")
42+
machine.succeed("tar -C /tmp/cache -xf /tmp/binary-cache.tar.gz")
2443
2544
# Sanity test of cache structure
2645
status, stdout = machine.execute("ls /tmp/cache")
@@ -42,8 +61,7 @@ import ./make-test-python.nix (
4261
if not match: raise Exception("Couldn't find hello store path in cache")
4362
storePath = match[1]
4463
45-
# Delete the store path
46-
machine.succeed("nix-store --delete " + storePath)
64+
# Make sure the store path doesn't exist yet
4765
machine.succeed("[ ! -d %s ] || exit 1" % storePath)
4866
4967
# Should be able to build hello using the cache

0 commit comments

Comments
 (0)