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 = ''