87 lines
2.4 KiB
Nix
87 lines
2.4 KiB
Nix
{ pkgs }:
|
|
let
|
|
#hello = pkgs.hello.overrideAttrs { pname = "custom-hello"; };
|
|
inherit (pkgs) hello;
|
|
in
|
|
pkgs.testers.runNixOSTest (_: {
|
|
name = "caching of upstream nar-store";
|
|
nodes = {
|
|
cache = {
|
|
imports = [
|
|
./common
|
|
../modules
|
|
];
|
|
|
|
system.extraDependencies = [ hello ];
|
|
|
|
services = {
|
|
tvix-binary-cache = {
|
|
enable = true;
|
|
enableNginx = true;
|
|
nginx = {
|
|
clientMaxBodySize = "50G";
|
|
host = "cache";
|
|
};
|
|
caches = {
|
|
cache = {
|
|
port = 8000;
|
|
remote-path-info-service-addr = "nix+http://localhost/upstream/"; # ?trusted-public-keys=${lib.escapeURL (builtins.readFile ./cache-keys/pubkey)}";
|
|
};
|
|
};
|
|
};
|
|
|
|
nix-serve = {
|
|
enable = true;
|
|
port = 8001;
|
|
secretKeyFile = "${./cache-keys/privkey}";
|
|
};
|
|
|
|
nginx = {
|
|
virtualHosts.cache = {
|
|
default = true;
|
|
locations = {
|
|
"/upstream".return = "302 /upstream/";
|
|
"/upstream/".proxyPass = "http://localhost:8001/";
|
|
};
|
|
};
|
|
};
|
|
|
|
};
|
|
networking.firewall.allowedTCPPorts = [ 80 ];
|
|
};
|
|
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("tvix-store-cache.service")
|
|
cache.wait_for_unit("nix-serve.service")
|
|
cache.wait_for_open_port(8001)
|
|
time.sleep(1)
|
|
|
|
def delete_and_substitute():
|
|
client.succeed("nix-store --delete ${hello}")
|
|
client.fail("stat ${hello}")
|
|
client.succeed("nix-store -r ${hello}")
|
|
client.succeed("stat ${hello}")
|
|
|
|
with subtest("Upload"):
|
|
narHash = "${hello}"[11:11+32]
|
|
cache.succeed(f"curl -f 'http://127.0.0.1/upstream/{narHash}.narinfo'")
|
|
cache.succeed(f"curl -f 'http://127.0.0.1/cache/{narHash}.narinfo'")
|
|
with subtest("Try to substitute from cache"):
|
|
delete_and_substitute()
|
|
with subtest("Check effective caching"):
|
|
cache.succeed("systemctl stop nix-serve.service")
|
|
delete_and_substitute()
|
|
'';
|
|
})
|