Store device scripts in scripts option

This commit is contained in:
Manuel Thalmann 2024-12-07 17:49:57 +01:00
parent 68e1990c87
commit 7b5564a632

View file

@ -61,9 +61,16 @@ let
default = { }; default = { };
}; };
script = mkOption { scripts = {
init = mkOption {
type = types.str; 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}"; id = "disk-${name}";
deviceVariable = deviceVar; deviceVariable = deviceVar;
deviceScript = scripts = {
init =
if config.path == null then '' if config.path == null then ''
${deviceSelector} ${deviceSelector}
'' else '' '' else ''
@ -191,7 +199,7 @@ let
fi fi
''; '';
script = lib.mkDefault '' partition = lib.mkDefault ''
function partition() { function partition() {
${if (!config.wipe) then cleanup else ""} ${if (!config.wipe) then cleanup else ""}
${probeScript} ${probeScript}
@ -202,6 +210,7 @@ let
partition partition
''; '';
}; };
};
} }
); );
@ -332,8 +341,8 @@ in
partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks); partitions = (builtins.concatMap (_: (builtins.attrValues _.partitions)) disks);
in in
{ {
init = lib.strings.concatLines (builtins.map (_: _.deviceScript) disks); init = lib.strings.concatLines (builtins.map (_: _.scripts.init) disks);
partition = lib.strings.concatLines (builtins.map (_: _.script) disks); partition = lib.strings.concatLines (builtins.map (_: _.scripts.partition) disks);
mount = lib.strings.concatLines ( mount = lib.strings.concatLines (
(builtins.concatMap (builtins.concatMap
( (
@ -360,7 +369,8 @@ in
sudo swapon ${partPath _} sudo swapon ${partPath _}
'' ''
) )
(builtins.filter (_: _.useSwap) partitions))); (builtins.filter (_: _.useSwap) partitions))
);
}; };
}; };
}; };