From 05958b228b49cfe97f7faf51de4aaf3ede31894e Mon Sep 17 00:00:00 2001 From: Weijia Wang <9713184+wegank@users.noreply.github.com> Date: Tue, 2 Aug 2022 20:39:08 +0200 Subject: [PATCH] nixos/console: detect unicode properly --- nixos/modules/config/console.nix | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/nixos/modules/config/console.nix b/nixos/modules/config/console.nix index 7bcbf54cedd6..493411d61836 100644 --- a/nixos/modules/config/console.nix +++ b/nixos/modules/config/console.nix @@ -8,14 +8,23 @@ let makeColor = i: concatMapStringsSep "," (x: "0x" + substring (2*i) 2 x); - isUnicode = hasSuffix "UTF-8" (toUpper config.i18n.defaultLocale); + isUnicode = '' \ + LOCALE_ARCHIVE=${config.i18n.glibcLocales}/lib/locale/locale-archive \ + LANG=${config.i18n.defaultLocale} \ + LC_IDENTIFICATION=${config.i18n.defaultLocale} \ + locale -k identification-codeset | grep -i UTF-8 \ + ''; optimizedKeymap = pkgs.runCommand "keymap" { - nativeBuildInputs = [ pkgs.buildPackages.kbd ]; + nativeBuildInputs = with pkgs.buildPackages; [ kbd locale ]; LOADKEYS_KEYMAP_PATH = "${consoleEnv pkgs.kbd}/share/keymaps/**"; preferLocalBuild = true; } '' - loadkeys -b ${optionalString isUnicode "-u"} "${cfg.keyMap}" > $out + if ${isUnicode} ; then + loadkeys -b -u "${cfg.keyMap}" > $out + else + loadkeys -b "${cfg.keyMap}" > $out + fi ''; # Sadly, systemd-vconsole-setup doesn't support binary keymaps. @@ -130,7 +139,7 @@ in }) (mkIf setVconsole (mkMerge [ - { environment.systemPackages = [ pkgs.kbd ]; + { environment.systemPackages = with pkgs; [ kbd locale ]; # Let systemd-vconsole-setup.service do the work of setting up the # virtual consoles. @@ -139,8 +148,13 @@ in environment.etc.kbd.source = "${consoleEnv pkgs.kbd}/share"; boot.initrd.preLVMCommands = mkIf (!config.boot.initrd.systemd.enable) (mkBefore '' - kbd_mode ${if isUnicode then "-u" else "-a"} -C /dev/console - printf "\033%%${if isUnicode then "G" else "@"}" >> /dev/console + if ${isUnicode} ; then + kbd_mode -u -C /dev/console + printf "\033%%G" >> /dev/console + else + kbd_mode -a -C /dev/console + printf "\033%%@" >> /dev/console + fi loadkmap < ${optimizedKeymap} ${optionalString cfg.earlySetup ''