summary refs log tree commit diff
path: root/nixos/modules/installer/tools/nixos-generate-config.pl
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-05-25 15:34:37 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-05-25 18:04:41 +0200
commita7baec7cb1539bd82bd458c64994bf476cdfe273 (patch)
treed656c787f3eabfaab78fe431914f1098ac4ca0d9 /nixos/modules/installer/tools/nixos-generate-config.pl
parentc6ab4ab20613150dab0496958e21c14bbe0ca350 (diff)
downloadnixpkgs-a7baec7cb1539bd82bd458c64994bf476cdfe273.tar
nixpkgs-a7baec7cb1539bd82bd458c64994bf476cdfe273.tar.gz
nixpkgs-a7baec7cb1539bd82bd458c64994bf476cdfe273.tar.bz2
nixpkgs-a7baec7cb1539bd82bd458c64994bf476cdfe273.tar.lz
nixpkgs-a7baec7cb1539bd82bd458c64994bf476cdfe273.tar.xz
nixpkgs-a7baec7cb1539bd82bd458c64994bf476cdfe273.tar.zst
nixpkgs-a7baec7cb1539bd82bd458c64994bf476cdfe273.zip
nixos-generate-config: Emit LUKS configuration for boot device
Diffstat (limited to 'nixos/modules/installer/tools/nixos-generate-config.pl')
-rw-r--r--nixos/modules/installer/tools/nixos-generate-config.pl23
1 files changed, 21 insertions, 2 deletions
diff --git a/nixos/modules/installer/tools/nixos-generate-config.pl b/nixos/modules/installer/tools/nixos-generate-config.pl
index ed6c1b2dcd3..ca7fb71ba9b 100644
--- a/nixos/modules/installer/tools/nixos-generate-config.pl
+++ b/nixos/modules/installer/tools/nixos-generate-config.pl
@@ -410,7 +410,7 @@ EOF
 EOF
 
     if (scalar @extraOptions > 0) {
-      $fileSystems .= <<EOF;
+        $fileSystems .= <<EOF;
       options = \[ ${\join " ", map { "\"" . $_ . "\"" } uniq(@extraOptions)} \];
 EOF
     }
@@ -419,6 +419,25 @@ 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";
+                }
+            }
+        }
+    }
 }
 
 
@@ -459,7 +478,7 @@ my $modulePackages = toNixList(uniq @modulePackages);
 
 my $fsAndSwap = "";
 if (!$noFilesystems) {
-    $fsAndSwap = "\n${fileSystems}  ";
+    $fsAndSwap = "\n$fileSystems  ";
     $fsAndSwap .= "swapDevices =" . multiLineList("    ", @swapDevices) . ";\n";
 }