git.iko.soy/typeable/nixpkgs
on master help sign in
nixos-generate-config: Emit LUKS configuration for boot device
commita7baec7cb1539bd82bd458c64994bf476cdfe273 authorEelco Dolstra <eelco.dolstra@logicblox.com> dateWed 25 May 2016, 15:34 (11 years ago) parentc6ab4ab
2 files changed+23−4
nixos/doc/manual/man-nixos-generate-config.xml+2−2 nixos/modules/installer/tools/nixos-generate-config.pl+21−2
nixos/doc/manual/man-nixos-generate-config.xml+2−2
@@ -113,8 +113,8 @@
113113 <varlistentry>
114114 <term><option>--no-filesystems</option></term>
115115 <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>
118118 </listitem>
119119 </varlistentry>
120120
nixos/modules/installer/tools/nixos-generate-config.pl+21−2
@@ -410,7 +410,7 @@ EOF
410410EOF
411411
412412 if (scalar @extraOptions > 0) {
413− $fileSystems .= <<EOF;
413+ $fileSystems .= <<EOF;
414414 options = \[ ${\join " ", map { "\"" . $_ . "\"" } uniq(@extraOptions)} \];
415415EOF
416416 }
@@ -419,6 +419,25 @@ EOF
419419 };
420420
421421EOF
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+ }
422441}
423442
424443
@@ -459,7 +478,7 @@ my $modulePackages = toNixList(uniq @modulePackages);
459478
460479my $fsAndSwap = "";
461480if (!$noFilesystems) {
462− $fsAndSwap = "\n${fileSystems} ";
481+ $fsAndSwap = "\n$fileSystems ";
463482 $fsAndSwap .= "swapDevices =" . multiLineList(" ", @swapDevices) . ";\n";
464483}
465484