From 5d9a7fbe7fdb491df2b4c93da813f959773b5d62 Mon Sep 17 00:00:00 2001 From: Stefan Haan Date: Sat, 11 Jul 2026 15:45:08 +0200 Subject: [PATCH 1/2] nixos/test/systemd-localed: services.xserver.xkb.layout should be respected --- nixos/tests/all-tests.nix | 1 + nixos/tests/systemd-localed.nix | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 nixos/tests/systemd-localed.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 5e7a1a12a29c..c2e373ce0fca 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1684,6 +1684,7 @@ in systemd-journal = runTest ./systemd-journal.nix; systemd-journal-gateway = runTest ./systemd-journal-gateway.nix; systemd-journal-upload = runTest ./systemd-journal-upload.nix; + systemd-localed = runTest ./systemd-localed.nix; systemd-lock-handler = runTestOn [ "aarch64-linux" "x86_64-linux" ] ./systemd-lock-handler.nix; systemd-machinectl = runTest ./systemd-machinectl.nix; systemd-misc = runTest ./systemd-misc.nix; diff --git a/nixos/tests/systemd-localed.nix b/nixos/tests/systemd-localed.nix new file mode 100644 index 000000000000..308d90122868 --- /dev/null +++ b/nixos/tests/systemd-localed.nix @@ -0,0 +1,23 @@ +{ lib, ... }: +{ + name = "systemd-localed"; + meta.maintainers = [ lib.maintainers.haansn08 ]; + + nodes.machine = { ... }: { + # we don't use services.xserver.enable because some window managers like + # niri rely on systemd-localed for the keyboard layout: + # https://niri-wm.github.io/niri/Configuration%3A-Input.html#layout + services.graphical-desktop.enable = true; + + services.xserver.xkb.layout = "jp"; + }; + + testScript = '' + machine.start() + machine.wait_for_unit("default.target") + machine.wait_for_unit("dbus.socket") + + status, stdout = machine.execute("localectl") + t.assertIn("X11 Layout: jp", stdout) + ''; +} From 3e46c77dd8c72ceb5db0fba1db90137b149ed163 Mon Sep 17 00:00:00 2001 From: Stefan Haan Date: Sun, 12 Jul 2026 04:23:54 +0200 Subject: [PATCH 2/2] nixos/graphical-desktop: avoid writing empty Option values to 00-keyboard.conf --- .../services/misc/graphical-desktop.nix | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/nixos/modules/services/misc/graphical-desktop.nix b/nixos/modules/services/misc/graphical-desktop.nix index e26050c123de..906601d1fc0c 100644 --- a/nixos/modules/services/misc/graphical-desktop.nix +++ b/nixos/modules/services/misc/graphical-desktop.nix @@ -22,17 +22,23 @@ in config = lib.mkIf cfg.enable { environment = { - # localectl looks into 00-keyboard.conf - etc."X11/xorg.conf.d/00-keyboard.conf".text = '' - Section "InputClass" - Identifier "Keyboard catchall" - MatchIsKeyboard "on" - Option "XkbModel" "${xcfg.xkb.model}" - Option "XkbLayout" "${xcfg.xkb.layout}" - Option "XkbOptions" "${xcfg.xkb.options}" - Option "XkbVariant" "${xcfg.xkb.variant}" - EndSection - ''; + # systemd-localed looks into 00-keyboard.conf + # systemd-localed does not like if Option values are "" + etc."X11/xorg.conf.d/00-keyboard.conf".text = + let + optionLine = + name: value: lib.optionalString (value != null && value != "") ''Option "${name}" "${value}"''; + in + '' + Section "InputClass" + Identifier "Keyboard catchall" + MatchIsKeyboard "on" + ${optionLine "XkbModel" xcfg.xkb.model} + ${optionLine "XkbLayout" xcfg.xkb.layout} + ${optionLine "XkbOptions" xcfg.xkb.options} + ${optionLine "XkbVariant" xcfg.xkb.variant} + EndSection + ''; systemPackages = with pkgs; [ nixos-icons # needed for gnome and pantheon about dialog, nixos-manual and maybe more xdg-utils