aboutsummaryrefslogtreecommitdiff
path: root/nixos/modules/autounlock.nix
blob: 0458c7b1cfecaa723fb407ac5049e3e6e084c2c1 (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."/luks-hw-password".source = pkgs.luks-hw-password;
      luks.devices = mapAttrs (name: value: {
          device = value;
          keyFile = "/keys/${name}.key";
          fallbackToPassword = true;
          preOpenCommands = ''
            mkdir -p /keys
            /luks-hw-password/bin/luks-hw-password > /keys/${name}.key
            '';
          postOpenCommands = ''
            rm -rf /keys
            '';
        }) cnf;
    };

  };

}