1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-11-30 19:26:21 +03:00

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.
This commit is contained in:
Samuel Dionne-Riel 2023-04-25 16:03:10 -04:00
parent 4aa0afd840
commit 069f2000f4
2 changed files with 67 additions and 0 deletions

66
modules/boot.nix Normal file
View File

@ -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)
)
);
};
}

View File

@ -5,6 +5,7 @@
./beautification.nix
./boot-control.nix
./boot-initrd.nix
./boot.nix
./bootloader.nix
./cross-workarounds.nix
./devices-metadata.nix