From 7fb2f407c01b017737eafc26b065d7f56434a992 Mon Sep 17 00:00:00 2001 From: Moritz Sanft <58110325+msanft@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:08:35 +0100 Subject: [PATCH] nixos/getty: only include if config.console.enable This makes it so that the getty units are only included if `config.console.enable` is set to `true`. Previously, they would be included, but disabled in that case, which is unnecessary. --- nixos/modules/config/console.nix | 14 ++++---------- nixos/modules/services/ttys/getty.nix | 11 ++++++++++- nixos/modules/system/boot/systemd.nix | 9 --------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/nixos/modules/config/console.nix b/nixos/modules/config/console.nix index 9beb7dc58703..b5b03637d884 100644 --- a/nixos/modules/config/console.nix +++ b/nixos/modules/config/console.nix @@ -128,16 +128,6 @@ in ''); } - (lib.mkIf (!cfg.enable) { - systemd.services = { - "serial-getty@ttyS0".enable = false; - "serial-getty@hvc0".enable = false; - "getty@tty1".enable = false; - "autovt@".enable = false; - systemd-vconsole-setup.enable = false; - }; - }) - (lib.mkIf cfg.enable (lib.mkMerge [ { environment.systemPackages = [ pkgs.kbd ]; @@ -178,6 +168,10 @@ in "${cfg.keyMap}" ]; + systemd.additionalUpstreamSystemUnits = [ + "systemd-vconsole-setup.service" + ]; + systemd.services.reload-systemd-vconsole-setup = { description = "Reset console on configuration changes"; wantedBy = [ "multi-user.target" ]; diff --git a/nixos/modules/services/ttys/getty.nix b/nixos/modules/services/ttys/getty.nix index fd9bd7aca019..60cf8fe30171 100644 --- a/nixos/modules/services/ttys/getty.nix +++ b/nixos/modules/services/ttys/getty.nix @@ -120,12 +120,21 @@ in ###### implementation - config = { + config = mkIf config.console.enable { # Note: this is set here rather than up there so that changing # nixos.label would not rebuild manual pages services.getty.greetingLine = mkDefault ''<<< Welcome to ${config.system.nixos.distroName} ${config.system.nixos.label} (\m) - \l >>>''; services.getty.helpLine = mkIf (config.documentation.nixos.enable && config.documentation.doc.enable) "\nRun 'nixos-help' for the NixOS manual."; + systemd.additionalUpstreamSystemUnits = [ + "getty.target" + "getty-pre.target" + "getty@.service" + "serial-getty@.service" + "console-getty.service" + "container-getty@.service" + ]; + systemd.services."getty@" = { serviceConfig.ExecStart = [ # override upstream default with an empty ExecStart diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix index 9260bc22b13e..4f77a8137cc4 100644 --- a/nixos/modules/system/boot/systemd.nix +++ b/nixos/modules/system/boot/systemd.nix @@ -60,15 +60,6 @@ let # hwdb.bin is managed by NixOS # "systemd-hwdb-update.service" - # Consoles. - "getty.target" - "getty-pre.target" - "getty@.service" - "serial-getty@.service" - "console-getty.service" - "container-getty@.service" - "systemd-vconsole-setup.service" - # Hardware (started by udev when a relevant device is plugged in). "sound.target" "bluetooth.target"