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

Changed files
+23 -4
nixos
doc
modules
installer
+2 -2
nixos/doc/manual/man-nixos-generate-config.xml
···
<varlistentry>
<term><option>--no-filesystems</option></term>
<listitem>
-
<para>Omit everything concerning file system information
-
(which includes swap devices) from the hardware configuration.</para>
</listitem>
</varlistentry>
···
<varlistentry>
<term><option>--no-filesystems</option></term>
<listitem>
+
<para>Omit everything concerning file systems and swap devices
+
from the hardware configuration.</para>
</listitem>
</varlistentry>
+21 -2
nixos/modules/installer/tools/nixos-generate-config.pl
···
EOF
if (scalar @extraOptions > 0) {
-
$fileSystems .= <<EOF;
options = \[ ${\join " ", map { "\"" . $_ . "\"" } uniq(@extraOptions)} \];
EOF
}
···
};
EOF
}
···
my $fsAndSwap = "";
if (!$noFilesystems) {
-
$fsAndSwap = "\n${fileSystems} ";
$fsAndSwap .= "swapDevices =" . multiLineList(" ", @swapDevices) . ";\n";
}
···
EOF
if (scalar @extraOptions > 0) {
+
$fileSystems .= <<EOF;
options = \[ ${\join " ", map { "\"" . $_ . "\"" } uniq(@extraOptions)} \];
EOF
}
···
};
EOF
+
+
# If this filesystem is on a LUKS device, then add a
+
# boot.initrd.luks.devices entry.
+
if (-e $device) {
+
my $deviceName = basename(abs_path($device));
+
if (-e "/sys/class/block/$deviceName"
+
&& read_file("/sys/class/block/$deviceName/dm/uuid", err_mode => 'quiet') =~ /^CRYPT-LUKS/)
+
{
+
my @slaves = glob("/sys/class/block/$deviceName/slaves/*");
+
if (scalar @slaves == 1) {
+
my $slave = "/dev/" . basename($slaves[0]);
+
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";
+
}
+
}
+
}
+
}
}
···
my $fsAndSwap = "";
if (!$noFilesystems) {
+
$fsAndSwap = "\n$fileSystems ";
$fsAndSwap .= "swapDevices =" . multiLineList(" ", @swapDevices) . ";\n";
}