diff --git a/nixos/tests/varnish.nix b/nixos/tests/varnish.nix index 10946fcdff65..e90420d1334e 100644 --- a/nixos/tests/varnish.nix +++ b/nixos/tests/varnish.nix @@ -1,6 +1,14 @@ { pkgs, package, ... }: let testPath = pkgs.hello; + + # Same stateDir logic as in nixos/modules/services/web-servers/varnish/default.nix + stateDir = + hostName: + if (pkgs.lib.versionOlder package.version "7") then + "/var/run/varnish/${hostName}" + else + "/var/run/varnishd"; in { name = "varnish"; @@ -37,13 +45,16 @@ in port = 8080; proto = "PROXY"; } - { address = "@asdf"; } { - address = "/run/varnishd/client.http.sock"; + address = "${stateDir config.networking.hostName}/client.http.sock"; user = "varnish"; group = "varnish"; mode = "660"; } + ] + ++ lib.optionals (lib.versionAtLeast package.version "7.3") [ + # Support added in 7.3.0 + { address = "@asdf"; } ]; config = '' vcl 4.1; @@ -59,24 +70,25 @@ in 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}`."; + }) ( - pattern: - let - cmdline = config.systemd.services.varnish.serviceConfig.ExecStart; - in - { - 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 @asdf,HTTP " - " -a /run/varnishd/client.http.sock,HTTP,user=varnish,group=varnish,mode=660 " - " -a 0.0.0.0:81 " - ]; + [ + " -a 0.0.0.0:80,HTTP " + " -a proxyport=0.0.0.0:8080,PROXY " + " -a ${stateDir config.networking.hostName}/client.http.sock,HTTP,user=varnish,group=varnish,mode=660 " + " -a 0.0.0.0:81 " + ] + ++ lib.optionals (lib.versionAtLeast package.version "7.3") [ + " -a @asdf,HTTP " + ] + ); }; client =