From 0f930a00f8773ffff96db6ecbc2e9664947ace95 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Sun, 12 May 2013 20:32:25 +0200 Subject: [PATCH] Add varnish module --- .../services/web-servers/varnish/default.nix | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 modules/services/web-servers/varnish/default.nix diff --git a/modules/services/web-servers/varnish/default.nix b/modules/services/web-servers/varnish/default.nix new file mode 100644 index 000000000000..66ec978bac8e --- /dev/null +++ b/modules/services/web-servers/varnish/default.nix @@ -0,0 +1,54 @@ +{ config, pkgs, ...}: +let + cfg = config.services.varnish; +in +with pkgs.lib; +{ + options = { + services.varnish = { + enable = mkOption { + default = false; + description = " + Enable the Varnish Server. + "; + }; + + config = mkOption { + description = " + Verbatim default.vcl configuration. + "; + }; + + stateDir = mkOption { + default = "/var/spool/varnish"; + 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} + ''; + path = [ pkgs.gcc ]; + serviceConfig.ExecStart = "${pkgs.varnish}/sbin/varnishd -f ${pkgs.writeText "default.vcl" cfg.config} -n ${cfg.stateDir} -u varnish"; + serviceConfig.Type = "forking"; + }; + + environment.systemPackages = [ pkgs.varnish ]; + + users.extraUsers.varnish = { + group = "varnish"; + }; + + users.extraGroups.varnish = {}; + }; +}