Allow specifying mountpaths and swap usage

This commit is contained in:
Manuel Thalmann 2024-06-22 20:45:15 +02:00
parent 9c4b00f1fb
commit 32b1b37b1d

View file

@ -209,6 +209,18 @@
description = "A script for printing the size to the console."; description = "A script for printing the size to the console.";
internal = true; internal = true;
}; };
useSwap = mkOption {
type = types.bool;
description = "A value indicating whether this partition should be used as swap.";
default = isSwap config;
};
mountPoint = mkOption {
type = types.nullOr types.str;
description = "The mountpoint of the partition.";
default = null;
};
}; };
config = { config = {
@ -225,6 +237,12 @@
in { in {
options = { options = {
partition = { partition = {
rootDir = mkOption {
type = types.str;
description = "The root of the installation directory to mount disks into.";
default = "/mnt";
};
os = mkOption { os = mkOption {
type = mkDiskType true; type = mkDiskType true;
description = "The partition layout of the OS disk."; description = "The partition layout of the OS disk.";
@ -270,11 +288,32 @@
script = script =
let let
inherit (config.partition) inherit (config.partition) os rootDir;
os inherit (lib.strings) normalizePath;
disks
; partPath = part: "/dev/disk/by-label/${part.label}";
in lib.strings.concatLines (builtins.map (_: _.script) ([os] ++ (builtins.attrValues disks))); disks = ([os] ++ (builtins.attrValues config.partition.disks));
partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks);
mountScript = lib.strings.concatLines (
builtins.map
(_: builtins.concatStringsSep " " [
"mount"
(partPath _)
(normalizePath "/${rootDir}/${_.mountPoint}")
])
(builtins.filter (_: _.mountPoint != null) partitions));
swapScript = lib.strings.concatLines (
builtins.map
(_: "swapon ${partPath _}")
(builtins.filter (_: _.useSwap) partitions));
in lib.strings.concatLines (
(builtins.map (_: _.script) disks) ++ [
mountScript
swapScript
]
);
}; };
}; };
} }