Skip to content

Commit

Permalink
refactor(systemd-log): move systemd log config
Browse files Browse the repository at this point in the history
Unify systemd log level configuration.

Signed-off-by: Manuel Bluhm <[email protected]>
  • Loading branch information
mbssrc authored and brianmcgillion committed Feb 1, 2025
1 parent ef396c1 commit 47bc804
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 30 deletions.
25 changes: 18 additions & 7 deletions modules/common/systemd/base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,22 @@ in
default = false;
};

verboseLogs = mkOption {
description = "Increase systemd log verbosity.";
type = types.bool;
default = false;
logLevel = mkOption {
description = ''
Systemd log verbosity. Must be one of 'debug', 'info', 'notice', 'warning', 'err',
'crit', 'alert', 'emerg'. Defaults to 'info'.
'';
type = types.enum [
"debug"
"info"
"notice"
"warning"
"err"
"crit"
"alert"
"emerg"
];
default = "info";
};
};

Expand All @@ -358,9 +370,8 @@ in
# Misc. configurations
enableEmergencyMode = cfg.withDebug;
coredump.enable = cfg.withDebug || cfg.withMachines;
managerEnvironment = optionalAttrs cfg.verboseLogs {
SYSTEMD_LOG_LEVEL = "debug";
};
managerEnvironment.SYSTEMD_LOG_LEVEL = cfg.logLevel;
globalEnvironment.SYSTEMD_LOG_LEVEL = cfg.logLevel;

# Service startup optimization
services.systemd-networkd-wait-online.enable = mkForce false;
Expand Down
5 changes: 1 addition & 4 deletions modules/common/systemd/boot.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ in

config = mkIf cfg.enable {
boot.initrd = {
verbose = cfgBase.verboseLogs;
services.lvm.enable = true;
systemd = {
enable = true;
Expand All @@ -79,9 +78,7 @@ in
pkgs.lvm2
pkgs.util-linux
];
managerEnvironment = optionalAttrs cfgBase.verboseLogs {
SYSTEMD_LOG_LEVEL = "debug";
};
managerEnvironment.SYSTEMD_LOG_LEVEL = cfgBase.logLevel;
};
};
};
Expand Down
25 changes: 6 additions & 19 deletions modules/common/systemd/harden.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,19 @@
let
# Ghaf systemd config
cfg = config.ghaf.systemd;
inherit (lib) mkIf mkOption types;
in
{
options.ghaf.systemd = {
withHardenedConfigs = lib.mkOption {
withHardenedConfigs = mkOption {
description = "Enable common hardened configs.";
type = lib.types.bool;
type = types.bool;
default = false;
};

logLevel = lib.mkOption {
description = ''
Log Level for systemd services.
Available options: "emerg", "alert", "crit", "err", "warning", "info", "debug"
'';
type = lib.types.str;
default = "info";
};
};

config = {
systemd = lib.mkMerge [
# Apply hardened systemd service configurations
(lib.mkIf cfg.withHardenedConfigs (import ./hardened-configs))

# Set systemd log level
{ services."_global_".environment.SYSTEMD_LOG_LEVEL = cfg.logLevel; }
];
config = mkIf cfg.withHardenedConfigs {
# Apply hardened systemd service configurations
systemd = import ./hardened-configs;
};
}

0 comments on commit 47bc804

Please sign in to comment.