summary refs log tree commit diff
path: root/modules/system
diff options
context:
space:
mode:
authorLluís Batlle i Rossell <viric@vicerveza.homeunix.net>2012-03-04 21:00:35 +0000
committerLluís Batlle i Rossell <viric@vicerveza.homeunix.net>2012-03-04 21:00:35 +0000
commit1adaabef58076b645b9393aa20819c2d897795b3 (patch)
tree7f74ac9b53a83fdf03c46b74a09b399fb901f2f1 /modules/system
parent0d4eb37e16dc44f2df7b048de1a48fab33a7d97f (diff)
downloadnixpkgs-1adaabef58076b645b9393aa20819c2d897795b3.tar
nixpkgs-1adaabef58076b645b9393aa20819c2d897795b3.tar.gz
nixpkgs-1adaabef58076b645b9393aa20819c2d897795b3.tar.bz2
nixpkgs-1adaabef58076b645b9393aa20819c2d897795b3.tar.lz
nixpkgs-1adaabef58076b645b9393aa20819c2d897795b3.tar.xz
nixpkgs-1adaabef58076b645b9393aa20819c2d897795b3.tar.zst
nixpkgs-1adaabef58076b645b9393aa20819c2d897795b3.zip
Adding an option to luksroot, so it allows to define whether to launch cryptsetup after or before LVM.
To allow dmcrypt over lvm and lvm over dmcrypt.


svn path=/nixos/trunk/; revision=32784
Diffstat (limited to 'modules/system')
-rw-r--r--modules/system/boot/luksroot.nix43
1 files changed, 39 insertions, 4 deletions
diff --git a/modules/system/boot/luksroot.nix b/modules/system/boot/luksroot.nix
index 098641b6cb6..398b6a6a660 100644
--- a/modules/system/boot/luksroot.nix
+++ b/modules/system/boot/luksroot.nix
@@ -5,7 +5,7 @@ with pkgs.lib;
 let
   luks = config.boot.initrd.luks;
 
-  openCommand = { name, device }: ''
+  openCommand = { name, device, ... }: ''
     # Wait for luksRoot to appear, e.g. if on a usb drive.
     # XXX: copied and adapted from stage-1-init.sh - should be
     # available as a function.
@@ -14,7 +14,7 @@ let
         for ((try = 0; try < 10; try++)); do
             sleep 1
             if test -e ${device}; then break; fi
-            echo -n "OK"
+            echo -n .
         done
         echo "ok"
     fi
@@ -23,6 +23,10 @@ let
     cryptsetup luksOpen ${device} ${name}
   '';
 
+  isPreLVM = f: f.preLVM;
+  preLVM = filter isPreLVM luks.devices;
+  postLVM = filter (f: !(isPreLVM f)) luks.devices;
+
 in
 {
 
@@ -36,7 +40,7 @@ in
 
     boot.initrd.luks.devices = mkOption {
       default = [ ];
-      example = [ { name = "luksroot"; device = "/dev/sda3"; } ];
+      example = [ { name = "luksroot"; device = "/dev/sda3"; preLVM = true; } ];
       description = '';
         The list of devices that should be decrypted using LUKS before trying to mount the
         root partition. This works for both LVM-over-LUKS and LUKS-over-LVM setups.
@@ -45,6 +49,36 @@ in
 
         Make sure that initrd has the crypto modules needed for decryption.
       '';
+
+      type = types.list types.optionSet;
+
+      options = {
+
+        name = mkOption {
+          example = "luksroot";
+          type = types.string;
+          description = ''
+            Name of the interface.
+          '';
+        };
+
+        device = mkOption {
+          example = "/dev/sda2";
+          type = types.string;
+          description = ''
+            IP address of the interface.  Leave empty to configure the
+            interface using DHCP.
+          '';
+        };
+
+        preLVM = mkOption {
+          default = true;
+          type = types.bool;
+          description = ''
+            Whether the luksOpen will be attempted before LVM scan or after it.
+          '';
+        };
+      };
     };
   };
 
@@ -68,6 +102,7 @@ in
       $out/bin/cryptsetup --version
     '';
 
-    boot.initrd.preLVMCommands = concatMapStrings openCommand luks.devices;
+    boot.initrd.preLVMCommands = concatMapStrings openCommand preLVM;
+    boot.initrd.postDeviceCommands = concatMapStrings openCommand postLVM;
   };
 }