From 352e06d3da68f0faf600e8f765328751dfe29266 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Sat, 19 Jan 2019 21:44:05 +0100 Subject: [PATCH] installer/tools: Avoid duplicate LUKS device entries in hw config There are situations where several filesystems reside on a single encrypted LUKS device (e.g. when using BTRFS subvolumes). Simply generating a `boot.init.luks.devices.NAME.device` entry for each mounted filesystem will result in an error later when evaluating the nix expression in `hardware-configuration.nix`. --- nixos/modules/installer/tools/nixos-generate-config.pl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl index 52a129b39bcd..bad9356ab5a6 100644 --- a/nixos/modules/installer/tools/nixos-generate-config.pl +++ b/nixos/modules/installer/tools/nixos-generate-config.pl @@ -449,7 +449,11 @@ EOF if (-e $slave) { my $dmName = read_file("/sys/class/block/$deviceName/dm/name"); chomp $dmName; - $fileSystems .= " boot.initrd.luks.devices.\"$dmName\".device = \"${\(findStableDevPath $slave)}\";\n\n"; + # Ensure to add an entry only once + my $luksDevice = " boot.initrd.luks.devices.\"$dmName\".device"; + if ($fileSystems !~ /^\Q$luksDevice\E/m) { + $fileSystems .= "$luksDevice = \"${\(findStableDevPath $slave)}\";\n\n"; + } } } }