Add support for MBR partition IDs

This commit is contained in:
Manuel Thalmann 2024-06-22 22:50:58 +02:00
parent 46820f376f
commit 1f24914de4

View file

@ -68,6 +68,12 @@
(_: if ((!isSwap _) && (_.size == null)) then 1 else 0) (_: if ((!isSwap _) && (_.size == null)) then 1 else 0)
]; ];
mkType = type:
lib.strings.escapeShellArg (
if builtins.isInt type
then "${lib.trivial.toHexString type}"
else type);
fdiskCommand = arguments: "sudo sfdisk ${arguments}"; fdiskCommand = arguments: "sudo sfdisk ${arguments}";
fdiskScript = script: append: "echo ${script} | ${fdiskCommand "${if append then "--append" else ""} ${diskVar}"}"; fdiskScript = script: append: "echo ${script} | ${fdiskCommand "${if append then "--append" else ""} ${diskVar}"}";
wipeScript = script: fdiskScript script false; wipeScript = script: fdiskScript script false;
@ -116,7 +122,7 @@
}; };
create = lib.strings.concatLines [ create = lib.strings.concatLines [
(appendScript "${toString index}: \"$(${sizeOption})\" type=${lib.strings.escapeShellArg type}") (appendScript "${toString index}: \"$(${sizeOption})\" type=${mkType type}")
]; ];
fallback = '' fallback = ''
@ -145,8 +151,8 @@
fixType = lib.strings.concatLines ( fixType = lib.strings.concatLines (
builtins.concatMap builtins.concatMap
(partition: lib.optional (partition: lib.optional
partition.keepExisting (partition.keepExisting && !(builtins.isNull partition.type))
''sudo sfdisk --part-type ${diskVar} ${toString partition.index} ${lib.strings.escapeShellArg partition.type}'') ''sudo sfdisk --part-type ${diskVar} ${toString partition.index} ${mkType partition.type}'')
partitions); partitions);
in { in {
script = '' script = ''