nixos-generate-config: Emit LUKS configuration for boot device

+23 -4
+2 -2
nixos/doc/manual/man-nixos-generate-config.xml
··· 113 113 <varlistentry> 114 114 <term><option>--no-filesystems</option></term> 115 115 <listitem> 116 - <para>Omit everything concerning file system information 117 - (which includes swap devices) from the hardware configuration.</para> 116 + <para>Omit everything concerning file systems and swap devices 117 + from the hardware configuration.</para> 118 118 </listitem> 119 119 </varlistentry> 120 120
+21 -2
nixos/modules/installer/tools/nixos-generate-config.pl
··· 410 410 EOF 411 411 412 412 if (scalar @extraOptions > 0) { 413 - $fileSystems .= <<EOF; 413 + $fileSystems .= <<EOF; 414 414 options = \[ ${\join " ", map { "\"" . $_ . "\"" } uniq(@extraOptions)} \]; 415 415 EOF 416 416 } ··· 419 419 }; 420 420 421 421 EOF 422 + 423 + # If this filesystem is on a LUKS device, then add a 424 + # boot.initrd.luks.devices entry. 425 + if (-e $device) { 426 + my $deviceName = basename(abs_path($device)); 427 + if (-e "/sys/class/block/$deviceName" 428 + && read_file("/sys/class/block/$deviceName/dm/uuid", err_mode => 'quiet') =~ /^CRYPT-LUKS/) 429 + { 430 + my @slaves = glob("/sys/class/block/$deviceName/slaves/*"); 431 + if (scalar @slaves == 1) { 432 + my $slave = "/dev/" . basename($slaves[0]); 433 + if (-e $slave) { 434 + my $dmName = read_file("/sys/class/block/$deviceName/dm/name"); 435 + chomp $dmName; 436 + $fileSystems .= " boot.initrd.luks.devices.\"$dmName\".device = \"${\(findStableDevPath $slave)}\";\n\n"; 437 + } 438 + } 439 + } 440 + } 422 441 } 423 442 424 443 ··· 459 478 460 479 my $fsAndSwap = ""; 461 480 if (!$noFilesystems) { 462 - $fsAndSwap = "\n${fileSystems} "; 481 + $fsAndSwap = "\n$fileSystems "; 463 482 $fsAndSwap .= "swapDevices =" . multiLineList(" ", @swapDevices) . ";\n"; 464 483 } 465 484