nixos/console: remove with lib;
This commit is contained in:
@@ -1,27 +1,23 @@
|
|||||||
|
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.console;
|
cfg = config.console;
|
||||||
|
|
||||||
makeColor = i: concatMapStringsSep "," (x: "0x" + substring (2*i) 2 x);
|
makeColor = i: lib.concatMapStringsSep "," (x: "0x" + lib.substring (2*i) 2 x);
|
||||||
|
|
||||||
isUnicode = hasSuffix "UTF-8" (toUpper config.i18n.defaultLocale);
|
isUnicode = lib.hasSuffix "UTF-8" (lib.toUpper config.i18n.defaultLocale);
|
||||||
|
|
||||||
optimizedKeymap = pkgs.runCommand "keymap" {
|
optimizedKeymap = pkgs.runCommand "keymap" {
|
||||||
nativeBuildInputs = [ pkgs.buildPackages.kbd ];
|
nativeBuildInputs = [ pkgs.buildPackages.kbd ];
|
||||||
LOADKEYS_KEYMAP_PATH = "${consoleEnv pkgs.kbd}/share/keymaps/**";
|
LOADKEYS_KEYMAP_PATH = "${consoleEnv pkgs.kbd}/share/keymaps/**";
|
||||||
preferLocalBuild = true;
|
preferLocalBuild = true;
|
||||||
} ''
|
} ''
|
||||||
loadkeys -b ${optionalString isUnicode "-u"} "${cfg.keyMap}" > $out
|
loadkeys -b ${lib.optionalString isUnicode "-u"} "${cfg.keyMap}" > $out
|
||||||
'';
|
'';
|
||||||
|
|
||||||
# Sadly, systemd-vconsole-setup doesn't support binary keymaps.
|
# Sadly, systemd-vconsole-setup doesn't support binary keymaps.
|
||||||
vconsoleConf = pkgs.writeText "vconsole.conf" ''
|
vconsoleConf = pkgs.writeText "vconsole.conf" ''
|
||||||
KEYMAP=${cfg.keyMap}
|
KEYMAP=${cfg.keyMap}
|
||||||
${optionalString (cfg.font != null) "FONT=${cfg.font}"}
|
${lib.optionalString (cfg.font != null) "FONT=${cfg.font}"}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
consoleEnv = kbd: pkgs.buildEnv {
|
consoleEnv = kbd: pkgs.buildEnv {
|
||||||
@@ -40,12 +36,12 @@ in
|
|||||||
###### interface
|
###### interface
|
||||||
|
|
||||||
options.console = {
|
options.console = {
|
||||||
enable = mkEnableOption "virtual console" // {
|
enable = lib.mkEnableOption "virtual console" // {
|
||||||
default = true;
|
default = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
font = mkOption {
|
font = lib.mkOption {
|
||||||
type = with types; nullOr (either str path);
|
type = with lib.types; nullOr (either str path);
|
||||||
default = null;
|
default = null;
|
||||||
example = "LatArCyrHeb-16";
|
example = "LatArCyrHeb-16";
|
||||||
description = ''
|
description = ''
|
||||||
@@ -61,8 +57,8 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
keyMap = mkOption {
|
keyMap = lib.mkOption {
|
||||||
type = with types; either str path;
|
type = with lib.types; either str path;
|
||||||
default = "us";
|
default = "us";
|
||||||
example = "fr";
|
example = "fr";
|
||||||
description = ''
|
description = ''
|
||||||
@@ -70,8 +66,8 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
colors = mkOption {
|
colors = lib.mkOption {
|
||||||
type = with types; listOf (strMatching "[[:xdigit:]]{6}");
|
type = with lib.types; listOf (strMatching "[[:xdigit:]]{6}");
|
||||||
default = [ ];
|
default = [ ];
|
||||||
example = [
|
example = [
|
||||||
"002b36" "dc322f" "859900" "b58900"
|
"002b36" "dc322f" "859900" "b58900"
|
||||||
@@ -88,8 +84,8 @@ in
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
packages = mkOption {
|
packages = lib.mkOption {
|
||||||
type = types.listOf types.package;
|
type = lib.types.listOf lib.types.package;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
description = ''
|
description = ''
|
||||||
List of additional packages that provide console fonts, keymaps and
|
List of additional packages that provide console fonts, keymaps and
|
||||||
@@ -97,8 +93,8 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
useXkbConfig = mkOption {
|
useXkbConfig = lib.mkOption {
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
If set, configure the virtual console keymap from the xserver
|
If set, configure the virtual console keymap from the xserver
|
||||||
@@ -106,9 +102,9 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
earlySetup = mkOption {
|
earlySetup = lib.mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
type = types.bool;
|
type = lib.types.bool;
|
||||||
description = ''
|
description = ''
|
||||||
Enable setting virtual console options as early as possible (in initrd).
|
Enable setting virtual console options as early as possible (in initrd).
|
||||||
'';
|
'';
|
||||||
@@ -119,12 +115,12 @@ in
|
|||||||
|
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkMerge [
|
config = lib.mkMerge [
|
||||||
{ console.keyMap = with config.services.xserver;
|
{ console.keyMap = with config.services.xserver;
|
||||||
mkIf cfg.useXkbConfig
|
lib.mkIf cfg.useXkbConfig
|
||||||
(pkgs.runCommand "xkb-console-keymap" { preferLocalBuild = true; } ''
|
(pkgs.runCommand "xkb-console-keymap" { preferLocalBuild = true; } ''
|
||||||
'${pkgs.buildPackages.ckbcomp}/bin/ckbcomp' \
|
'${pkgs.buildPackages.ckbcomp}/bin/ckbcomp' \
|
||||||
${optionalString (config.environment.sessionVariables ? XKB_CONFIG_ROOT)
|
${lib.optionalString (config.environment.sessionVariables ? XKB_CONFIG_ROOT)
|
||||||
"-I${config.environment.sessionVariables.XKB_CONFIG_ROOT}"
|
"-I${config.environment.sessionVariables.XKB_CONFIG_ROOT}"
|
||||||
} \
|
} \
|
||||||
-model '${xkb.model}' -layout '${xkb.layout}' \
|
-model '${xkb.model}' -layout '${xkb.layout}' \
|
||||||
@@ -132,7 +128,7 @@ in
|
|||||||
'');
|
'');
|
||||||
}
|
}
|
||||||
|
|
||||||
(mkIf (!cfg.enable) {
|
(lib.mkIf (!cfg.enable) {
|
||||||
systemd.services = {
|
systemd.services = {
|
||||||
"serial-getty@ttyS0".enable = false;
|
"serial-getty@ttyS0".enable = false;
|
||||||
"serial-getty@hvc0".enable = false;
|
"serial-getty@hvc0".enable = false;
|
||||||
@@ -142,7 +138,7 @@ in
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.enable (mkMerge [
|
(lib.mkIf cfg.enable (lib.mkMerge [
|
||||||
{ environment.systemPackages = [ pkgs.kbd ];
|
{ environment.systemPackages = [ pkgs.kbd ];
|
||||||
|
|
||||||
# Let systemd-vconsole-setup.service do the work of setting up the
|
# Let systemd-vconsole-setup.service do the work of setting up the
|
||||||
@@ -151,12 +147,12 @@ in
|
|||||||
# Provide kbd with additional packages.
|
# Provide kbd with additional packages.
|
||||||
environment.etc.kbd.source = "${consoleEnv pkgs.kbd}/share";
|
environment.etc.kbd.source = "${consoleEnv pkgs.kbd}/share";
|
||||||
|
|
||||||
boot.initrd.preLVMCommands = mkIf (!config.boot.initrd.systemd.enable) (mkBefore ''
|
boot.initrd.preLVMCommands = lib.mkIf (!config.boot.initrd.systemd.enable) (lib.mkBefore ''
|
||||||
kbd_mode ${if isUnicode then "-u" else "-a"} -C /dev/console
|
kbd_mode ${if isUnicode then "-u" else "-a"} -C /dev/console
|
||||||
printf "\033%%${if isUnicode then "G" else "@"}" >> /dev/console
|
printf "\033%%${if isUnicode then "G" else "@"}" >> /dev/console
|
||||||
loadkmap < ${optimizedKeymap}
|
loadkmap < ${optimizedKeymap}
|
||||||
|
|
||||||
${optionalString (cfg.earlySetup && cfg.font != null) ''
|
${lib.optionalString (cfg.earlySetup && cfg.font != null) ''
|
||||||
setfont -C /dev/console $extraUtils/share/consolefonts/font.psf
|
setfont -C /dev/console $extraUtils/share/consolefonts/font.psf
|
||||||
''}
|
''}
|
||||||
'');
|
'');
|
||||||
@@ -176,9 +172,9 @@ in
|
|||||||
"${config.boot.initrd.systemd.package.kbd}/bin/setfont"
|
"${config.boot.initrd.systemd.package.kbd}/bin/setfont"
|
||||||
"${config.boot.initrd.systemd.package.kbd}/bin/loadkeys"
|
"${config.boot.initrd.systemd.package.kbd}/bin/loadkeys"
|
||||||
"${config.boot.initrd.systemd.package.kbd.gzip}/bin/gzip" # Fonts and keyboard layouts are compressed
|
"${config.boot.initrd.systemd.package.kbd.gzip}/bin/gzip" # Fonts and keyboard layouts are compressed
|
||||||
] ++ optionals (cfg.font != null && hasPrefix builtins.storeDir cfg.font) [
|
] ++ lib.optionals (cfg.font != null && lib.hasPrefix builtins.storeDir cfg.font) [
|
||||||
"${cfg.font}"
|
"${cfg.font}"
|
||||||
] ++ optionals (hasPrefix builtins.storeDir cfg.keyMap) [
|
] ++ lib.optionals (lib.hasPrefix builtins.storeDir cfg.keyMap) [
|
||||||
"${cfg.keyMap}"
|
"${cfg.keyMap}"
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -195,7 +191,7 @@ in
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
(mkIf (cfg.colors != []) {
|
(lib.mkIf (cfg.colors != []) {
|
||||||
boot.kernelParams = [
|
boot.kernelParams = [
|
||||||
"vt.default_red=${makeColor 0 cfg.colors}"
|
"vt.default_red=${makeColor 0 cfg.colors}"
|
||||||
"vt.default_grn=${makeColor 1 cfg.colors}"
|
"vt.default_grn=${makeColor 1 cfg.colors}"
|
||||||
@@ -203,10 +199,10 @@ in
|
|||||||
];
|
];
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (cfg.earlySetup && cfg.font != null && !config.boot.initrd.systemd.enable) {
|
(lib.mkIf (cfg.earlySetup && cfg.font != null && !config.boot.initrd.systemd.enable) {
|
||||||
boot.initrd.extraUtilsCommands = ''
|
boot.initrd.extraUtilsCommands = ''
|
||||||
mkdir -p $out/share/consolefonts
|
mkdir -p $out/share/consolefonts
|
||||||
${if substring 0 1 cfg.font == "/" then ''
|
${if lib.substring 0 1 cfg.font == "/" then ''
|
||||||
font="${cfg.font}"
|
font="${cfg.font}"
|
||||||
'' else ''
|
'' else ''
|
||||||
font="$(echo ${consoleEnv pkgs.kbd}/share/consolefonts/${cfg.font}.*)"
|
font="$(echo ${consoleEnv pkgs.kbd}/share/consolefonts/${cfg.font}.*)"
|
||||||
@@ -222,14 +218,14 @@ in
|
|||||||
];
|
];
|
||||||
|
|
||||||
imports = [
|
imports = [
|
||||||
(mkRenamedOptionModule [ "i18n" "consoleFont" ] [ "console" "font" ])
|
(lib.mkRenamedOptionModule [ "i18n" "consoleFont" ] [ "console" "font" ])
|
||||||
(mkRenamedOptionModule [ "i18n" "consoleKeyMap" ] [ "console" "keyMap" ])
|
(lib.mkRenamedOptionModule [ "i18n" "consoleKeyMap" ] [ "console" "keyMap" ])
|
||||||
(mkRenamedOptionModule [ "i18n" "consoleColors" ] [ "console" "colors" ])
|
(lib.mkRenamedOptionModule [ "i18n" "consoleColors" ] [ "console" "colors" ])
|
||||||
(mkRenamedOptionModule [ "i18n" "consolePackages" ] [ "console" "packages" ])
|
(lib.mkRenamedOptionModule [ "i18n" "consolePackages" ] [ "console" "packages" ])
|
||||||
(mkRenamedOptionModule [ "i18n" "consoleUseXkbConfig" ] [ "console" "useXkbConfig" ])
|
(lib.mkRenamedOptionModule [ "i18n" "consoleUseXkbConfig" ] [ "console" "useXkbConfig" ])
|
||||||
(mkRenamedOptionModule [ "boot" "earlyVconsoleSetup" ] [ "console" "earlySetup" ])
|
(lib.mkRenamedOptionModule [ "boot" "earlyVconsoleSetup" ] [ "console" "earlySetup" ])
|
||||||
(mkRenamedOptionModule [ "boot" "extraTTYs" ] [ "console" "extraTTYs" ])
|
(lib.mkRenamedOptionModule [ "boot" "extraTTYs" ] [ "console" "extraTTYs" ])
|
||||||
(mkRemovedOptionModule [ "console" "extraTTYs" ] ''
|
(lib.mkRemovedOptionModule [ "console" "extraTTYs" ] ''
|
||||||
Since NixOS switched to systemd (circa 2012), TTYs have been spawned on
|
Since NixOS switched to systemd (circa 2012), TTYs have been spawned on
|
||||||
demand, so there is no need to configure them manually.
|
demand, so there is no need to configure them manually.
|
||||||
'')
|
'')
|
||||||
|
|||||||
Reference in New Issue
Block a user