1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-25 03:17:13 +00:00
nixpkgs/nixos/modules/services/web-servers/varnish/default.nix
Christian Kauhaus ea7e705cd9 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
2016-08-04 15:25:23 +02:00

67 lines
1.5 KiB
Nix

{ config, lib, pkgs, ...}:
let
cfg = config.services.varnish;
in
with lib;
{
options = {
services.varnish = {
enable = mkOption {
default = false;
description = "
Enable the Varnish Server.
";
};
http_address = mkOption {
default = "*:6081";
description = "
HTTP listen address and port.
";
};
config = mkOption {
description = "
Verbatim default.vcl configuration.
";
};
stateDir = mkOption {
default = "/var/spool/varnish/${config.networking.hostName}";
description = "
Directory holding all state for Varnish to run.
";
};
};
};
config = mkIf cfg.enable {
systemd.services.varnish = {
description = "Varnish";
wantedBy = [ "multi-user.target" ];
preStart = ''
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";
};
environment.systemPackages = [ pkgs.varnish ];
users.extraUsers.varnish = {
group = "varnish";
uid = config.ids.uids.varnish;
};
users.extraGroups.varnish.gid = config.ids.uids.varnish;
};
}