Skip to content

Commit ba79b6d

Browse files
committed
nixos/varnish: reduce overusage of lib (NixOS#208242)
1 parent 75ad720 commit ba79b6d

File tree

1 file changed

+22
-26
lines changed

1 file changed

+22
-26
lines changed

nixos/modules/services/web-servers/varnish/default.nix

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,65 +5,62 @@
55
...
66
}:
77

8-
with lib;
9-
108
let
119
cfg = config.services.varnish;
1210

1311
commandLine =
1412
"-f ${pkgs.writeText "default.vcl" cfg.config}"
1513
+
16-
optionalString (cfg.extraModules != [ ])
14+
lib.optionalString (cfg.extraModules != [ ])
1715
" -p vmod_path='${
18-
makeSearchPathOutput "lib" "lib/varnish/vmods" ([ cfg.package ] ++ cfg.extraModules)
16+
lib.makeSearchPathOutput "lib" "lib/varnish/vmods" ([ cfg.package ] ++ cfg.extraModules)
1917
}' -r vmod_path";
2018
in
2119
{
2220
options = {
2321
services.varnish = {
24-
enable = mkEnableOption "Varnish Server";
22+
enable = lib.mkEnableOption "Varnish Server";
2523

26-
enableConfigCheck = mkEnableOption "checking the config during build time" // {
24+
enableConfigCheck = lib.mkEnableOption "checking the config during build time" // {
2725
default = true;
2826
};
2927

30-
package = mkPackageOption pkgs "varnish" { };
28+
package = lib.mkPackageOption pkgs "varnish" { };
3129

32-
http_address = mkOption {
33-
type = types.str;
30+
http_address = lib.mkOption {
31+
type = lib.types.str;
3432
default = "*:6081";
3533
description = ''
3634
HTTP listen address and port.
3735
'';
3836
};
3937

40-
config = mkOption {
41-
type = types.lines;
38+
config = lib.mkOption {
39+
type = lib.types.lines;
4240
description = ''
4341
Verbatim default.vcl configuration.
4442
'';
4543
};
4644

47-
stateDir = mkOption {
48-
type = types.path;
45+
stateDir = lib.mkOption {
46+
type = lib.types.path;
4947
default = "/run/varnish/${config.networking.hostName}";
50-
defaultText = literalExpression ''"/run/varnish/''${config.networking.hostName}"'';
48+
defaultText = lib.literalExpression ''"/run/varnish/''${config.networking.hostName}"'';
5149
description = ''
5250
Directory holding all state for Varnish to run. Note that this should be a tmpfs in order to avoid performance issues and crashes.
5351
'';
5452
};
55-
56-
extraModules = mkOption {
57-
type = types.listOf types.package;
53+
extraModules = lib.mkOption {
54+
type = lib.types.listOf lib.types.package;
5855
default = [ ];
59-
example = literalExpression "[ pkgs.varnishPackages.geoip ]";
56+
example = lib.literalExpression "[ pkgs.varnishPackages.geoip ]";
6057
description = ''
6158
Varnish modules (except 'std').
6259
'';
6360
};
6461

65-
extraCommandLine = mkOption {
66-
type = types.str;
62+
extraCommandLine = lib.mkOption {
63+
type = lib.types.str;
6764
default = "";
6865
example = "-s malloc,256M";
6966
description = ''
@@ -74,17 +71,16 @@ in
7471

7572
};
7673

77-
config = mkIf cfg.enable {
78-
74+
config = lib.mkIf cfg.enable {
7975
systemd.services.varnish = {
8076
description = "Varnish";
8177
wantedBy = [ "multi-user.target" ];
8278
after = [ "network.target" ];
83-
preStart = mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) ''
79+
preStart = lib.mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) ''
8480
mkdir -p ${cfg.stateDir}
8581
chown -R varnish:varnish ${cfg.stateDir}
8682
'';
87-
postStop = mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) ''
83+
postStop = lib.mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) ''
8884
rm -rf ${cfg.stateDir}
8985
'';
9086
serviceConfig = {
@@ -95,7 +91,7 @@ in
9591
RestartSec = "5s";
9692
User = "varnish";
9793
Group = "varnish";
98-
RuntimeDirectory = mkIf (lib.hasPrefix "/run/" cfg.stateDir) (
94+
RuntimeDirectory = lib.mkIf (lib.hasPrefix "/run/" cfg.stateDir) (
9995
lib.removePrefix "/run/" cfg.stateDir
10096
);
10197
AmbientCapabilities = "cap_net_bind_service";
@@ -107,7 +103,7 @@ in
107103
environment.systemPackages = [ cfg.package ];
108104

109105
# check .vcl syntax at compile time (e.g. before nixops deployment)
110-
system.checks = mkIf cfg.enableConfigCheck [
106+
system.checks = lib.mkIf cfg.enableConfigCheck [
111107
(pkgs.runCommand "check-varnish-syntax" { } ''
112108
${cfg.package}/bin/varnishd -C ${commandLine} 2> $out || (cat $out; exit 1)
113109
'')

0 commit comments

Comments
 (0)