aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules/autounlock.nix
blob: 2e40bb2c3b6610fa0d8e58b0f5b8ae396f0bb55a (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
37
38
39
40
{ config, lib, pkgs, ... }:

with lib;

let

  cnf = config.cynerd.autounlock;

in {

  options = {
    cynerd.autounlock = mkOption {
      type = with types; attrsOf string;
      default = {};
      description = "Devices to be auto-unlocked.";
    };
  };

  config = mkIf (cnf != {}) {

    environment.systemPackages = [ pkgs.luks-hw-password ];
    boot.initrd = {
      extraFiles."/bin/luks-password" = pkgs.luks-hw-password + "/bin/luks-hw-password";
      luks.devices = mapAttrs (name: value: {
          device = value;
          keyFile = "/keys/${name}.key";
          fallbackToPassword = true;
          preOpenCommands = ''
            mkdir -p /keys
            luks-hw-password > /keys/${name}.key
            '';
          postOpenCommands = ''
            rm -rf /keys
            '';
        }) cnf;
    };

  };

}