2010-10-25 00:57:30 +00:00
|
|
|
{pkgs, config, ...}:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
luksRoot = config.boot.initrd.luksRoot;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
boot.initrd.luksRoot = mkOption {
|
2010-10-25 22:21:51 +00:00
|
|
|
default = "";
|
2010-10-25 00:57:30 +00:00
|
|
|
example = "/dev/sda3";
|
|
|
|
description = '';
|
|
|
|
The device 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.
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2010-10-25 00:57:30 +00:00
|
|
|
Make sure that initrd has the crypto modules needed for decryption.
|
|
|
|
|
|
|
|
The decrypted device name is /dev/mapper/luksroot.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-25 22:21:51 +00:00
|
|
|
config = mkIf (luksRoot != "") {
|
2010-10-25 00:57:30 +00:00
|
|
|
|
2011-12-28 21:46:40 +00:00
|
|
|
# copy the cryptsetup binary and it's dependencies
|
2010-10-25 00:57:30 +00:00
|
|
|
boot.initrd.extraUtilsCommands = ''
|
2011-12-28 21:46:40 +00:00
|
|
|
cp -pdv ${pkgs.cryptsetup}/sbin/cryptsetup $out/bin
|
|
|
|
# XXX: do we have a function that does this?
|
|
|
|
for lib in $(ldd $out/bin/cryptsetup |grep '=>' |grep /nix/store/ |cut -d' ' -f3); do
|
|
|
|
cp -pdvn $lib $out/lib
|
|
|
|
cp -pvn $(readlink -f $lib) $out/lib
|
|
|
|
done
|
|
|
|
'';
|
|
|
|
|
|
|
|
boot.initrd.extraUtilsCommandsTest = ''
|
|
|
|
$out/bin/cryptsetup --version
|
|
|
|
$out/bin/lvm vgscan --version
|
|
|
|
$out/bin/lvm vgchange --version
|
2010-10-25 00:57:30 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
boot.initrd.postDeviceCommands = ''
|
|
|
|
cryptsetup luksOpen ${luksRoot} luksroot
|
|
|
|
lvm vgscan
|
|
|
|
lvm vgchange -ay
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-09-14 18:20:50 +00:00
|
|
|
}
|