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
|
{ config, package, ... }:
let
pkgs = config.node.pkgs;
testPath = pkgs.hello;
# Same stateDir logic as in nixos/modules/services/web-servers/varnish/default.nix
stateDir = "/var/run/varnishd";
in
{
name = "varnish-${package.version}";
meta = {
maintainers = [ ];
};
nodes = {
varnish =
{
config,
pkgs,
lib,
...
}:
{
services.nix-serve = {
enable = true;
};
nix.enable = true; # disabled by default. See all-tests.nix / tag(no-nix-by-default)
services.varnish = {
inherit package;
enable = true;
http_address = "0.0.0.0:81";
listen = [
{
address = "0.0.0.0";
port = 80;
proto = "HTTP";
}
{
name = "proxyport";
address = "0.0.0.0";
port = 8080;
proto = "PROXY";
}
{
address = "/var/run/varnishd/client.http.sock";
user = "varnish";
group = "varnish";
mode = "660";
}
{ 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.varnish.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/varnishd/client.http.sock,HTTP,user=varnish,group=varnish,mode=660 "
" -a 0.0.0.0:81 "
" -a @asdf,HTTP "
];
};
client =
{ lib, ... }:
{
nix.settings = {
require-sigs = false;
substituters = lib.mkForce [ "http://varnish" ];
};
nix.enable = true; # disabled by default. See all-tests.nix / tag(no-nix-by-default)
};
};
testScript = ''
start_all()
varnish.wait_for_open_port(80)
client.wait_until_succeeds("curl -f http://varnish/nix-cache-info");
client.wait_until_succeeds("nix-store -r ${testPath}")
client.succeed("${testPath}/bin/hello")
output = varnish.succeed("varnishadm status")
print(output)
assert "Child in state running" in output, "Unexpected varnishadm response"
'';
}
|