From 35d194ebf61d1fc29bc3759249dae5dd6096a5c0 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Mon, 24 Nov 2025 15:06:26 -0500 Subject: [PATCH] feat: make boot messages configureable --- nixos/modules/system/boot/stage-1-init.sh | 4 ++-- nixos/modules/system/boot/stage-1.nix | 21 ++++++++++++++++++++- nixos/modules/system/boot/stage-2-init.sh | 2 +- nixos/modules/system/boot/stage-2.nix | 11 ++++++++++- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh index b8dbfb70c0bb..09ef663dbb6f 100644 --- a/nixos/modules/system/boot/stage-1-init.sh +++ b/nixos/modules/system/boot/stage-1-init.sh @@ -73,7 +73,7 @@ trap 'fail' 0 # Print a greeting. info -info "<<< @distroName@ Stage 1 >>>" +info "[1;32m@stage1Greeting@[0m" info # Make several required directories. @@ -445,7 +445,7 @@ lustrateRoot () { local root="$1" echo - echo -e "\e[1;33m<<< @distroName@ is now lustrating the root filesystem (cruft goes to /old-root) >>>\e[0m" + echo -e "\\e[1;33m@lustrateMessage@\\e[0m" echo mkdir -m 0755 -p "$root/old-root.tmp" diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index c87b3ecef4da..434e33ee8b70 100644 --- a/nixos/modules/system/boot/stage-1.nix +++ b/nixos/modules/system/boot/stage-1.nix @@ -309,7 +309,8 @@ let inherit (config.boot) resumeDevice; - inherit (config.system.nixos) distroName; + stage1Greeting = config.boot.initrd.stage1Greeting; + lustrateMessage = config.boot.initrd.lustrateMessage; inherit (config.system.build) earlyMountScript; @@ -686,6 +687,24 @@ in ''; }; + boot.initrd.stage1Greeting = mkOption { + type = types.str; + default = "<<< ${config.system.nixos.distroName} Stage 1 >>>"; + defaultText = lib.literalExpression ''"<<< ''${config.system.nixos.distroName} Stage 1 >>>"''; + description = '' + The greeting message displayed during NixOS stage 1 boot. + ''; + }; + + boot.initrd.lustrateMessage = mkOption { + type = types.str; + default = "<<< ${config.system.nixos.distroName} is now lustrating the root filesystem (cruft goes to /old-root) >>>"; + defaultText = lib.literalExpression ''"<<< ''${config.system.nixos.distroName} is now lustrating the root filesystem (cruft goes to /old-root) >>>"''; + description = '' + The message displayed when lustrating the root filesystem. + ''; + }; + boot.loader.supportsInitrdSecrets = mkOption { internal = true; default = false; diff --git a/nixos/modules/system/boot/stage-2-init.sh b/nixos/modules/system/boot/stage-2-init.sh index e960f1bbcc39..c9884a719012 100755 --- a/nixos/modules/system/boot/stage-2-init.sh +++ b/nixos/modules/system/boot/stage-2-init.sh @@ -19,7 +19,7 @@ if [ "${IN_NIXOS_SYSTEMD_STAGE1:-}" != true ]; then # Print a greeting. echo - echo -e "\e[1;32m<<< @distroName@ Stage 2 >>>\e[0m" + echo -e "\\e[1;32m@stage2Greeting@\\e[0m" echo diff --git a/nixos/modules/system/boot/stage-2.nix b/nixos/modules/system/boot/stage-2.nix index 9565ac5e8ef1..993f4415cf24 100644 --- a/nixos/modules/system/boot/stage-2.nix +++ b/nixos/modules/system/boot/stage-2.nix @@ -19,7 +19,7 @@ let systemConfig = null; # replaced in ../activation/top-level.nix inherit (config.boot) systemdExecutable; nixStoreMountOpts = lib.concatStringsSep " " (map lib.escapeShellArg config.boot.nixStoreMountOpts); - inherit (config.system.nixos) distroName; + stage2Greeting = config.boot.stage2Greeting; inherit useHostResolvConf; inherit (config.system.build) earlyMountScript; path = lib.makeBinPath ( @@ -87,6 +87,15 @@ in ''; }; + stage2Greeting = mkOption { + type = types.str; + default = "<<< ${config.system.nixos.distroName} Stage 2 >>>"; + defaultText = lib.literalExpression ''"<<< ''${config.system.nixos.distroName} Stage 2 >>>"''; + description = '' + The greeting message displayed during NixOS stage 2 boot. + ''; + }; + extraSystemdUnitPaths = mkOption { default = [ ]; type = types.listOf types.str; -- 2.51.2