From a35b12ed215e3b978ba4f14eca7bdcc11d2bf70c Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Fri, 22 Nov 2019 11:50:46 +0100 Subject: [PATCH] nixos/console: set colors using kernel parameters This commit changes the console colors implementation to use the kernel parameters instead of relying on terminal escape sequences. This means the palette is applied by the kernel itself with no custom code running in the initrd and works for all virtual terminals (not only tty0). --- nixos/modules/config/console.nix | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/nixos/modules/config/console.nix b/nixos/modules/config/console.nix index a524aa3adcd..f662ed62d31 100644 --- a/nixos/modules/config/console.nix +++ b/nixos/modules/config/console.nix @@ -6,10 +6,7 @@ with lib; let cfg = config.console; - makeColor = n: value: "COLOR_${toString n}=${value}"; - makeColorCS = - let positions = [ "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "A" "B" "C" "D" "E" "F" ]; - in n: value: "\\033]P${elemAt positions (n - 1)}${value}"; + makeColor = i: concatMapStringsSep "," (x: "0x" + substring (2*i) 2 x); isUnicode = hasSuffix "UTF-8" (toUpper config.i18n.defaultLocale); @@ -25,7 +22,6 @@ let vconsoleConf = pkgs.writeText "vconsole.conf" '' KEYMAP=${cfg.keyMap} FONT=${cfg.font} - ${concatImapStringsSep "\n" makeColor cfg.colors} ''; consoleEnv = pkgs.buildEnv { @@ -160,10 +156,6 @@ in ${optionalString cfg.earlySetup '' setfont -C /dev/console $extraUtils/share/consolefonts/font.psf ''} - - ${concatImapStringsSep "\n" (n: color: '' - printf "${makeColorCS n color}" >> /dev/console - '') cfg.colors} ''; systemd.services.systemd-vconsole-setup = @@ -173,6 +165,14 @@ in }; } + (mkIf (cfg.colors != []) { + boot.kernelParams = [ + "vt.default_red=${makeColor 0 cfg.colors}" + "vt.default_grn=${makeColor 1 cfg.colors}" + "vt.default_blu=${makeColor 2 cfg.colors}" + ]; + }) + (mkIf cfg.earlySetup { boot.initrd.extraUtilsCommands = '' mkdir -p $out/share/consolefonts