From da97ba359e5aac17c2a3eab5fd787b169d72dd05 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Fri, 8 Jul 2016 18:32:17 +0300 Subject: busybox: set default keymap path --- pkgs/os-specific/linux/busybox/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/os-specific/linux/busybox/default.nix b/pkgs/os-specific/linux/busybox/default.nix index fa6591701a69..b04f7855fefa 100644 --- a/pkgs/os-specific/linux/busybox/default.nix +++ b/pkgs/os-specific/linux/busybox/default.nix @@ -56,6 +56,9 @@ stdenv.mkDerivation rec { CONFIG_FEATURE_MOUNT_CIFS n CONFIG_FEATURE_MOUNT_HELPERS y + # Set paths for console fonts. + CONFIG_DEFAULT_SETFONT_DIR "/etc/kbd" + ${extraConfig} $extraCrossConfig EOF -- cgit 1.4.1 From 5622226d5b3043d5a6239b4c4f28e64fdbbaaba2 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sun, 3 Jul 2016 03:28:29 +0300 Subject: kbd service: drop a comment now when we do restart vconsole setup --- nixos/modules/tasks/kbd.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nixos/modules/tasks/kbd.nix b/nixos/modules/tasks/kbd.nix index 02721bb3bea2..c1087ce4783e 100644 --- a/nixos/modules/tasks/kbd.nix +++ b/nixos/modules/tasks/kbd.nix @@ -52,8 +52,7 @@ in environment.systemPackages = [ pkgs.kbd ]; # Let systemd-vconsole-setup.service do the work of setting up the - # virtual consoles. FIXME: trigger a restart of - # systemd-vconsole-setup.service if /etc/vconsole.conf changes. + # virtual consoles. environment.etc = [ { target = "vconsole.conf"; source = vconsoleConf; -- cgit 1.4.1 From 803b1eedd65337e18c54d413f4bbbcbcba772e53 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Sun, 3 Jul 2016 03:29:21 +0300 Subject: kbd service: add system-wise console resources --- nixos/modules/config/i18n.nix | 9 +++++++++ nixos/modules/tasks/kbd.nix | 15 ++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/nixos/modules/config/i18n.nix b/nixos/modules/config/i18n.nix index b20fac6ad3e2..2dc0df85e5ff 100644 --- a/nixos/modules/config/i18n.nix +++ b/nixos/modules/config/i18n.nix @@ -41,6 +41,15 @@ in ''; }; + consolePackages = mkOption { + type = types.listOf types.package; + default = []; + description = '' + List of additional packages that provide console fonts, keymaps and + other resources. + ''; + }; + consoleFont = mkOption { type = types.str; default = "Lat2-Terminus16"; diff --git a/nixos/modules/tasks/kbd.nix b/nixos/modules/tasks/kbd.nix index c1087ce4783e..dd89804d43a7 100644 --- a/nixos/modules/tasks/kbd.nix +++ b/nixos/modules/tasks/kbd.nix @@ -13,6 +13,12 @@ let ${colors} ''; + kbdEnv = pkgs.buildEnv { + name = "kbd-env"; + paths = [ pkgs.kbd ] ++ config.i18n.consolePackages; + pathsToLink = [ "/share/consolefonts" "/share/consoletrans" "/share/keymaps" "/share/unimaps" ]; + }; + setVconsole = !config.boot.isContainer; in @@ -53,10 +59,9 @@ in # Let systemd-vconsole-setup.service do the work of setting up the # virtual consoles. - environment.etc = [ { - target = "vconsole.conf"; - source = vconsoleConf; - } ]; + environment.etc."vconsole.conf".source = vconsoleConf; + # Provide kbd with additional packages. + environment.etc."kbd".source = "${kbdEnv}/share"; # This is identical to the systemd-vconsole-setup.service unit # shipped with systemd, except that it uses /dev/tty1 instead of @@ -66,7 +71,7 @@ in { wantedBy = [ "multi-user.target" ]; before = [ "display-manager.service" ]; after = [ "systemd-udev-settle.service" ]; - restartTriggers = [ vconsoleConf ]; + restartTriggers = [ vconsoleConf kbdEnv ]; }; }) ]; -- cgit 1.4.1 From 9e48baa716f17385b4850377f11e16c33d75cac1 Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Fri, 8 Jul 2016 20:01:42 +0300 Subject: kbd service: add support for early loading of fonts and keymaps --- nixos/modules/tasks/kbd.nix | 104 ++++++++++++++++++++++++++++++++------------ 1 file changed, 77 insertions(+), 27 deletions(-) diff --git a/nixos/modules/tasks/kbd.nix b/nixos/modules/tasks/kbd.nix index dd89804d43a7..5a49b09d6356 100644 --- a/nixos/modules/tasks/kbd.nix +++ b/nixos/modules/tasks/kbd.nix @@ -5,20 +5,33 @@ with lib; let 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 position n}${value}"; colors = concatImapStringsSep "\n" makeColor config.i18n.consoleColors; - vconsoleConf = pkgs.writeText "vconsole.conf" '' - KEYMAP=${config.i18n.consoleKeyMap} - FONT=${config.i18n.consoleFont} - ${colors} - ''; - kbdEnv = pkgs.buildEnv { name = "kbd-env"; paths = [ pkgs.kbd ] ++ config.i18n.consolePackages; pathsToLink = [ "/share/consolefonts" "/share/consoletrans" "/share/keymaps" "/share/unimaps" ]; }; + isUnicode = hasSuffix "UTF-8" (toUpper config.i18n.defaultLocale); + + optimizedKeymap = pkgs.runCommand "keymap" { + nativeBuildInputs = [ pkgs.kbd ]; + } '' + cd ${kbdEnv}/share/keymaps + loadkeys -b ${optionalString isUnicode "-u"} "${config.i18n.consoleKeyMap}" > $out + ''; + + # Sadly, systemd-vconsole-setup doesn't support binary keymaps. + vconsoleConf = pkgs.writeText "vconsole.conf" '' + KEYMAP=${config.i18n.consoleKeyMap} + FONT=${config.i18n.consoleFont} + ${colors} + ''; + setVconsole = !config.boot.isContainer; in @@ -44,36 +57,73 @@ in ''; }; + boot.earlyVconsoleSetup = mkOption { + default = false; + type = types.bool; + description = '' + Enable setting font and keymap as early as possible (in initrd). + ''; + }; + }; ###### implementation config = mkMerge [ - (mkIf (!setVconsole) { + (mkIf (!setVconsole || (setVconsole && config.boot.earlyVconsoleSetup)) { systemd.services."systemd-vconsole-setup".enable = false; }) - (mkIf setVconsole { - environment.systemPackages = [ pkgs.kbd ]; - - # Let systemd-vconsole-setup.service do the work of setting up the - # virtual consoles. - environment.etc."vconsole.conf".source = vconsoleConf; - # Provide kbd with additional packages. - environment.etc."kbd".source = "${kbdEnv}/share"; - - # This is identical to the systemd-vconsole-setup.service unit - # shipped with systemd, except that it uses /dev/tty1 instead of - # /dev/tty0 to prevent putting the X server in non-raw mode, and - # it has a restart trigger. - systemd.services."systemd-vconsole-setup" = - { wantedBy = [ "multi-user.target" ]; - before = [ "display-manager.service" ]; - after = [ "systemd-udev-settle.service" ]; - restartTriggers = [ vconsoleConf kbdEnv ]; - }; - }) + (mkIf setVconsole (mkMerge [ + { environment.systemPackages = [ pkgs.kbd ]; + + # Let systemd-vconsole-setup.service do the work of setting up the + # virtual consoles. + environment.etc."vconsole.conf".source = vconsoleConf; + } + + (mkIf (!config.boot.earlyVconsoleSetup) { + # This is identical to the systemd-vconsole-setup.service unit + # shipped with systemd, except that it uses /dev/tty1 instead of + # /dev/tty0 to prevent putting the X server in non-raw mode, and + # it has a restart trigger. + systemd.services."systemd-vconsole-setup" = + { wantedBy = [ "sysinit.target" ]; + before = [ "display-manager.service" ]; + after = [ "systemd-udev-settle.service" ]; + restartTriggers = [ vconsoleConf ]; + }; + }) + + (mkIf config.boot.earlyVconsoleSetup { + boot.initrd.extraUtilsCommands = '' + mkdir -p $out/share/consolefonts + ${if substring 0 1 config.i18n.consoleFont == "/" then '' + font="${config.i18n.consoleFont}" + '' else '' + font="$(echo ${kbdEnv}/share/consolefonts/${config.i18n.consoleFont}.*)" + ''} + if [[ $font == *.gz ]]; then + gzip -cd $font > $out/share/consolefonts/font.psf + else + cp -L $font $out/share/consolefonts/font.psf + fi + ''; + + boot.initrd.preLVMCommands = mkBefore '' + kbd_mode ${if isUnicode then "-u" else "-a"} -C /dev/console + printf "\033%%${if isUnicode then "G" else "@"}" >> /dev/console + loadkmap < ${optimizedKeymap} + + setfont -C /dev/console $extraUtils/share/consolefonts/font.psf + + ${concatImapStringsSep "\n" (n: color: '' + printf "${makeColorCS n color}" >> /dev/console + '') config.i18n.consoleColors} + ''; + }) + ])) ]; } -- cgit 1.4.1