binary-cache/tests/substitution.nix

64 lines
1.7 KiB
Nix
Raw Normal View History

2024-07-17 16:36:20 +00:00
{ pkgs }:
let
#hello = pkgs.hello.overrideAttrs { pname = "custom-hello"; };
inherit (pkgs) hello;
in
pkgs.testers.runNixOSTest (_: {
2024-07-19 08:51:57 +00:00
name = "cache substitution test";
2024-07-17 16:36:20 +00:00
nodes = {
2024-07-19 08:51:57 +00:00
cache = {
imports = [
./common
../modules
];
2024-07-17 16:36:20 +00:00
2024-07-19 08:51:57 +00:00
system.extraDependencies = [ hello ];
2024-07-17 16:36:20 +00:00
2024-07-19 08:51:57 +00:00
services.tvix-binary-cache = {
enable = true;
enableNginx = true;
nginx = {
clientMaxBodySize = "50G";
host = "cache";
2024-07-17 16:36:20 +00:00
};
2024-07-19 08:51:57 +00:00
caches = {
cache.grpcListenAddress = "[::1]:5000";
cache.narBridgeListenAddress = "[::1]:8000";
2024-07-17 16:36:20 +00:00
};
};
2024-07-19 08:51:57 +00:00
services.nginx.virtualHosts.cache = {
default = true;
};
networking.firewall.allowedTCPPorts = [ 80 ];
};
2024-07-17 16:36:20 +00:00
client =
{ lib, ... }:
{
imports = [ ./common ];
nix.settings = {
substituters = lib.mkForce [ "http://cache/cache" ];
trusted-public-keys = lib.mkForce [ (builtins.readFile ./cache-keys/pubkey) ];
};
};
};
testScript = ''
import time
start_all()
cache.wait_for_unit("nginx.service")
cache.wait_for_unit("narbridge-cache.service")
2024-07-17 16:36:20 +00:00
time.sleep(1)
with subtest("Nar bridge home"):
cache.succeed("curl -f http://127.0.0.1/cache/nix-cache-info")
2024-07-17 16:36:20 +00:00
with subtest("Path signature and copy"):
# Sign
cache.succeed("nix store sign -k ${./cache-keys/privkey} ${hello}")
cache.succeed("nix copy --to 'http://127.0.0.1/cache/?compression=none' ${hello}")
with subtest("Substitution"):
client.succeed("nix-store --delete ${hello}")
client.fail("stat ${hello}")
client.succeed("nix-store -r ${hello}")
client.succeed("stat ${hello}")
'';
})