Prefix valhalla related settings

This commit is contained in:
Manuel Thalmann 2024-07-11 19:31:50 +02:00
parent e7f8a6558f
commit 665a5d2f6e
9 changed files with 113 additions and 104 deletions

View file

@ -6,11 +6,13 @@
;
in {
options = {
i18n = {
localeSettings = mkOption {
type = types.attrsOf types.str;
description = "The system wide locale settings";
default = {};
valhalla = {
i18n = {
localeSettings = mkOption {
type = types.attrsOf types.str;
description = "The system wide locale settings";
default = {};
};
};
};
};

View file

@ -286,80 +286,85 @@
);
in {
options = {
partition = {
rootDir = mkOption {
type = types.str;
description = "The root of the installation directory to mount disks into.";
default = "/mnt";
};
valhalla = {
partition = {
rootDir = mkOption {
type = types.str;
description = "The root of the installation directory to mount disks into.";
default = "/mnt";
};
os = mkOption {
type = mkDiskType true;
description = "The partition layout of the OS disk.";
};
os = mkOption {
type = mkDiskType true;
description = "The partition layout of the OS disk.";
};
disks = mkOption {
type = types.attrsOf (mkDiskType false);
description = "The additional disks to format.";
default = {};
};
disks = mkOption {
type = types.attrsOf (mkDiskType false);
description = "The additional disks to format.";
default = {};
};
script = mkOption {
type = types.lines;
description = "The script for partitioning the system's disks.";
internal = true;
script = mkOption {
type = types.lines;
description = "The script for partitioning the system's disks.";
internal = true;
};
};
};
};
config = {
partition = {
script =
let
inherit (config.partition) os rootDir;
inherit (lib.strings) normalizePath;
valhalla = {
partition = {
script =
let
cfg = config.valhalla.partition;
inherit (cfg) os rootDir;
inherit (lib.strings) normalizePath;
partPath = part: "/dev/disk/by-label/${part.label}";
disks = ([os] ++ (builtins.attrValues config.partition.disks));
partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks);
partPath = part: "/dev/disk/by-label/${part.label}";
disks = ([os] ++ (builtins.attrValues cfg.disks));
partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks);
mountScript = lib.strings.concatLines (
builtins.map
(_: builtins.concatStringsSep " " [
"sudo"
"mount"
"--mkdir"
(builtins.concatStringsSep " " (builtins.map (_: "-o ${_}") _.mountOptions))
(partPath _)
(normalizePath "/${rootDir}/${_.mountPoint}")
])
(lib.lists.sortOn
(_: normalizePath "/${_.mountPoint}")
(builtins.filter (_: _.mountPoint != null) partitions)));
mountScript = lib.strings.concatLines (
builtins.map
(_: builtins.concatStringsSep " " [
"sudo"
"mount"
"--mkdir"
(builtins.concatStringsSep " " (builtins.map (_: "-o ${_}") _.mountOptions))
(partPath _)
(normalizePath "/${rootDir}/${_.mountPoint}")
])
(lib.lists.sortOn
(_: normalizePath "/${_.mountPoint}")
(builtins.filter (_: _.mountPoint != null) partitions)));
swapScript = lib.strings.concatLines (
builtins.map
(_: "sudo swapon ${partPath _}")
(builtins.filter (_: _.useSwap) partitions));
in lib.strings.concatLines (
(builtins.map (_: _.deviceScript) disks) ++ lib.optionals ((builtins.length disks) > 0) [
". ${./../../../scripts/Common/Scripts/is-truthy.sh}"
''echo "$(tput setaf 3)==== WARNING ====$(tput sgr0)"''
(''echo "Continuing this script will wipe the contents of '' + (
lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init disks))
) + (if (builtins.length disks) > 1 then " and " else "") + (lib.lists.last disks).deviceVariable + ''"'')
''read -p "Are you sure you want to continue? [y/n] " answer''
''
if ! isTruthy "$answer"; then
exit 1
fi
''
] ++
(builtins.map (_: _.script) disks) ++ [
mountScript
swapScript
]
);
swapScript = lib.strings.concatLines (
builtins.map
(_: "sudo swapon ${partPath _}")
(builtins.filter (_: _.useSwap) partitions));
in lib.strings.concatLines (
(builtins.map (_: _.deviceScript) disks) ++ lib.optionals ((builtins.length disks) > 0) [
". ${./../../../scripts/Common/Scripts/is-truthy.sh}"
''echo "$(tput setaf 3)==== WARNING ====$(tput sgr0)"''
(''echo "Continuing this script will wipe the contents of '' + (
lib.strings.concatStringsSep ", " (builtins.map (_: "${_.deviceVariable}") (lib.lists.init disks))
) + (if (builtins.length disks) > 1 then " and " else "") + (lib.lists.last disks).deviceVariable + ''"'')
''read -p "Are you sure you want to continue? [y/n] " answer''
''
if ! isTruthy "$answer"; then
exit 1
fi
''
] ++
(builtins.map (_: _.script) disks) ++ [
mountScript
swapScript
]
);
};
};
};
}

View file

@ -4,7 +4,7 @@
];
config = {
partition.os.partitions = {
valhalla.partition.os.partitions = {
# Keep Windows' boot partition
Boot.keepExisting = true;

View file

@ -4,7 +4,7 @@
];
config = {
partition.os.partitions = {
valhalla.partition.os.partitions = {
OS.label = "Arch";
};
};

View file

@ -8,40 +8,42 @@
];
config = {
partition = {
os = {
partitions = {
Boot = {
index = 1;
type = "uefi";
size = "+1G";
format = fs.fat32;
mountPoint = "/boot";
};
valhalla = {
partition = {
os = {
partitions = {
Boot = {
index = 1;
type = "uefi";
size = "+1G";
format = fs.fat32;
mountPoint = "/boot";
};
Swap = {
index = 2;
type = "swap";
};
Swap = {
index = 2;
type = "swap";
};
OS = {
index = 3;
type = "linux";
format = fs.ext4;
mountPoint = "/";
OS = {
index = 3;
type = "linux";
format = fs.ext4;
mountPoint = "/";
};
};
};
};
};
i18n = {
localeSettings =
let defaultLocale = "en_US.UTF-8";
in {
LANG = "de_CH.UTF-8";
LANGUAGE = defaultLocale;
LC_MESSAGE = defaultLocale;
};
i18n = {
localeSettings =
let defaultLocale = "en_US.UTF-8";
in {
LANG = "de_CH.UTF-8";
LANGUAGE = defaultLocale;
LC_MESSAGE = defaultLocale;
};
};
};
};
}

View file

@ -4,6 +4,6 @@
];
config = {
partition.os.deviceName = "nvme0n1";
valhalla.partition.os.deviceName = "nvme0n1";
};
}

View file

@ -6,7 +6,7 @@ begin
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 (getConfig partition.rootDir --raw)
set -q ARCH_MOUNT_ROOT || set -l ARCH_MOUNT_ROOT (getConfig valhalla.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
@ -49,7 +49,7 @@ begin
and arch-chroot "$ARCH_MOUNT_ROOT" hwclock --systohc
and begin
getConfig i18n.localeSettings --json | \
getConfig valhalla.i18n.localeSettings --json | \
jq --raw-output '[.[] | split(".") | .[0]] | unique | join("\\\\|")'
end | begin
read LOCALES
@ -57,7 +57,7 @@ begin
end
and begin
getConfig i18n.localeSettings --json | \
getConfig valhalla.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

View file

@ -5,7 +5,7 @@ pushd "${BASH_SOURCE%/*}" > /dev/null;
CONFIG_MODULE="${CONFIG_MODULE:-"./config.nix"}";
ARCH_TIMEZONE="${ARCH_TIMEZONE:-"Europe/Zurich"}";
ARCH_HOSTNAME="${ARCH_HOSTNAME}";
ARCH_MOUNT_ROOT="${ARCH_MOUNT_ROOT:-"$(../../eval-module.sh "$CONFIG_MODULE" partition.rootDir --raw)"}";
ARCH_MOUNT_ROOT="${ARCH_MOUNT_ROOT:-"$(../../eval-module.sh "$CONFIG_MODULE" valhalla.partition.rootDir --raw)"}";
ARCH_LANG="${ARCH_LANG:-"en_US.UTF-8"}";
ARCH_KEYMAP="${ARCH_KEYMAP:-"de_CH-latin1"}";
ARCH_X11_KEYMAP="${ARCH_X11_KEYMAP:-"ch"}";

View file

@ -1,2 +1,2 @@
#!/bin/bash
eval "$("${BASH_SOURCE%/*}/../../eval-module.sh" "$CONFIG_MODULE" partition.script --raw)";
eval "$("${BASH_SOURCE%/*}/../../eval-module.sh" "$CONFIG_MODULE" valhalla.partition.script --raw)";