From 1f24914de4b3610b95c32daafef9559da5fb1b2e Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 22 Jun 2024 22:50:58 +0200 Subject: [PATCH] Add support for MBR partition IDs --- lib/modules/partition.nix | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/modules/partition.nix b/lib/modules/partition.nix index 6949e9ff..4d2db02b 100644 --- a/lib/modules/partition.nix +++ b/lib/modules/partition.nix @@ -68,6 +68,12 @@ (_: 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}"; fdiskScript = script: append: "echo ${script} | ${fdiskCommand "${if append then "--append" else ""} ${diskVar}"}"; wipeScript = script: fdiskScript script false; @@ -116,7 +122,7 @@ }; create = lib.strings.concatLines [ - (appendScript "${toString index}: \"$(${sizeOption})\" type=${lib.strings.escapeShellArg type}") + (appendScript "${toString index}: \"$(${sizeOption})\" type=${mkType type}") ]; fallback = '' @@ -145,8 +151,8 @@ fixType = lib.strings.concatLines ( builtins.concatMap (partition: lib.optional - partition.keepExisting - ''sudo sfdisk --part-type ${diskVar} ${toString partition.index} ${lib.strings.escapeShellArg partition.type}'') + (partition.keepExisting && !(builtins.isNull partition.type)) + ''sudo sfdisk --part-type ${diskVar} ${toString partition.index} ${mkType partition.type}'') partitions); in { script = ''