From a73b04f56b7c178d5cd33d49309450e55d90cbad Mon Sep 17 00:00:00 2001
From: Manuel Thalmann <m@nuth.ch>
Date: Sat, 22 Jun 2024 20:00:25 +0200
Subject: [PATCH] Allow automated labelling of partitions

---
 lib/modules/partition.nix | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/modules/partition.nix b/lib/modules/partition.nix
index f1428df1..16c0e246 100644
--- a/lib/modules/partition.nix
+++ b/lib/modules/partition.nix
@@ -88,6 +88,7 @@
                     format
                     index
                     keepExisting
+                    label
                     sizeScript
                     type
                   ;
@@ -102,6 +103,12 @@
                     ${fs.fat32} = "mkfs.fat -F 32 ${diskVar}";
                   };
 
+                  labelScripts = {
+                    ${fs.ext4} = label: "e2label ${diskVar} ${label}";
+                    ${fs.ntfs} = label: "ntfslabel ${diskVar} ${label}";
+                    ${fs.fat32} = label: "fatlabel ${diskVar} ${label}";
+                  };
+
                   create = lib.strings.concatLines [
                     (appendScript "${toString index}: \"$(${sizeOption})\" type=${lib.strings.escapeShellArg type}")
                     formatScripts.${format}
@@ -115,6 +122,7 @@
                   '';
                 in [
                   (if keepExisting then fallback else create)
+                  (labelScripts.${format} label)
                 ])
               partitions)
           );