blob: aca217e5c09c9b7c6db56875c0431672a3695239 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
{
config,
lib,
modulesPath,
pkgs,
...
}:
{
imports = [ (modulesPath + "/profiles/all-hardware.nix") ];
options.usbauth = lib.mkOption {
description = "USB Auth";
type = lib.types.submodule {
options = lib.mkOption {
device = lib.types.str;
keyname = lib.types.str;
uuid = lib.types.str;
};
};
};
config = {
boot.initrd.postDeviceCommands = pkgs.lib.mkBefore ''
mkdir -m 0755 -p /key
lsblk -o NAME,UUID
while ! findfs UUID=${config.usbauth.uuid} 2> /dev/null; do sleep 0.1; done
cryptsetup open $(findfs UUID=${config.usbauth.uuid}) _key
mount -o ro "/dev/mapper/_key" /key
'';
boot.initrd.luks.devices."${config.usbauth.device
}".keyFile = "/key/.keys/${config.usbauth.keyname}";
boot.initrd.luks.devices."${config.usbauth.device}".preLVM = false;
};
}
|