Store device scripts in scripts option

This commit is contained in:
Manuel Thalmann 2024-12-07 17:49:57 +01:00
parent 25ba2fbe8a
commit f9af3388a7

View file

@ -61,9 +61,16 @@ let
default = { };
};
script = mkOption {
scripts = {
init = mkOption {
type = types.str;
description = "The script for formatting the disk.";
description = "A script for loading the device path into the device variable";
};
partition = mkOption {
type = types.str;
description = "A script for partitioning and formatting the device.";
};
};
};
@ -172,7 +179,8 @@ let
id = "disk-${name}";
deviceVariable = deviceVar;
deviceScript =
scripts = {
init =
if config.path == null then ''
${deviceSelector}
'' else ''
@ -191,7 +199,7 @@ let
fi
'';
script = lib.mkDefault ''
partition = lib.mkDefault ''
function partition() {
${if (!config.wipe) then cleanup else ""}
${probeScript}
@ -202,6 +210,7 @@ let
partition
'';
};
};
}
);
@ -332,8 +341,8 @@ in
partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks);
in
{
init = lib.strings.concatLines (builtins.map (_: _.deviceScript) disks);
partition = lib.strings.concatLines (builtins.map (_: _.script) disks);
init = lib.strings.concatLines (builtins.map (_: _.scripts.init) disks);
partition = lib.strings.concatLines (builtins.map (_: _.scripts.partition) disks);
mount = lib.strings.concatLines (
(builtins.concatMap
(
@ -360,7 +369,8 @@ in
sudo swapon ${partPath _}
''
)
(builtins.filter (_: _.useSwap) partitions)));
(builtins.filter (_: _.useSwap) partitions))
);
};
};
};