Store disk paths in an associative array

This commit is contained in:
Manuel Thalmann 2024-07-06 22:20:33 +02:00
parent be3c6c54b1
commit 85763017f1

View file

@ -2,7 +2,6 @@
let
inherit (lib) types mkOption;
diskVarName = "myDisk";
diskVar = ''''${${diskVarName}}'';
isSwap = partition: builtins.elem partition.type ["swap" 19];
fs = {
@ -20,6 +19,12 @@
mkDiskType = osDisk: types.submodule (
{ config, name, ... }: {
options = {
id = mkOption {
type = types.str;
description = "The internal identifier of the disk.";
internal = true;
};
wipe = mkOption {
type = types.bool;
description = "A value indicating whether the disk should be wiped.";
@ -65,6 +70,8 @@
config =
let
diskVar = ''''${${diskVarName}[${config.id}]}'';
partitions = builtins.foldl'
(list: predicate: lib.lists.sortOn predicate list)
(builtins.filter (_: _ != null) (builtins.attrValues config.partitions))
@ -161,6 +168,8 @@
''sudo sfdisk --part-type ${diskVar} ${toString partition.index} ${mkType partition.type}'')
partitions);
in {
id = if osDisk then "os" else "disk-${name}";
deviceScript = if osDisk && config.devicePath == null then ''
${diskSelector}
''