From 73d72c569e3d25c265b19150a37dd919f0b70518 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Tue, 9 Jul 2024 02:22:12 +0200 Subject: [PATCH] Load language settings from the config --- archiso/packages.x86_64 | 1 + scripts/Arch/OS/setup.fish | 18 +++++++++++------- scripts/Common/Scripts/config.fish | 5 +++++ scripts/Common/Scripts/eval-module.fish | 5 +++++ 4 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 scripts/Common/Scripts/config.fish create mode 100644 scripts/Common/Scripts/eval-module.fish diff --git a/archiso/packages.x86_64 b/archiso/packages.x86_64 index b89ab309..c5db92a8 100644 --- a/archiso/packages.x86_64 +++ b/archiso/packages.x86_64 @@ -47,6 +47,7 @@ irssi iw iwd jfsutils +jq kitty-terminfo ldns less diff --git a/scripts/Arch/OS/setup.fish b/scripts/Arch/OS/setup.fish index 604f4a5c..0438ed54 100644 --- a/scripts/Arch/OS/setup.fish +++ b/scripts/Arch/OS/setup.fish @@ -1,14 +1,14 @@ #!/bin/env fish begin set -l dir (status dirname) + . "$dir/../../Common/Scripts/config.fish" set -q CONFIG_MODULE || set -l CONFIG_MODULE "$dir/config.nix" set -q ARCH_TIMEZONE || set -l ARCH_TIMEZONE "Europe/Zurich" - set -q ARCH_MOUNT_ROOT || set -l ARCH_MOUNT_ROOT ("$dir/../../eval-module.sh" "$CONFIG_MODULE" partition.rootDir --raw) + set -q ARCH_MOUNT_ROOT || set -l ARCH_MOUNT_ROOT (getConfig partition.rootDir --raw) set -q ARCH_LANG || set -l ARCH_LANG en_US.UTF-8 set -q ARCH_KEYMAP || set -l ARCH_KEYMAP de_CH-latin1 set -q ARCH_X11_KEYMAP || set -l ARCH_X11_KEYMAP ch - set -q LOCALE_PATTERN || set -l LOCALE_PATTERN "\(de_CH\|en_US\)" set -q USER_NAME || set -l USER_NAME manuel set -q USER_DISPLAYNAME @@ -52,13 +52,17 @@ begin and arch-chroot "$ARCH_MOUNT_ROOT" ln -sf "/usr/share/zoneinfo/$ARCH_TIMEZONE" /etc/localtime and arch-chroot "$ARCH_MOUNT_ROOT" hwclock --systohc - and arch-chroot "$ARCH_MOUNT_ROOT" sed -i "s/^#\?\($LOCALE_PATTERN.*\)\$/\1/" /etc/locale.gen - and arch-chroot "$ARCH_MOUNT_ROOT" locale-gen + and begin + getConfig i18n.localeSettings --json | \ + jq --raw-output '[.[] | split(".") | .[0]] | unique | join("\\\\|")' + end | begin + read LOCALES + and arch-chroot "$ARCH_MOUNT_ROOT" sed -i "s/^#\?\(\($LOCALES\).*\)\$/\1/" /etc/locale.gen + end and begin - echo "LANG=de_CH.UTF-8" - echo "LANGUAGE=en_US.UTF-8" - echo "LC_MESSAGES=en_US.UTF-8" + getConfig i18n.localeSettings --json | \ + jq --raw-output '[keys[] as $key | "\($key)=\(.[$key])"] | join("\n")' end | arch-chroot "$ARCH_MOUNT_ROOT" tee /etc/locale.conf > /dev/null and echo "KEYMAP=$ARCH_KEYMAP" | arch-chroot "$ARCH_MOUNT_ROOT" tee /etc/vconsole.conf > /dev/null diff --git a/scripts/Common/Scripts/config.fish b/scripts/Common/Scripts/config.fish new file mode 100644 index 00000000..fd23b0d9 --- /dev/null +++ b/scripts/Common/Scripts/config.fish @@ -0,0 +1,5 @@ +#!/bin/env fish +function getConfig -S -a property + . "$(status dirname)/eval-module.fish" + evalModule "$CONFIG_MODULE" "$property" $argv[2..] +end diff --git a/scripts/Common/Scripts/eval-module.fish b/scripts/Common/Scripts/eval-module.fish new file mode 100644 index 00000000..2ffa1b17 --- /dev/null +++ b/scripts/Common/Scripts/eval-module.fish @@ -0,0 +1,5 @@ +#!/bin/env fish +function evalModule --argument-names modulePath property + set -l nixPkgs 'import { config = {}; overlay = []; }' + nix eval --file "$modulePath" --apply "_: (($nixPkgs).lib.evalModules { modules = [ _ ]; }).config.$property" $argv[3..] +end