|
5 | 5 | ... |
6 | 6 | }: |
7 | 7 |
|
8 | | -with lib; |
9 | | - |
10 | 8 | let |
11 | 9 | cfg = config.services.varnish; |
12 | 10 |
|
13 | 11 | commandLine = |
14 | 12 | "-f ${pkgs.writeText "default.vcl" cfg.config}" |
15 | 13 | + |
16 | | - optionalString (cfg.extraModules != [ ]) |
| 14 | + lib.optionalString (cfg.extraModules != [ ]) |
17 | 15 | " -p vmod_path='${ |
18 | | - makeSearchPathOutput "lib" "lib/varnish/vmods" ([ cfg.package ] ++ cfg.extraModules) |
| 16 | + lib.makeSearchPathOutput "lib" "lib/varnish/vmods" ([ cfg.package ] ++ cfg.extraModules) |
19 | 17 | }' -r vmod_path"; |
20 | 18 | in |
21 | 19 | { |
22 | 20 | options = { |
23 | 21 | services.varnish = { |
24 | | - enable = mkEnableOption "Varnish Server"; |
| 22 | + enable = lib.mkEnableOption "Varnish Server"; |
25 | 23 |
|
26 | | - enableConfigCheck = mkEnableOption "checking the config during build time" // { |
| 24 | + enableConfigCheck = lib.mkEnableOption "checking the config during build time" // { |
27 | 25 | default = true; |
28 | 26 | }; |
29 | 27 |
|
30 | | - package = mkPackageOption pkgs "varnish" { }; |
| 28 | + package = lib.mkPackageOption pkgs "varnish" { }; |
31 | 29 |
|
32 | | - http_address = mkOption { |
33 | | - type = types.str; |
| 30 | + http_address = lib.mkOption { |
| 31 | + type = lib.types.str; |
34 | 32 | default = "*:6081"; |
35 | 33 | description = '' |
36 | 34 | HTTP listen address and port. |
37 | 35 | ''; |
38 | 36 | }; |
39 | 37 |
|
40 | | - config = mkOption { |
41 | | - type = types.lines; |
| 38 | + config = lib.mkOption { |
| 39 | + type = lib.types.lines; |
42 | 40 | description = '' |
43 | 41 | Verbatim default.vcl configuration. |
44 | 42 | ''; |
45 | 43 | }; |
46 | 44 |
|
47 | | - stateDir = mkOption { |
48 | | - type = types.path; |
| 45 | + stateDir = lib.mkOption { |
| 46 | + type = lib.types.path; |
49 | 47 | default = "/run/varnish/${config.networking.hostName}"; |
50 | | - defaultText = literalExpression ''"/run/varnish/''${config.networking.hostName}"''; |
| 48 | + defaultText = lib.literalExpression ''"/run/varnish/''${config.networking.hostName}"''; |
51 | 49 | description = '' |
52 | 50 | Directory holding all state for Varnish to run. Note that this should be a tmpfs in order to avoid performance issues and crashes. |
53 | 51 | ''; |
54 | 52 | }; |
55 | | - |
56 | | - extraModules = mkOption { |
57 | | - type = types.listOf types.package; |
| 53 | + extraModules = lib.mkOption { |
| 54 | + type = lib.types.listOf lib.types.package; |
58 | 55 | default = [ ]; |
59 | | - example = literalExpression "[ pkgs.varnishPackages.geoip ]"; |
| 56 | + example = lib.literalExpression "[ pkgs.varnishPackages.geoip ]"; |
60 | 57 | description = '' |
61 | 58 | Varnish modules (except 'std'). |
62 | 59 | ''; |
63 | 60 | }; |
64 | 61 |
|
65 | | - extraCommandLine = mkOption { |
66 | | - type = types.str; |
| 62 | + extraCommandLine = lib.mkOption { |
| 63 | + type = lib.types.str; |
67 | 64 | default = ""; |
68 | 65 | example = "-s malloc,256M"; |
69 | 66 | description = '' |
|
74 | 71 |
|
75 | 72 | }; |
76 | 73 |
|
77 | | - config = mkIf cfg.enable { |
78 | | - |
| 74 | + config = lib.mkIf cfg.enable { |
79 | 75 | systemd.services.varnish = { |
80 | 76 | description = "Varnish"; |
81 | 77 | wantedBy = [ "multi-user.target" ]; |
82 | 78 | after = [ "network.target" ]; |
83 | | - preStart = mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) '' |
| 79 | + preStart = lib.mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) '' |
84 | 80 | mkdir -p ${cfg.stateDir} |
85 | 81 | chown -R varnish:varnish ${cfg.stateDir} |
86 | 82 | ''; |
87 | | - postStop = mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) '' |
| 83 | + postStop = lib.mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) '' |
88 | 84 | rm -rf ${cfg.stateDir} |
89 | 85 | ''; |
90 | 86 | serviceConfig = { |
|
95 | 91 | RestartSec = "5s"; |
96 | 92 | User = "varnish"; |
97 | 93 | Group = "varnish"; |
98 | | - RuntimeDirectory = mkIf (lib.hasPrefix "/run/" cfg.stateDir) ( |
| 94 | + RuntimeDirectory = lib.mkIf (lib.hasPrefix "/run/" cfg.stateDir) ( |
99 | 95 | lib.removePrefix "/run/" cfg.stateDir |
100 | 96 | ); |
101 | 97 | AmbientCapabilities = "cap_net_bind_service"; |
|
107 | 103 | environment.systemPackages = [ cfg.package ]; |
108 | 104 |
|
109 | 105 | # check .vcl syntax at compile time (e.g. before nixops deployment) |
110 | | - system.checks = mkIf cfg.enableConfigCheck [ |
| 106 | + system.checks = lib.mkIf cfg.enableConfigCheck [ |
111 | 107 | (pkgs.runCommand "check-varnish-syntax" { } '' |
112 | 108 | ${cfg.package}/bin/varnishd -C ${commandLine} 2> $out || (cat $out; exit 1) |
113 | 109 | '') |
|
0 commit comments