nixos/tests: add vconsole and locale tests

Signed-off-by: Kajus Naujokaitis <kajusn@gmail.com>
This commit is contained in:
Kajus Naujokaitis
2026-04-22 14:31:49 +03:00
parent bc2562685c
commit 567f03fad7
3 changed files with 127 additions and 0 deletions

View File

@@ -374,6 +374,7 @@ in
collectd = runTest ./collectd.nix;
commafeed = runTest ./commafeed.nix;
connman = runTest ./connman.nix;
console = runTest ./console.nix;
console-xkb-and-i18n = runTest ./console-xkb-and-i18n.nix;
consul = runTest ./consul.nix;
consul-template = runTest ./consul-template.nix;
@@ -899,6 +900,7 @@ in
llama-swap = runTest ./web-servers/llama-swap.nix;
lldap = runTest ./lldap.nix;
local-content-share = runTest ./local-content-share.nix;
locale = runTest ./locale.nix;
localsend = runTest ./localsend.nix;
locate = runTest ./locate.nix;
login = runTest ./login.nix;

72
nixos/tests/console.nix Normal file
View File

@@ -0,0 +1,72 @@
{ ... }:
{
name = "console";
meta.maintainers = [ ];
nodes =
let
# Temporary dirty workaround for nixpkgs/issues/286283
# Point directly to pkgs.kbd (real files) rather than /etc/kbd/keymaps
# (which goes through consoleEnv's buildEnv and contains only symlinks).
# systemd-localed follows the directory symlink but not individual file
# symlinks inside it, so buildEnv-based paths yield no usable keymaps.
missingKeymapsWorkaround =
{ pkgs, ... }:
{
systemd.tmpfiles.rules = [
"L /usr/share/keymaps - - - - ${pkgs.kbd}/share/keymaps"
];
};
in
{
node_static =
{ ... }:
{
imports = [ missingKeymapsWorkaround ];
console.keyMap = "lt";
};
node_imperative =
{ ... }:
{
imports = [ missingKeymapsWorkaround ];
console.keyMap = "lt";
i18n.imperativeLocale = true;
};
};
testScript =
{ ... }:
''
node_static.wait_for_unit("dbus.socket")
with subtest("static - declared keymap is reported by localectl"):
node_static.succeed("localectl status | grep -q 'VC Keymap: lt'")
with subtest("static - keymap reverts to declared value after reboot"):
# Unlike localectl set-locale, vconsole_write_data() in systemd's
# localed-util.c writes to a hardcoded /etc/vconsole.conf path rather
# than respecting SYSTEMD_ETC_VCONSOLE_CONF, so the set-keymap call
# itself always succeeds. The static guarantee is that NixOS activation
# restores the symlink on reboot, reverting any runtime changes.
node_static.succeed("localectl set-keymap fr")
node_static.succeed("localectl status | grep -q 'VC Keymap: fr'")
node_static.shutdown()
node_static.wait_for_unit("dbus.socket")
node_static.succeed("localectl status | grep -q 'VC Keymap: lt'")
node_imperative.wait_for_unit("dbus.socket")
with subtest("imperative - declared keymap is reported by localectl on first boot"):
node_imperative.succeed("localectl status | grep -q 'VC Keymap: lt'")
with subtest("imperative - localectl set-keymap changes the keymap"):
node_imperative.succeed("localectl set-keymap --no-convert fr")
node_imperative.succeed("localectl status | grep -q 'VC Keymap: fr'")
with subtest("imperative - keymap change persists across reboot"):
node_imperative.shutdown()
node_imperative.wait_for_unit("dbus.socket")
node_imperative.succeed("localectl status | grep -q 'VC Keymap: fr'")
'';
}

53
nixos/tests/locale.nix Normal file
View File

@@ -0,0 +1,53 @@
{ ... }:
{
name = "imperative-locale";
meta.maintainers = [ ];
nodes = {
node_static =
{ ... }:
{
i18n = {
defaultLocale = "lt_LT.UTF-8";
extraLocales = [ "en_US.UTF-8/UTF-8" ];
};
};
node_imperative =
{ ... }:
{
i18n = {
defaultLocale = "lt_LT.UTF-8";
imperativeLocale = true;
extraLocales = [ "en_US.UTF-8/UTF-8" ];
};
};
};
testScript =
{ ... }:
''
node_static.wait_for_unit("dbus.socket")
with subtest("static - declared locale is reported by localectl"):
node_static.succeed("localectl status | grep -q 'System Locale: LANG=lt_LT.UTF-8'")
with subtest("static - localectl set-locale is blocked"):
node_static.fail("localectl set-locale LANG=en_US.UTF-8")
node_static.succeed("localectl status | grep -q 'System Locale: LANG=lt_LT.UTF-8'")
node_imperative.wait_for_unit("dbus.socket")
with subtest("imperative - declared locale is reported by localectl on first boot"):
node_imperative.succeed("localectl status | grep -q 'System Locale: LANG=lt_LT.UTF-8'")
with subtest("imperative - localectl set-locale changes the locale"):
node_imperative.succeed("localectl set-locale LANG=en_US.UTF-8")
node_imperative.succeed("localectl status | grep -q 'System Locale: LANG=en_US.UTF-8'")
with subtest("imperative - locale change persists across reboot"):
node_imperative.shutdown()
node_imperative.wait_for_unit("dbus.socket")
node_imperative.succeed("localectl status | grep -q 'System Locale: LANG=en_US.UTF-8'")
'';
}