From fb3a89f4b81a808a46daf9733d2b8b6e44b62675 Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Thu, 11 Jul 2024 22:10:57 +0200
Subject: [PATCH] Allow setting the keyboard layout from the config file

---
 lib/modules/valhalla.nix    |  6 ++++++
 profiles/Generic/config.nix |  1 +
 scripts/Arch/OS/setup.fish  | 17 +++++++++--------
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/lib/modules/valhalla.nix b/lib/modules/valhalla.nix
index abab8a39..f308fc6e 100644
--- a/lib/modules/valhalla.nix
+++ b/lib/modules/valhalla.nix
@@ -23,6 +23,12 @@
           description = "The console key map of the system.";
           default = null;
         };
+
+        keyboardLayout = mkOption {
+          type = types.nullOr types.str;
+          description = "The X11 keyboard layout of the system.";
+          default = null;
+        };
       };
     };
   }
diff --git a/profiles/Generic/config.nix b/profiles/Generic/config.nix
index 4f0b5bbd..537e6bef 100644
--- a/profiles/Generic/config.nix
+++ b/profiles/Generic/config.nix
@@ -36,6 +36,7 @@
 
         timeZone = "Europe/Zurich";
         keyMap = "de_CH-latin1";
+        keyboardLayout = "ch";
 
         i18n = {
           localeSettings =
diff --git a/scripts/Arch/OS/setup.fish b/scripts/Arch/OS/setup.fish
index 1b8176ae..75535736 100644
--- a/scripts/Arch/OS/setup.fish
+++ b/scripts/Arch/OS/setup.fish
@@ -5,7 +5,6 @@ begin
     source "$dir/../../Common/Scripts/hooks.fish"
 
     set -q CONFIG_MODULE || set -l CONFIG_MODULE "$dir/config.nix"
-    set -q ARCH_X11_KEYMAP || set -l ARCH_X11_KEYMAP ch
 
     set -l mountDir (getConfig valhalla.partition.rootDir)
 
@@ -83,12 +82,14 @@ begin
         USER_GROUPS="$USER_GROUPS" \
             arch-chroot "$mountDir" bash "$tempDir/user.sh"
 
-        and set -l serviceName set-keymap.service
-        and set -l serviceFile "$mountDir/etc/systemd/system/$serviceName"
-        and cp "$dir/$serviceName" "$serviceFile"
-        and systemd-nspawn -D "$mountDir" systemctl enable "$serviceName"
-        and systemd-nspawn -bD "$mountDir" -E "ARCH_X11_KEYMAP=$ARCH_X11_KEYMAP"
-        and systemd-nspawn -D "$mountDir" systemctl disable "$serviceName"
-        and rm "$serviceFile"
+        and if set -l keyLayout (getConfig valhalla.keyboardLayout)
+            set -l serviceName set-keymap.service
+            and set -l serviceFile "$mountDir/etc/systemd/system/$serviceName"
+            and cp "$dir/$serviceName" "$serviceFile"
+            and systemd-nspawn -D "$mountDir" systemctl enable "$serviceName"
+            and systemd-nspawn -bD "$mountDir" -E "ARCH_X11_KEYMAP=$keyLayout"
+            and systemd-nspawn -D "$mountDir" systemctl disable "$serviceName"
+            and rm "$serviceFile"
+        end
     end
 end