From ea7e705cd905e01bc65f2a7ccc6e700bd1bcd4e0 Mon Sep 17 00:00:00 2001 From: Christian Kauhaus Date: Thu, 4 Aug 2016 15:25:23 +0200 Subject: [PATCH] varnish: fix localstatedir for varnish* tools (#17508) The varnish tools (varnishstat, varnishlog, ...) tried to load the VSM file from a spurious var directory in the Nix store. Fix the default so the tools "just work" when also keeping services.varnish.stateDir at the default. Notes: - The tools use $localstatedir/$HOSTNAME so I've adapted the default for stateDir as well to contain hostName. - Added postStop action to remove the localstatedir. There is no point in keeping it around when varnish does not run, as it regenerates it on startup anyway. Fixes #7495 --- nixos/modules/services/web-servers/varnish/default.nix | 5 ++++- pkgs/servers/varnish/default.nix | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/web-servers/varnish/default.nix b/nixos/modules/services/web-servers/varnish/default.nix index 364f6c68faca..61df43ec2352 100644 --- a/nixos/modules/services/web-servers/varnish/default.nix +++ b/nixos/modules/services/web-servers/varnish/default.nix @@ -28,7 +28,7 @@ with lib; }; stateDir = mkOption { - default = "/var/spool/varnish"; + default = "/var/spool/varnish/${config.networking.hostName}"; description = " Directory holding all state for Varnish to run. "; @@ -46,6 +46,9 @@ with lib; mkdir -p ${cfg.stateDir} chown -R varnish:varnish ${cfg.stateDir} ''; + postStop = '' + rm -rf ${cfg.stateDir} + ''; path = [ pkgs.gcc ]; serviceConfig.ExecStart = "${pkgs.varnish}/sbin/varnishd -a ${cfg.http_address} -f ${pkgs.writeText "default.vcl" cfg.config} -n ${cfg.stateDir} -u varnish"; serviceConfig.Type = "forking"; diff --git a/pkgs/servers/varnish/default.nix b/pkgs/servers/varnish/default.nix index 358afb3dfb36..fb3331768014 100644 --- a/pkgs/servers/varnish/default.nix +++ b/pkgs/servers/varnish/default.nix @@ -13,6 +13,8 @@ stdenv.mkDerivation rec { buildInputs = [ pcre libxslt groff ncurses pkgconfig readline python pythonPackages.docutils]; + buildFlags = "localstatedir=/var/spool"; + meta = { description = "Web application accelerator also known as a caching HTTP reverse proxy"; homepage = "https://www.varnish-cache.org";