2010-10-25 02:57:30 +02:00
|
|
|
{pkgs, config, ...}:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
luksRoot = config.boot.initrd.luksRoot;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
boot.initrd.luksRoot = mkOption {
|
2010-10-26 00:21:51 +02:00
|
|
|
default = "";
|
2010-10-25 02:57:30 +02: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 20:20:50 +02:00
|
|
|
|
2010-10-25 02:57:30 +02:00
|
|
|
Make sure that initrd has the crypto modules needed for decryption.
|
|
|
|
|
|
|
|
The decrypted device name is /dev/mapper/luksroot.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-26 00:21:51 +02:00
|
|
|
config = mkIf (luksRoot != "") {
|
2010-10-25 02:57:30 +02:00
|
|
|
|
2011-12-28 22:46:40 +01:00
|
|
|
# copy the cryptsetup binary and it's dependencies
|
2010-10-25 02:57:30 +02:00
|
|
|
boot.initrd.extraUtilsCommands = ''
|
2011-12-28 22:46:40 +01: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 = ''
|
2011-12-28 23:37:38 +01:00
|
|
|
$out/bin/cryptsetup --version
|
2010-10-25 02:57:30 +02:00
|
|
|
'';
|
|
|
|
|
2011-12-28 22:46:48 +01:00
|
|
|
boot.initrd.preLVMCommands = ''
|
2011-12-28 22:46:42 +01:00
|
|
|
# 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.
|
|
|
|
if ! test -e ${luksRoot}; then
|
|
|
|
echo -n "waiting for device ${luksRoot} to appear..."
|
|
|
|
for ((try = 0; try < 10; try++)); do
|
|
|
|
sleep 1
|
|
|
|
if test -e ${luksRoot}; then break; fi
|
|
|
|
echo -n "."
|
|
|
|
done
|
|
|
|
echo "ok"
|
|
|
|
fi
|
|
|
|
# open luksRoot and scan for logical volumes
|
2010-10-25 02:57:30 +02:00
|
|
|
cryptsetup luksOpen ${luksRoot} luksroot
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
}
|