1{
2 lib,
3 pkgs,
4 ...
5}:
6
7{
8 name = "ncps";
9
10 nodes = {
11 harmonia = {
12 services.harmonia = {
13 enable = true;
14 signKeyPaths = [
15 (pkgs.writeText "cache-key" "cache.example.com-1:9FhO0w+7HjZrhvmzT1VlAZw4OSAlFGTgC24Seg3tmPl4gZBdwZClzTTHr9cVzJpwsRSYLTu7hEAQe3ljy92CWg==")
16 ];
17 settings.priority = 35;
18 };
19
20 networking.firewall.allowedTCPPorts = [ 5000 ];
21 system.extraDependencies = [ pkgs.emptyFile ];
22 };
23
24 ncps = {
25 services.ncps = {
26 enable = true;
27
28 cache = {
29 hostName = "ncps";
30 secretKeyPath = builtins.toString (
31 pkgs.writeText "ncps-cache-key" "ncps:dcrGsrku0KvltFhrR5lVIMqyloAdo0y8vYZOeIFUSLJS2IToL7dPHSSCk/fi+PJf8EorpBn8PU7MNhfvZoI8mA=="
32 );
33 };
34
35 upstream = {
36 caches = [ "http://harmonia:5000" ];
37 publicKeys = [
38 "cache.example.com-1:eIGQXcGQpc00x6/XFcyacLEUmC07u4RAEHt5Y8vdglo="
39 ];
40 };
41 };
42
43 networking.firewall.allowedTCPPorts = [ 8501 ];
44 };
45
46 client01 = {
47 nix.settings = {
48 substituters = lib.mkForce [ "http://ncps:8501" ];
49 trusted-public-keys = lib.mkForce [
50 "ncps:UtiE6C+3Tx0kgpP34vjyX/BKK6QZ/D1OzDYX72aCPJg="
51 ];
52 };
53 };
54 };
55
56 testScript =
57 { nodes, ... }:
58 let
59 narinfoName =
60 (lib.strings.removePrefix "/nix/store/" (
61 lib.strings.removeSuffix "-empty-file" pkgs.emptyFile.outPath
62 ))
63 + ".narinfo";
64
65 narinfoNameChars = lib.strings.stringToCharacters narinfoName;
66
67 narinfoPath = lib.concatStringsSep "/" [
68 nodes.ncps.services.ncps.cache.dataPath
69 "store/narinfo"
70 (lib.lists.elemAt narinfoNameChars 0)
71 ((lib.lists.elemAt narinfoNameChars 0) + (lib.lists.elemAt narinfoNameChars 1))
72 narinfoName
73 ];
74 in
75 ''
76 start_all()
77
78 harmonia.wait_for_unit("harmonia.service")
79
80 ncps.wait_for_unit("ncps.service")
81
82 client01.wait_until_succeeds("curl -f http://ncps:8501/ | grep '\"hostname\":\"${toString nodes.ncps.services.ncps.cache.hostName}\"' >&2")
83
84 client01.succeed("cat /etc/nix/nix.conf >&2")
85 client01.succeed("nix-store --realise ${pkgs.emptyFile}")
86
87 ncps.succeed("cat ${narinfoPath} >&2")
88 '';
89}