From 56f6d3d4af2c61c050a4f940c37a6f6f30f51553 Mon Sep 17 00:00:00 2001 From: lassulus Date: Mon, 4 Mar 2024 01:50:21 +0100 Subject: [PATCH] types gpt: hash label if it's > 36 characters --- lib/types/gpt.nix | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/types/gpt.nix b/lib/types/gpt.nix index 1b47020..5a70f07 100644 --- a/lib/types/gpt.nix +++ b/lib/types/gpt.nix @@ -55,7 +55,15 @@ in }; label = lib.mkOption { type = lib.types.str; - default = "${config._parent.type}-${config._parent.name}-${partition.config.name}"; + default = let + # 72 bytes is the maximum length of a GPT partition name + # the labels seem to be in UTF-16, so 2 bytes per character + limit = 36; + label = "${config._parent.type}-${config._parent.name}-${partition.config.name}"; + in if (lib.stringLength label) > limit then + builtins.substring 0 limit (builtins.hashString "sha256" label) + else + label; }; size = lib.mkOption { type = lib.types.either (lib.types.enum [ "100%" ]) (lib.types.strMatching "[0-9]+[KMGTP]?");