Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/modules/services/logging: Remove top-level with lib; #325936

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions nixos/modules/services/logging/SystemdJournal2Gelf.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{ config, lib, pkgs, ... }:

with lib;

let cfg = config.services.SystemdJournal2Gelf;
inherit (lib) mkOption mkPackageOption mkIf types;
in

{ options = {
Expand Down
17 changes: 15 additions & 2 deletions nixos/modules/services/logging/awstats.nix
Original file line number Diff line number Diff line change
@@ -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, ...}: {
Expand Down
5 changes: 2 additions & 3 deletions nixos/modules/services/logging/fluentd.nix
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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 = {
Expand Down
3 changes: 1 addition & 2 deletions nixos/modules/services/logging/graylog.nix
Original file line number Diff line number Diff line change
@@ -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" ''
Expand Down
5 changes: 2 additions & 3 deletions nixos/modules/services/logging/heartbeat.nix
Original file line number Diff line number Diff line change
@@ -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" ''
Expand Down Expand Up @@ -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 = ''
Expand Down
3 changes: 1 addition & 2 deletions nixos/modules/services/logging/journalbeat.nix
Original file line number Diff line number Diff line change
@@ -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" ''
Expand Down
4 changes: 3 additions & 1 deletion nixos/modules/services/logging/journaldriver.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions nixos/modules/services/logging/journalwatch.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions nixos/modules/services/logging/logcheck.nix
Original file line number Diff line number Diff line change
@@ -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; } ''
Expand Down Expand Up @@ -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}" {
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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 ];
};
}
21 changes: 10 additions & 11 deletions nixos/modules/services/logging/logrotate.nix
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
{ config, lib, pkgs, utils, ... }:

with lib;

let
inherit (lib) mkRemovedOptionModule mkOption optionalString types literalExpression attrValues foldr mkIf;
cfg = config.services.logrotate;

generateLine = n: v:
if builtins.elem n [ "files" "priority" "enable" "global" ] || v == null then null
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;
Expand All @@ -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 ''
Expand Down Expand Up @@ -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 != {}";
};
Expand Down Expand Up @@ -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;
};

Expand Down
17 changes: 13 additions & 4 deletions nixos/modules/services/logging/logstash.nix
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.";
};

Expand Down Expand Up @@ -100,7 +109,7 @@ in
type = types.lines;
default = "generator { }";
description = "Logstash input configuration.";
example = literalExpression ''
example = lib.literalExpression ''
'''
# Read from journal
pipe {
Expand Down
9 changes: 6 additions & 3 deletions nixos/modules/services/logging/promtail.nix
Original file line number Diff line number Diff line change
@@ -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" {} ''
Expand All @@ -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";


Expand All @@ -23,7 +26,7 @@ in {
};

extraFlags = mkOption {
type = listOf str;
type = types.listOf types.str;
default = [];
example = [ "--server.http-listen-port=3101" ];
description = ''
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/services/logging/rsyslogd.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{ config, lib, pkgs, ... }:

with lib;

let

inherit (lib) mkOption mkIf types;

cfg = config.services.rsyslogd;

syslogConf = pkgs.writeText "syslog.conf" ''
Expand Down
4 changes: 2 additions & 2 deletions nixos/modules/services/logging/syslog-ng.nix
Original file line number Diff line number Diff line change
@@ -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" ''
Expand Down
3 changes: 1 addition & 2 deletions nixos/modules/services/logging/syslogd.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{ config, lib, pkgs, ... }:

with lib;

let
inherit (lib) optionalString mkOption types mkIf optional;

cfg = config.services.syslogd;

Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/logging/ulogd.nix
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/logging/vector.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }:

with lib;
let cfg = config.services.vector;
inherit (lib) mkEnableOption mkPackageOption mkOption types mkIf getExe;

in
{
Expand Down