From 3293ac0c14240c97f2a925d47bea6ab1d536a2a1 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Sun, 12 May 2024 13:31:50 +0200 Subject: [PATCH] fix get_keymap_and_locale --- nixosModules/installer/default.nix | 1 + pkgs/clan-cli/clan_cli/flash.py | 35 ++++++++++++++---------- pkgs/installer/flake-module.nix | 44 ++++++++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/nixosModules/installer/default.nix b/nixosModules/installer/default.nix index 21f48851..e80484d3 100644 --- a/nixosModules/installer/default.nix +++ b/nixosModules/installer/default.nix @@ -55,6 +55,7 @@ in # https://github.com/nix-community/nixos-images/blob/main/nix/image-installer/module.nix#L46C3-L117C6 # # # ######################################################################################################## + systemd.tmpfiles.rules = [ "d /var/shared 0777 root root - -" ]; services.openssh.settings.PermitRootLogin = lib.mkForce "prohibit-password"; hidden-ssh-announce = { diff --git a/pkgs/clan-cli/clan_cli/flash.py b/pkgs/clan-cli/clan_cli/flash.py index e841c9d0..ed7cc77c 100644 --- a/pkgs/clan-cli/clan_cli/flash.py +++ b/pkgs/clan-cli/clan_cli/flash.py @@ -3,6 +3,7 @@ import importlib import json import logging import os +import re import shutil import textwrap from collections.abc import Sequence @@ -54,21 +55,27 @@ def read_public_key_contents(public_keys: list[Path]) -> list[str]: return public_key_contents -def get_locale() -> tuple[str, str]: - """ - Function to get the current default locale from the system. - """ - default_locale = "en_US.UTF-8" +def get_keymap_and_locale() -> dict[str, str]: + locale = "en_US.UTF-8" keymap = "en" - res = run(["locale", "lang_ab", "country_ab2", "charmap"]) + # Execute the `localectl status` command + result = run(["localectl", "status"]) - if res.returncode == 0: - arr = res.stdout.strip().split("\n") - default_locale = f"{arr[0]}_{arr[1]}.{arr[2]}" - keymap = arr[0] + if result.returncode == 0: + output = result.stdout - return (keymap, default_locale) + # Extract the Keymap (X11 Layout) + keymap_match = re.search(r"X11 Layout:\s+(.*)", output) + if keymap_match: + keymap = keymap_match.group(1) + + # Extract the System Locale (LANG only) + locale_match = re.search(r"System Locale:\s+LANG=(.*)", output) + if locale_match: + locale = locale_match.group(1) + + return {"keymap": keymap, "locale": locale} def flash_machine( @@ -206,16 +213,16 @@ def flash_command(args: argparse.Namespace) -> None: else: raise ClanError("Invalid state") - console_keymap, default_locale = get_locale() + localectl = get_keymap_and_locale() extra_config = { "users": { "users": {"root": {"openssh": {"authorizedKeys": {"keys": root_keys}}}} }, "console": { - "keyMap": opts.keymap if opts.keymap else console_keymap, + "keyMap": opts.keymap if opts.keymap else localectl["keymap"], }, "i18n": { - "defaultLocale": opts.language if opts.language else default_locale, + "defaultLocale": opts.language if opts.language else localectl["locale"], }, } diff --git a/pkgs/installer/flake-module.nix b/pkgs/installer/flake-module.nix index 5318919f..31313fba 100644 --- a/pkgs/installer/flake-module.nix +++ b/pkgs/installer/flake-module.nix @@ -50,11 +50,52 @@ let imports = [ wifiModule self.nixosModules.installer - self.clanModules.disk-layouts ]; system.stateVersion = config.system.nixos.version; nixpkgs.pkgs = self.inputs.nixpkgs.legacyPackages.x86_64-linux; + } + // flashDiskoConfig; + + # Important: The partition names need to be different to the clan install + flashDiskoConfig = { + boot.loader.grub.efiSupport = lib.mkDefault true; + boot.loader.grub.efiInstallAsRemovable = lib.mkDefault true; + disko.devices = { + disk = { + main = { + type = "disk"; + device = lib.mkDefault "/dev/null"; + content = { + type = "gpt"; + partitions = { + installer-boot = { + size = "1M"; + type = "EF02"; # for grub MBR + priority = 1; + }; + installer-ESP = { + size = "512M"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + installer-root = { + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + }; + }; + }; + }; }; + }; in { clan = { @@ -74,7 +115,6 @@ in # This will include your ssh public keys in the installer. machines.flash-installer = { imports = [ flashInstallerModule ]; - clan.disk-layouts.singleDiskExt4.device = lib.mkDefault "/dev/null"; boot.loader.grub.enable = lib.mkDefault true; }; };