···
cfg = config.services.varnish;
"-f ${pkgs.writeText "default.vcl" cfg.config}"
16
-
optionalString (cfg.extraModules != [ ])
14
+
lib.optionalString (cfg.extraModules != [ ])
18
-
makeSearchPathOutput "lib" "lib/varnish/vmods" ([ cfg.package ] ++ cfg.extraModules)
16
+
lib.makeSearchPathOutput "lib" "lib/varnish/vmods" ([ cfg.package ] ++ cfg.extraModules)
24
-
enable = mkEnableOption "Varnish Server";
22
+
enable = lib.mkEnableOption "Varnish Server";
26
-
enableConfigCheck = mkEnableOption "checking the config during build time" // {
24
+
enableConfigCheck = lib.mkEnableOption "checking the config during build time" // {
30
-
package = mkPackageOption pkgs "varnish" { };
28
+
package = lib.mkPackageOption pkgs "varnish" { };
32
-
http_address = mkOption {
30
+
http_address = lib.mkOption {
31
+
type = lib.types.str;
HTTP listen address and port.
38
+
config = lib.mkOption {
39
+
type = lib.types.lines;
Verbatim default.vcl configuration.
47
-
stateDir = mkOption {
45
+
stateDir = lib.mkOption {
46
+
type = lib.types.path;
default = "/run/varnish/${config.networking.hostName}";
50
-
defaultText = literalExpression ''"/run/varnish/''${config.networking.hostName}"'';
48
+
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.
56
-
extraModules = mkOption {
57
-
type = types.listOf types.package;
53
+
extraModules = lib.mkOption {
54
+
type = lib.types.listOf lib.types.package;
59
-
example = literalExpression "[ pkgs.varnishPackages.geoip ]";
56
+
example = lib.literalExpression "[ pkgs.varnishPackages.geoip ]";
Varnish modules (except 'std').
65
-
extraCommandLine = mkOption {
62
+
extraCommandLine = lib.mkOption {
63
+
type = lib.types.str;
example = "-s malloc,256M";
···
77
-
config = mkIf cfg.enable {
74
+
config = lib.mkIf cfg.enable {
systemd.services.varnish = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
83
-
preStart = mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) ''
79
+
preStart = lib.mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) ''
chown -R varnish:varnish ${cfg.stateDir}
87
-
postStop = mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) ''
83
+
postStop = lib.mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) ''
···
98
-
RuntimeDirectory = mkIf (lib.hasPrefix "/run/" cfg.stateDir) (
94
+
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)
110
-
system.checks = mkIf cfg.enableConfigCheck [
106
+
system.checks = lib.mkIf cfg.enableConfigCheck [
(pkgs.runCommand "check-varnish-syntax" { } ''
${cfg.package}/bin/varnishd -C ${commandLine} 2> $out || (cat $out; exit 1)