From 4e3542ce03f36e580e69b6c37d815cf7ea532da6 Mon Sep 17 00:00:00 2001 From: Sergey Kazenyuk Date: Fri, 6 Sep 2024 03:39:43 +0300 Subject: [PATCH 1/2] gpt: add partition attributes --- lib/types/gpt.nix | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/types/gpt.nix b/lib/types/gpt.nix index cb5e2b49..611494de 100644 --- a/lib/types/gpt.nix +++ b/lib/types/gpt.nix @@ -57,6 +57,27 @@ in or a fully specified GUID (see https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs). ''; }; + attributes = lib.mkOption { + type = lib.types.listOf lib.types.int; + default = [ ]; + description = '' + GPT partition entry attributes, according to UEFI specification + 2.10 (see https://uefi.org/specs/UEFI/2.10_A/05_GUID_Partition_Table_Format.html#defined-gpt-partition-entry-attributes) + and `sgdisk`s man page: + + - 0: Required Partition (`sgdisk`: system partition) + - 1: No Block IO Protocol (`sgdisk`: hide from EFI) + - 2: Legacy BIOS Bootable + - 3-47: Undefined and must be zero, reserved for future use + - 48-63: Reserved for GUID specific use. The use of these bits + will vary depending on the partition type + + `sgdisk` describes some of the GUID-specific bits this way: + - 60: read only + - 62: hidden + - 63: do not automount + ''; + }; device = lib.mkOption { type = lib.types.str; default = @@ -268,6 +289,14 @@ in }" \ --change-name="${toString partition._index}:${partition.label}" \ --typecode=${toString partition._index}:${partition.type} \ + --attributes=${toString partition._index}:=:0 \ + ${ + lib.concatStringsSep " \\\n" ( + builtins.map (bitNumber: "--attributes=${toString partition._index}:set:${toString bitNumber}") ( + lib.unique partition.attributes + ) + ) + } \ "${config.device}" \ ''; createArgs = '' From c56f45eceea173c6c7d6cf9d262a2b88c17f5820 Mon Sep 17 00:00:00 2001 From: Yifei Sun Date: Sun, 7 Sep 2025 15:29:18 +0200 Subject: [PATCH 2/2] examples: gpt partition attributes cherry-picked from https://github.com/nvmd/disko/commit/9dc58d4d49c9f74623a06e2fc20cdfd8bb3cbe8b usage example: - set attribute: https://github.com/nvmd/nixos-raspberrypi-demo/blob/2847963e7555fc412c1d0f37bb48c761e78f350d/disko-nvme-zfs.nix#L9L11 - check: https://github.com/nvmd/nixos-raspberrypi-demo/blob/2847963e7555fc412c1d0f37bb48c761e78f350d/flake.nix#L154L160 --- example/gpt-bios-compat.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/example/gpt-bios-compat.nix b/example/gpt-bios-compat.nix index 4be1942b..d3955ebf 100644 --- a/example/gpt-bios-compat.nix +++ b/example/gpt-bios-compat.nix @@ -11,6 +11,7 @@ boot = { size = "1M"; type = "EF02"; # for grub MBR + attributes = [ 0 ]; # partition attribute }; root = { size = "100%";