From b6dbf6deed81ee4e2bb75d355ec480f9adb5240a Mon Sep 17 00:00:00 2001 From: r-vdp Date: Sun, 8 Dec 2024 15:40:56 +0300 Subject: [PATCH] nixos/filesystems: assert that the device and label options are consistent --- nixos/modules/tasks/filesystems.nix | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nixos/modules/tasks/filesystems.nix b/nixos/modules/tasks/filesystems.nix index b7d18dfe4173..cb9884aaf29f 100644 --- a/nixos/modules/tasks/filesystems.nix +++ b/nixos/modules/tasks/filesystems.nix @@ -138,7 +138,7 @@ let }; - config.device = lib.mkIf (config.label != null) "/dev/disk/by-label/${escape config.label}"; + config.device = lib.mkIf (config.label != null) (lib.mkDefault "/dev/disk/by-label/${escape config.label}"); config.options = let inInitrd = utils.fsNeededForBoot config; @@ -354,7 +354,15 @@ in options. ''; } - ]; + ] ++ lib.map (fs: { + assertion = fs.label != null -> fs.device == "/dev/disk/by-label/${escape fs.label}"; + message = '' + The filesystem with mount point ${fs.mountPoint} has its label and device set to inconsistent values: + label: ${toString fs.label} + device: ${toString fs.device} + 'filesystems..label' and 'filesystems..device' are mutually exclusive. Please set only one. + ''; + }) fileSystems; # Export for use in other modules system.build.fileSystems = fileSystems;