diff --git a/nixos/modules/services/logging/SystemdJournal2Gelf.nix b/nixos/modules/services/logging/SystemdJournal2Gelf.nix index 7c50e9e2c42f5..4e350b04f7731 100644 --- a/nixos/modules/services/logging/SystemdJournal2Gelf.nix +++ b/nixos/modules/services/logging/SystemdJournal2Gelf.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: -with lib; - let cfg = config.services.SystemdJournal2Gelf; +inherit (lib) mkOption mkPackageOption mkIf types; in { options = { diff --git a/nixos/modules/services/logging/awstats.nix b/nixos/modules/services/logging/awstats.nix index a5b0e6347b2b8..c91035f95188a 100644 --- a/nixos/modules/services/logging/awstats.nix +++ b/nixos/modules/services/logging/awstats.nix @@ -1,8 +1,21 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) + mkOption + types + literalExpression + mkRemovedOptionModule + mkRenamedOptionModule + mkEnableOption + mkIf + optionalString + filterAttrs + mapAttrs' + mapAttrsToList + nameValuePair + concatStringsSep; + cfg = config.services.awstats; package = pkgs.awstats; configOpts = {name, config, ...}: { diff --git a/nixos/modules/services/logging/fluentd.nix b/nixos/modules/services/logging/fluentd.nix index bbf905eca06b2..cc344339fd5a9 100644 --- a/nixos/modules/services/logging/fluentd.nix +++ b/nixos/modules/services/logging/fluentd.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) mkEnableOption types mkOption mkPackageOption mkIf concatStringsSep; cfg = config.services.fluentd; pluginArgs = concatStringsSep " " (map (x: "-p ${x}") cfg.plugins); @@ -37,7 +36,7 @@ in { ###### implementation config = mkIf cfg.enable { - systemd.services.fluentd = with pkgs; { + systemd.services.fluentd = { description = "Fluentd Daemon"; wantedBy = [ "multi-user.target" ]; serviceConfig = { diff --git a/nixos/modules/services/logging/graylog.nix b/nixos/modules/services/logging/graylog.nix index caeac16815f42..ef254a82636f7 100644 --- a/nixos/modules/services/logging/graylog.nix +++ b/nixos/modules/services/logging/graylog.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) mkEnableOption boolToString mkOption types concatStringsSep literalExpression versionOlder mkIf; cfg = config.services.graylog; confFile = pkgs.writeText "graylog.conf" '' diff --git a/nixos/modules/services/logging/heartbeat.nix b/nixos/modules/services/logging/heartbeat.nix index 1a264cebf6a22..a734cb7553d84 100644 --- a/nixos/modules/services/logging/heartbeat.nix +++ b/nixos/modules/services/logging/heartbeat.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) mkEnableOption mkPackageOption mkOption types mkIf; cfg = config.services.heartbeat; heartbeatYml = pkgs.writeText "heartbeat.yml" '' @@ -62,7 +61,7 @@ in "d '${cfg.stateDir}' - nobody nogroup - -" ]; - systemd.services.heartbeat = with pkgs; { + systemd.services.heartbeat = { description = "heartbeat log shipper"; wantedBy = [ "multi-user.target" ]; preStart = '' diff --git a/nixos/modules/services/logging/journalbeat.nix b/nixos/modules/services/logging/journalbeat.nix index e7d726ab1f612..3eaf718a8c27b 100644 --- a/nixos/modules/services/logging/journalbeat.nix +++ b/nixos/modules/services/logging/journalbeat.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) mkEnableOption mkOption mkPackageOption types mkIf hasPrefix; cfg = config.services.journalbeat; journalbeatYml = pkgs.writeText "journalbeat.yml" '' diff --git a/nixos/modules/services/logging/journaldriver.nix b/nixos/modules/services/logging/journaldriver.nix index bb82f8cf30ccd..477e49126e04d 100644 --- a/nixos/modules/services/logging/journaldriver.nix +++ b/nixos/modules/services/logging/journaldriver.nix @@ -11,7 +11,9 @@ { config, lib, pkgs, ...}: -with lib; let cfg = config.services.journaldriver; +let + inherit (lib) mkOption types mkIf; + cfg = config.services.journaldriver; in { options.services.journaldriver = { enable = mkOption { diff --git a/nixos/modules/services/logging/journalwatch.nix b/nixos/modules/services/logging/journalwatch.nix index 48fd992ffb65a..3b0084f84dc96 100644 --- a/nixos/modules/services/logging/journalwatch.nix +++ b/nixos/modules/services/logging/journalwatch.nix @@ -1,7 +1,6 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) optionalString concatStringsSep mkOption mkPackageOption mkIf types literalExpression; cfg = config.services.journalwatch; user = "journalwatch"; # for journal access @@ -242,7 +241,7 @@ in { # requires a relative directory name to create beneath /var/lib StateDirectory = user; StateDirectoryMode = "0750"; - ExecStart = "${getExe cfg.package} mail"; + ExecStart = "${lib.getExe cfg.package} mail"; # lowest CPU and IO priority, but both still in best-effort class to prevent starvation Nice=19; IOSchedulingPriority=7; diff --git a/nixos/modules/services/logging/logcheck.nix b/nixos/modules/services/logging/logcheck.nix index bda7f9a607e14..5f07999a326f4 100644 --- a/nixos/modules/services/logging/logcheck.nix +++ b/nixos/modules/services/logging/logcheck.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) getAttrFromPath types mkOption mapAttrsToList optionalAttrs mkIf; cfg = config.services.logcheck; defaultRules = pkgs.runCommand "logcheck-default-rules" { preferLocalBuild = true; } '' @@ -43,7 +42,7 @@ let }; writeIgnoreCronRule = name: {level, user, regex, cmdline, ...}: - let escapeRegex = escape (stringToCharacters "\\[]{}()^$?*+|."); + let escapeRegex = lib.escape (lib.stringToCharacters "\\[]{}()^$?*+|."); cmdline_ = builtins.unsafeDiscardStringContext cmdline; re = if regex != "" then regex else if cmdline_ == "" then ".*" else escapeRegex cmdline_; in writeIgnoreRule "cron-${name}" { @@ -109,7 +108,7 @@ in { options = { services.logcheck = { - enable = mkEnableOption "logcheck cron job, to mail anomalies in the system logfiles to the administrator"; + enable = lib.mkEnableOption "logcheck cron job, to mail anomalies in the system logfiles to the administrator"; user = mkOption { default = "logcheck"; @@ -236,7 +235,7 @@ in mkCron = name: {user, cmdline, timeArgs, ...}: '' ${timeArgs} ${user} ${cmdline} ''; - in mapAttrsToList mkCron (filterAttrs withTime cfg.ignoreCron) + in mapAttrsToList mkCron (lib.filterAttrs withTime cfg.ignoreCron) ++ [ cronJob ]; }; } diff --git a/nixos/modules/services/logging/logrotate.nix b/nixos/modules/services/logging/logrotate.nix index 9344277fc1e02..b5d421d173f8e 100644 --- a/nixos/modules/services/logging/logrotate.nix +++ b/nixos/modules/services/logging/logrotate.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, utils, ... }: -with lib; - let + inherit (lib) mkRemovedOptionModule mkOption optionalString types literalExpression attrValues foldr mkIf; cfg = config.services.logrotate; generateLine = n: v: @@ -10,24 +9,24 @@ let else if builtins.elem n [ "frequency" ] then "${v}\n" else if builtins.elem n [ "firstaction" "lastaction" "prerotate" "postrotate" "preremove" ] then "${n}\n ${v}\n endscript\n" - else if isInt v then "${n} ${toString v}\n" + else if lib.isInt v then "${n} ${toString v}\n" else if v == true then "${n}\n" else if v == false then "no${n}\n" else "${n} ${v}\n"; - generateSection = indent: settings: concatStringsSep (fixedWidthString indent " " "") ( - filter (x: x != null) (mapAttrsToList generateLine settings) + generateSection = indent: settings: lib.concatStringsSep (lib.fixedWidthString indent " " "") ( + lib.filter (x: x != null) (lib.mapAttrsToList generateLine settings) ); # generateSection includes a final newline hence weird closing brace mkConf = settings: if settings.global or false then generateSection 0 settings else '' - ${concatMapStringsSep "\n" (files: ''"${files}"'') (toList settings.files)} { + ${lib.concatMapStringsSep "\n" (files: ''"${files}"'') (lib.toList settings.files)} { ${generateSection 2 settings}} ''; - settings = sortProperties (attrValues (filterAttrs (_: settings: settings.enable) ( - foldAttrs recursiveUpdate { } [ + settings = lib.sortProperties (attrValues (lib.filterAttrs (_: settings: settings.enable) ( + lib.foldAttrs lib.recursiveUpdate { } [ { header = { enable = true; @@ -43,7 +42,7 @@ let ))); configFile = pkgs.writeTextFile { name = "logrotate.conf"; - text = concatStringsSep "\n" ( + text = lib.concatStringsSep "\n" ( map mkConf settings ); checkPhase = optionalString cfg.checkConfig '' @@ -95,7 +94,7 @@ in options = { services.logrotate = { - enable = mkEnableOption "the logrotate systemd service" // { + enable = lib.mkEnableOption "the logrotate systemd service" // { default = foldr (n: a: a || n.enable) false (attrValues cfg.settings); defaultText = literalExpression "cfg.settings != {}"; }; @@ -142,7 +141,7 @@ in freeformType = with types; attrsOf (nullOr (oneOf [ int bool str ])); options = { - enable = mkEnableOption "setting individual kill switch" // { + enable = lib.mkEnableOption "setting individual kill switch" // { default = true; }; diff --git a/nixos/modules/services/logging/logstash.nix b/nixos/modules/services/logging/logstash.nix index 53e2e91d6212e..3caa6db1d8d1a 100644 --- a/nixos/modules/services/logging/logstash.nix +++ b/nixos/modules/services/logging/logstash.nix @@ -1,8 +1,17 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) + concatMapStringsSep + concatStringsSep + filter + mkIf + mkOption + mkPackageOption + mkRemovedOptionModule + mkRenamedOptionModule + stringLength + types; cfg = config.services.logstash; ops = lib.optionalString; verbosityFlag = "--log.level " + cfg.logLevel; @@ -59,7 +68,7 @@ in plugins = mkOption { type = types.listOf types.path; default = [ ]; - example = literalExpression "[ pkgs.logstash-contrib ]"; + example = lib.literalExpression "[ pkgs.logstash-contrib ]"; description = "The paths to find other logstash plugins in."; }; @@ -100,7 +109,7 @@ in type = types.lines; default = "generator { }"; description = "Logstash input configuration."; - example = literalExpression '' + example = lib.literalExpression '' ''' # Read from journal pipe { diff --git a/nixos/modules/services/logging/promtail.nix b/nixos/modules/services/logging/promtail.nix index 9eccd34cef234..9c0dc5e2f8191 100644 --- a/nixos/modules/services/logging/promtail.nix +++ b/nixos/modules/services/logging/promtail.nix @@ -1,5 +1,8 @@ -{ config, lib, pkgs, ... }: with lib; +{ config, lib, pkgs, ... }: let + + inherit (lib) types mkOption mkEnableOption mkIf mkDefault escapeShellArgs optionalAttrs; + cfg = config.services.promtail; prettyJSON = conf: pkgs.runCommandLocal "promtail-config.json" {} '' @@ -11,7 +14,7 @@ let allowPositionsFile = !lib.hasPrefix "/var/cache/promtail" positionsFile; positionsFile = cfg.configuration.positions.filename; in { - options.services.promtail = with types; { + options.services.promtail = { enable = mkEnableOption "the Promtail ingresser"; @@ -23,7 +26,7 @@ in { }; extraFlags = mkOption { - type = listOf str; + type = types.listOf types.str; default = []; example = [ "--server.http-listen-port=3101" ]; description = '' diff --git a/nixos/modules/services/logging/rsyslogd.nix b/nixos/modules/services/logging/rsyslogd.nix index 25b6eec5056ca..0b85b7178dbba 100644 --- a/nixos/modules/services/logging/rsyslogd.nix +++ b/nixos/modules/services/logging/rsyslogd.nix @@ -1,9 +1,9 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) mkOption mkIf types; + cfg = config.services.rsyslogd; syslogConf = pkgs.writeText "syslog.conf" '' diff --git a/nixos/modules/services/logging/syslog-ng.nix b/nixos/modules/services/logging/syslog-ng.nix index 14e18d3f0eefd..b54d6ec7a9340 100644 --- a/nixos/modules/services/logging/syslog-ng.nix +++ b/nixos/modules/services/logging/syslog-ng.nix @@ -1,9 +1,9 @@ { config, pkgs, lib, ... }: -with lib; - let + inherit (lib) concatStringsSep mkRemovedOptionModule mkOption types mkPackageOption mkIf; + cfg = config.services.syslog-ng; syslogngConfig = pkgs.writeText "syslog-ng.conf" '' diff --git a/nixos/modules/services/logging/syslogd.nix b/nixos/modules/services/logging/syslogd.nix index 8674fad69658c..8078dc625a82f 100644 --- a/nixos/modules/services/logging/syslogd.nix +++ b/nixos/modules/services/logging/syslogd.nix @@ -1,8 +1,7 @@ { config, lib, pkgs, ... }: -with lib; - let + inherit (lib) optionalString mkOption types mkIf optional; cfg = config.services.syslogd; diff --git a/nixos/modules/services/logging/ulogd.nix b/nixos/modules/services/logging/ulogd.nix index 5bd51ef88fe53..1c3b851fc1b74 100644 --- a/nixos/modules/services/logging/ulogd.nix +++ b/nixos/modules/services/logging/ulogd.nix @@ -1,10 +1,10 @@ { config, lib, pkgs, ... }: -with lib; let cfg = config.services.ulogd; settingsFormat = pkgs.formats.ini { listsAsDuplicateKeys = true; }; settingsFile = settingsFormat.generate "ulogd.conf" cfg.settings; + inherit (lib) mkEnableOption mkOption mkIf types; in { options = { services.ulogd = { diff --git a/nixos/modules/services/logging/vector.nix b/nixos/modules/services/logging/vector.nix index 129a38b1d20f0..c1b8621ec0d5c 100644 --- a/nixos/modules/services/logging/vector.nix +++ b/nixos/modules/services/logging/vector.nix @@ -1,7 +1,7 @@ { config, lib, pkgs, ... }: -with lib; let cfg = config.services.vector; +inherit (lib) mkEnableOption mkPackageOption mkOption types mkIf getExe; in {