From 7f8a0810c34f7c085dd50c1325c7964e961ad1c4 Mon Sep 17 00:00:00 2001 From: Christian Theune Date: Tue, 14 Jan 2025 16:46:29 +0100 Subject: [PATCH] varnish: fix #208242 overusage of `lib` --- .../services/web-servers/varnish/default.nix | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/nixos/modules/services/web-servers/varnish/default.nix b/nixos/modules/services/web-servers/varnish/default.nix index d2b035b7cc5f70..033dc631289ba5 100644 --- a/nixos/modules/services/web-servers/varnish/default.nix +++ b/nixos/modules/services/web-servers/varnish/default.nix @@ -5,65 +5,62 @@ ... }: -with lib; - let cfg = config.services.varnish; commandLine = "-f ${pkgs.writeText "default.vcl" cfg.config}" + - optionalString (cfg.extraModules != [ ]) + lib.optionalString (cfg.extraModules != [ ]) " -p vmod_path='${ - makeSearchPathOutput "lib" "lib/varnish/vmods" ([ cfg.package ] ++ cfg.extraModules) + lib.makeSearchPathOutput "lib" "lib/varnish/vmods" ([ cfg.package ] ++ cfg.extraModules) }' -r vmod_path"; in { options = { services.varnish = { - enable = mkEnableOption "Varnish Server"; + enable = lib.mkEnableOption "Varnish Server"; - enableConfigCheck = mkEnableOption "checking the config during build time" // { + enableConfigCheck = lib.mkEnableOption "checking the config during build time" // { default = true; }; - package = mkPackageOption pkgs "varnish" { }; + package = lib.mkPackageOption pkgs "varnish" { }; - http_address = mkOption { - type = types.str; + http_address = lib.mkOption { + type = lib.types.str; default = "*:6081"; description = '' HTTP listen address and port. ''; }; - config = mkOption { - type = types.lines; + config = lib.mkOption { + type = lib.types.lines; description = '' Verbatim default.vcl configuration. ''; }; - stateDir = mkOption { - type = types.path; + stateDir = lib.mkOption { + type = lib.types.path; default = "/run/varnish/${config.networking.hostName}"; - defaultText = literalExpression ''"/run/varnish/''${config.networking.hostName}"''; + defaultText = lib.literalExpression ''"/run/varnish/''${config.networking.hostName}"''; description = '' Directory holding all state for Varnish to run. Note that this should be a tmpfs in order to avoid performance issues and crashes. ''; }; - - extraModules = mkOption { - type = types.listOf types.package; + extraModules = lib.mkOption { + type = lib.types.listOf lib.types.package; default = [ ]; - example = literalExpression "[ pkgs.varnishPackages.geoip ]"; + example = lib.literalExpression "[ pkgs.varnishPackages.geoip ]"; description = '' Varnish modules (except 'std'). ''; }; - extraCommandLine = mkOption { - type = types.str; + extraCommandLine = lib.mkOption { + type = lib.types.str; default = ""; example = "-s malloc,256M"; description = '' @@ -74,17 +71,16 @@ in }; - config = mkIf cfg.enable { - + config = lib.mkIf cfg.enable { systemd.services.varnish = { description = "Varnish"; wantedBy = [ "multi-user.target" ]; after = [ "network.target" ]; - preStart = mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) '' + preStart = lib.mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) '' mkdir -p ${cfg.stateDir} chown -R varnish:varnish ${cfg.stateDir} ''; - postStop = mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) '' + postStop = lib.mkIf (!(lib.hasPrefix "/run/" cfg.stateDir)) '' rm -rf ${cfg.stateDir} ''; serviceConfig = { @@ -95,7 +91,7 @@ in RestartSec = "5s"; User = "varnish"; Group = "varnish"; - RuntimeDirectory = mkIf (lib.hasPrefix "/run/" cfg.stateDir) ( + RuntimeDirectory = lib.mkIf (lib.hasPrefix "/run/" cfg.stateDir) ( lib.removePrefix "/run/" cfg.stateDir ); AmbientCapabilities = "cap_net_bind_service"; @@ -107,7 +103,7 @@ in environment.systemPackages = [ cfg.package ]; # check .vcl syntax at compile time (e.g. before nixops deployment) - system.checks = mkIf cfg.enableConfigCheck [ + system.checks = lib.mkIf cfg.enableConfigCheck [ (pkgs.runCommand "check-varnish-syntax" { } '' ${cfg.package}/bin/varnishd -C ${commandLine} 2> $out || (cat $out; exit 1) '')