aboutsummaryrefslogtreecommitdiff
path: root/nixos/yubikey.nix
blob: 868913aeacdd73517be6c20200634f205748fe28 (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
41
42
43
44
45
46
47
48
49
50
51
52
{ config, lib, pkgs, ... }:
let
  cfg = config.nixos.yubikey;
  inherit (lib) types mkOption;
in
{
  options.nixos.yubikey = {
    enable = mkOption {
      type = types.bool;
      default = false;
      description = "enable yubikey support";
    };
  };

  config = lib.mkIf cfg.enable {
    environment.systemPackages = builtins.attrValues {
      inherit (pkgs)
      yubioath-flutter
      yubikey-manager
      pam_u2f
      ;
    };

    programs.yubikey-touch-detector = {
      enable = true;
      libnotify = true;
    };
    # for gpg and ssh
    services.pcscd.enable = true; # https://ludovicrousseau.blogspot.com/2019/06/gnupg-and-pcsc-conflicts.html
    services.udev.packages = [ pkgs.yubikey-personalization ];

    security.pam = {
      u2f = {
        enable = true;
        origin = "pam://yubi";
        settings = {
          # interactive = true;
          interactive = false;
          cue = true;
          authfile = pkgs.writeText "u2f-mappings" (lib.concatStrings [
            config.nixos.username
            ":GB+R91Ur898D/fEgih7f/tsSDOaDw1QcEOSGzHs4fOUo5uCaliIiEK4fFGDClybL/8Qa7tGAN+mo0tU7PVmzfA==,GUPJuYykJoqBw7atGbIK/QcIATgJ3VZQKd1BrjMZ9g/f3nSejOv69LM5UCEoXAwuZHyJitVr1qYd1jLP2uckoQ==,es256,+presence"
          ]);
        };
      };
      services = {
        login.u2fAuth = true;
        sudo.u2fAuth = true;
      };
    };
  };
}