From 069f2000f4e098dcc09291a7396d267e569618b1 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Tue, 25 Apr 2023 16:03:10 -0400 Subject: [PATCH] modules/boot: Add options to better control console parameters It is generally awkward to deal with the console kernel parameters, and just as awkward to deal with lists in the modules system. Internally to Mobile NixOS, we'll use these values that should always be prefixed to any other values. This means that those consoles will likely to be less preferred than any the end-users sets (e.g. `console=tty1` in their own config). The option for `defaultConsole` is not really meant to be user-controlled, but there is actually no issue if they use it, as long as their configuration does not set another console later in the cmdline. --- modules/boot.nix | 66 +++++++++++++++++++++++++++++++++++++++++ modules/module-list.nix | 1 + 2 files changed, 67 insertions(+) create mode 100644 modules/boot.nix diff --git a/modules/boot.nix b/modules/boot.nix new file mode 100644 index 00000000..434a7e8d --- /dev/null +++ b/modules/boot.nix @@ -0,0 +1,66 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.mobile.boot; + inherit (lib) + mkBefore + mkOption + mkOptionDefault + optional + types + ; +in +{ + options.mobile.boot = { + defaultConsole = mkOption { + type = with types; nullOr str; + description = lib.mdDoc '' + When not null, sets a `console=` parameter early in the kernel cmdline. + + This option is useful to control the default console that will be + used by the produced system, since otherwise it is impossible to + remove an added `console=` parameter from the cmdline. + + When using beautification options with the kernel logo, the console + will be set to tty2, "losing" messages to the second VT. Without + beautification, this will be set to `tty1`. + + You can also add additional console params to the kernel cmdline, + the last valid one in the list will be used for kernel messages by + default during boot. + ''; + }; + additionalConsoles = mkOption { + type = with types; listOf str; + default = [ ]; + example = [ "ttyS0" ]; + description = lib.mdDoc '' + List of additional console names to be prepended in the list of + consoles in the kernel cmdline. + + These will have a lower priority than the console listed in `defaultConsole`, + and assumedly other kernel cmdline parameters added by the user. + + This option is useful to add additional consoles like the serial + console to the list so that console multiplexing during boot can + print messages to it too. + + The kernel's own messages will not be printed on those consoles. + ''; + }; + }; + config = { + mobile.boot.defaultConsole = mkOptionDefault ( + # We add the default default console only when the whole of Mobile NixOS is enabled. + if config.mobile.enable then "tty1" else null + ); + boot.kernelParams = mkBefore ( + map + (console: "console=${console}") + ( + cfg.additionalConsoles + ++ (optional (cfg.defaultConsole != null) cfg.defaultConsole) + ) + ); + }; +} diff --git a/modules/module-list.nix b/modules/module-list.nix index 80d75be1..f88b84d3 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -5,6 +5,7 @@ ./beautification.nix ./boot-control.nix ./boot-initrd.nix + ./boot.nix ./bootloader.nix ./cross-workarounds.nix ./devices-metadata.nix