1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
{
config,
package,
lib,
...
}:
let
pkgs = config.node.pkgs;
testPath = pkgs.hello;
in
{
name = "vinyl";
meta = {
maintainers = [
lib.maintainers.leona
lib.maintainers.osnyx
];
};
nodes = {
vinyl =
{
config,
pkgs,
lib,
...
}:
{
services.nix-serve = {
enable = true;
};
nix.enable = true; # disabled by default. See all-tests.nix / tag(no-nix-by-default)
services.vinyl-cache = {
inherit package;
enable = true;
enableFileLogging = true;
listen = [
{
address = "0.0.0.0";
port = 80;
proto = "HTTP";
}
{
name = "proxyport";
address = "0.0.0.0";
port = 8080;
proto = "PROXY";
}
{
address = "/var/run/vinyld/client.http.sock";
user = "vinyl-cache";
group = "vinyl-cache";
mode = "660";
}
]
++ lib.optionals (lib.versionAtLeast package.version "7.3") [
# Support added in 7.3.0
{ address = "@asdf"; }
];
config = ''
vcl 4.1;
backend nix-serve {
.host = "127.0.0.1";
.port = "${toString config.services.nix-serve.port}";
}
'';
};
networking.firewall.allowedTCPPorts = [ 80 ];
system.extraDependencies = [ testPath ];
assertions =
let
cmdline = config.systemd.services.vinyl-cache.serviceConfig.ExecStart;
in
map
(pattern: {
assertion = lib.hasInfix pattern cmdline;
message = "Address argument `${pattern}` missing in commandline `${cmdline}`.";
})
(
[
" -a 0.0.0.0:80,HTTP "
" -a proxyport=0.0.0.0:8080,PROXY "
" -a /var/run/vinyld/client.http.sock,HTTP,user=vinyl-cache,group=vinyl-cache,mode=660 "
]
++ lib.optionals (lib.versionAtLeast package.version "7.3") [
" -a @asdf,HTTP "
]
);
};
client =
{ lib, ... }:
{
nix.settings = {
require-sigs = false;
substituters = lib.mkForce [ "http://vinyl" ];
};
nix.enable = true; # disabled by default. See all-tests.nix / tag(no-nix-by-default)
};
};
testScript = ''
from pathlib import Path
import os
start_all()
vinyl.wait_for_open_port(80)
vinyl.wait_for_unit("vinylncsa")
client.wait_until_succeeds("curl -f http://vinyl/nix-cache-info");
client.wait_until_succeeds("nix-store -r ${testPath}")
client.succeed("${testPath}/bin/hello")
output = vinyl.succeed("vinyladm status")
print(output)
assert "Child in state running" in output, "Unexpected vinyladm response"
vinyl.copy_from_machine("/var/log/vinyl-cache/vinyl-cache.log")
out_dir = os.environ.get("out", os.getcwd())
vinyl_log = (Path(out_dir) / "vinyl-cache.log").read_text()
assert "http://vinyl/nix-cache-info" in vinyl_log
'';
}
|