diff --git a/example/gpt-unformatted.nix b/example/gpt-unformatted.nix new file mode 100644 index 0000000..871e972 --- /dev/null +++ b/example/gpt-unformatted.nix @@ -0,0 +1,36 @@ +# Example to create a GPT partition but doesn't format it +{ + disko.devices = { + disk = { + main = { + device = "/dev/vdb"; + type = "disk"; + content = { + type = "gpt"; + partitions = { + ESP = { + type = "EF00"; + size = "100M"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + empty = { + size = "1G"; + }; + root = { + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/lib/types/gpt.nix b/lib/types/gpt.nix index b547b4d..68f7074 100644 --- a/lib/types/gpt.nix +++ b/lib/types/gpt.nix @@ -26,7 +26,7 @@ in lib.types.either (lib.types.strMatching (hexPattern 4)) (lib.types.strMatching (lib.concatMapStringsSep "-" hexPattern [ 8 4 4 4 12 ])); - default = if partition.config.content.type == "swap" then "8200" else "8300"; + default = if partition.config.content != null && partition.config.content.type == "swap" then "8200" else "8300"; defaultText = ''8300 (Linux filesystem) normally, 8200 (Linux swap) if content.type is "swap"''; description = '' Filesystem type to use. diff --git a/tests/gpt-unformatted.nix b/tests/gpt-unformatted.nix new file mode 100644 index 0000000..9c75f46 --- /dev/null +++ b/tests/gpt-unformatted.nix @@ -0,0 +1,11 @@ +{ pkgs ? import { } +, diskoLib ? pkgs.callPackage ../lib { } +}: +diskoLib.testLib.makeDiskoTest { + inherit pkgs; + name = "gpt-unformatted"; + disko-config = ../example/gpt-unformatted.nix; + extraTestScript = '' + machine.succeed("mountpoint /"); + ''; +}