2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ...}:
|
2013-05-12 19:32:25 +01:00
|
|
|
let
|
|
|
|
cfg = config.services.varnish;
|
2013-10-03 23:24:59 +01:00
|
|
|
|
2013-05-12 19:32:25 +01:00
|
|
|
in
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2013-05-12 19:32:25 +01:00
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.varnish = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "
|
|
|
|
Enable the Varnish Server.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2013-10-03 23:24:59 +01:00
|
|
|
http_address = mkOption {
|
|
|
|
default = "*:6081";
|
|
|
|
description = "
|
|
|
|
HTTP listen address and port.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
2013-05-12 19:32:25 +01:00
|
|
|
config = mkOption {
|
|
|
|
description = "
|
|
|
|
Verbatim default.vcl configuration.
|
|
|
|
";
|
|
|
|
};
|
|
|
|
|
|
|
|
stateDir = mkOption {
|
2016-08-04 14:25:23 +01:00
|
|
|
default = "/var/spool/varnish/${config.networking.hostName}";
|
2013-05-12 19:32:25 +01:00
|
|
|
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}
|
|
|
|
'';
|
2016-08-04 14:25:23 +01:00
|
|
|
postStop = ''
|
|
|
|
rm -rf ${cfg.stateDir}
|
|
|
|
'';
|
2013-05-12 19:32:25 +01:00
|
|
|
path = [ pkgs.gcc ];
|
2013-10-03 23:24:59 +01:00
|
|
|
serviceConfig.ExecStart = "${pkgs.varnish}/sbin/varnishd -a ${cfg.http_address} -f ${pkgs.writeText "default.vcl" cfg.config} -n ${cfg.stateDir} -u varnish";
|
2013-05-12 19:32:25 +01:00
|
|
|
serviceConfig.Type = "forking";
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.varnish ];
|
|
|
|
|
|
|
|
users.extraUsers.varnish = {
|
|
|
|
group = "varnish";
|
2013-08-23 10:33:24 +01:00
|
|
|
uid = config.ids.uids.varnish;
|
2013-05-12 19:32:25 +01:00
|
|
|
};
|
|
|
|
|
2013-08-23 10:33:24 +01:00
|
|
|
users.extraGroups.varnish.gid = config.ids.uids.varnish;
|
2013-05-12 19:32:25 +01:00
|
|
|
};
|
|
|
|
}
|