types gpt: sort after priority. add size option

This commit is contained in:
lassulus 2023-06-17 09:07:14 +02:00 committed by mergify[bot]
parent 95c10a6c7f
commit 64c9c78c15
2 changed files with 16 additions and 6 deletions

View file

@ -9,8 +9,7 @@
partitions = { partitions = {
ESP = { ESP = {
type = "EF00"; type = "EF00";
start = "1M"; size = "100M";
end = "+100M";
content = { content = {
type = "filesystem"; type = "filesystem";
format = "vfat"; format = "vfat";
@ -18,7 +17,7 @@
}; };
}; };
root = { root = {
end = "-0"; size = "100%";
content = { content = {
type = "filesystem"; type = "filesystem";
format = "ext4"; format = "ext4";

View file

@ -16,8 +16,8 @@
}; };
priority = lib.mkOption { priority = lib.mkOption {
type = lib.types.int; type = lib.types.int;
default = 1000; default = if (partition.config.size or "" == "100%") then 9001 else 1000;
description = "Priority of the partition, higher priority partitions are created first"; description = "Priority of the partition, smaller values are created first";
}; };
name = lib.mkOption { name = lib.mkOption {
type = lib.types.str; type = lib.types.str;
@ -28,6 +28,15 @@
type = lib.types.str; type = lib.types.str;
default = "${config._parent.type}-${config._parent.name}-${partition.name}"; default = "${config._parent.type}-${config._parent.name}-${partition.name}";
}; };
size = lib.mkOption {
type = lib.types.either (lib.types.enum [ "100%" ]) (lib.types.strMatching "[0-9]+[KMGTP]?");
default = "0";
description = ''
Size of the partition, in sgdisk format.
sets end automatically with the + prefix
can be 100% for the whole remaining disk, will be done last in that case.
'';
};
start = lib.mkOption { start = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = "0"; default = "0";
@ -35,6 +44,7 @@
}; };
end = lib.mkOption { end = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = if partition.config.size == "100%" then "-0" else "+${partition.config.size}";
description = '' description = ''
End of the partition, in sgdisk format. End of the partition, in sgdisk format.
Use + for relative sizes from the partitons start Use + for relative sizes from the partitons start
@ -75,7 +85,8 @@
# ensure /dev/disk/by-path/..-partN exists before continuing # ensure /dev/disk/by-path/..-partN exists before continuing
udevadm trigger --subsystem-match=block; udevadm settle udevadm trigger --subsystem-match=block; udevadm settle
${lib.optionalString (partition.content != null) (partition.content._create { dev = "/dev/disk/by-partlabel/${partition.label}"; })} ${lib.optionalString (partition.content != null) (partition.content._create { dev = "/dev/disk/by-partlabel/${partition.label}"; })}
'') (lib.attrValues config.partitions))} '') (lib.sort (x: y: x.priority < y.priority) (lib.attrValues config.partitions)))}
''; '';
}; };
_mount = diskoLib.mkMountOption { _mount = diskoLib.mkMountOption {