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.";
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 = {
@ -225,6 +237,12 @@
in {
options = {
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.";
@ -270,11 +288,32 @@
script =
let
inherit (config.partition)
os
disks
;
in lib.strings.concatLines (builtins.map (_: _.script) ([os] ++ (builtins.attrValues disks)));
inherit (config.partition) 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);
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
]
);
};
};
}