1
0
forked from clan/clan-core

fix get_keymap_and_locale

This commit is contained in:
Luis Hebendanz 2024-05-12 13:31:50 +02:00
parent be841cdec2
commit 3293ac0c14
3 changed files with 64 additions and 16 deletions

View File

@ -55,6 +55,7 @@ in
# https://github.com/nix-community/nixos-images/blob/main/nix/image-installer/module.nix#L46C3-L117C6 # # 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"; services.openssh.settings.PermitRootLogin = lib.mkForce "prohibit-password";
hidden-ssh-announce = { hidden-ssh-announce = {

View File

@ -3,6 +3,7 @@ import importlib
import json import json
import logging import logging
import os import os
import re
import shutil import shutil
import textwrap import textwrap
from collections.abc import Sequence from collections.abc import Sequence
@ -54,21 +55,27 @@ def read_public_key_contents(public_keys: list[Path]) -> list[str]:
return public_key_contents return public_key_contents
def get_locale() -> tuple[str, str]: def get_keymap_and_locale() -> dict[str, str]:
""" locale = "en_US.UTF-8"
Function to get the current default locale from the system.
"""
default_locale = "en_US.UTF-8"
keymap = "en" keymap = "en"
res = run(["locale", "lang_ab", "country_ab2", "charmap"]) # Execute the `localectl status` command
result = run(["localectl", "status"])
if res.returncode == 0: if result.returncode == 0:
arr = res.stdout.strip().split("\n") output = result.stdout
default_locale = f"{arr[0]}_{arr[1]}.{arr[2]}"
keymap = arr[0]
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( def flash_machine(
@ -206,16 +213,16 @@ def flash_command(args: argparse.Namespace) -> None:
else: else:
raise ClanError("Invalid state") raise ClanError("Invalid state")
console_keymap, default_locale = get_locale() localectl = get_keymap_and_locale()
extra_config = { extra_config = {
"users": { "users": {
"users": {"root": {"openssh": {"authorizedKeys": {"keys": root_keys}}}} "users": {"root": {"openssh": {"authorizedKeys": {"keys": root_keys}}}}
}, },
"console": { "console": {
"keyMap": opts.keymap if opts.keymap else console_keymap, "keyMap": opts.keymap if opts.keymap else localectl["keymap"],
}, },
"i18n": { "i18n": {
"defaultLocale": opts.language if opts.language else default_locale, "defaultLocale": opts.language if opts.language else localectl["locale"],
}, },
} }

View File

@ -50,11 +50,52 @@ let
imports = [ imports = [
wifiModule wifiModule
self.nixosModules.installer self.nixosModules.installer
self.clanModules.disk-layouts
]; ];
system.stateVersion = config.system.nixos.version; system.stateVersion = config.system.nixos.version;
nixpkgs.pkgs = self.inputs.nixpkgs.legacyPackages.x86_64-linux; 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 in
{ {
clan = { clan = {
@ -74,7 +115,6 @@ in
# This will include your ssh public keys in the installer. # This will include your ssh public keys in the installer.
machines.flash-installer = { machines.flash-installer = {
imports = [ flashInstallerModule ]; imports = [ flashInstallerModule ];
clan.disk-layouts.singleDiskExt4.device = lib.mkDefault "/dev/null";
boot.loader.grub.enable = lib.mkDefault true; boot.loader.grub.enable = lib.mkDefault true;
}; };
}; };