···
cfg = config.services.varnish;
"-f ${pkgs.writeText "default.vcl" cfg.config}"
+
lib.optionalString (cfg.extraModules != [ ])
+
lib.makeSearchPathOutput "lib" "lib/varnish/vmods" ([ cfg.package ] ++ cfg.extraModules)
+
enable = lib.mkEnableOption "Varnish Server";
+
enableConfigCheck = lib.mkEnableOption "checking the config during build time" // {
+
package = lib.mkPackageOption pkgs "varnish" { };
+
http_address = lib.mkOption {
HTTP listen address and port.
+
config = lib.mkOption {
+
type = lib.types.lines;
Verbatim default.vcl configuration.
+
stateDir = lib.mkOption {
default = "/run/varnish/${config.networking.hostName}";
+
defaultText = lib.literalExpression ''"/run/varnish/''${config.networking.hostName}"'';
Directory holding all state for Varnish to run. Note that this should be a tmpfs in order to avoid performance issues and crashes.
+
extraModules = lib.mkOption {
+
type = lib.types.listOf lib.types.package;
+
example = lib.literalExpression "[ pkgs.varnishPackages.geoip ]";
Varnish modules (except 'std').
+
extraCommandLine = lib.mkOption {
example = "-s malloc,256M";
···
+
config = lib.mkIf cfg.enable {
systemd.services.varnish = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
+
preStart = lib.mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) ''
chown -R varnish:varnish ${cfg.stateDir}
+
postStop = lib.mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) ''
···
+
RuntimeDirectory = lib.mkIf (lib.hasPrefix "/run/" cfg.stateDir) (
lib.removePrefix "/run/" cfg.stateDir
AmbientCapabilities = "cap_net_bind_service";
···
environment.systemPackages = [ cfg.package ];
# check .vcl syntax at compile time (e.g. before nixops deployment)
+
system.checks = lib.mkIf cfg.enableConfigCheck [
(pkgs.runCommand "check-varnish-syntax" { } ''
${cfg.package}/bin/varnishd -C ${commandLine} 2> $out || (cat $out; exit 1)