From 3e83c1103855ea50fffc573277d5c680f357d8e3 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 25 Nov 2024 02:10:48 +0000 Subject: [PATCH] Fix evaluation when a GPT partition is left unformatted --- example/gpt-unformatted.nix | 36 ++++++++++++++++++++++++++++++++++++ lib/types/gpt.nix | 2 +- tests/gpt-unformatted.nix | 11 +++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 example/gpt-unformatted.nix create mode 100644 tests/gpt-unformatted.nix 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 /"); + ''; +}