summaryrefslogtreecommitdiff
path: root/modules/yubikey.nix
blob: b171408a71b6644e989a4cbbea3ad9042f404df8 (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
{ config, lib, pkgs, ... }:
let
  cfg = config.orbekk.yubikey;

  yubikey-pkgs = with pkgs; [
    ccid
    libu2f-host
    libusb
    rng-tools
    yubikey-manager
    yubikey-personalization
    gnupg
    pinentry
  ];
in
{
  options = {
    orbekk.yubikey = {
      enable = lib.mkEnableOption "Enable yubikey config";
    };
  };

  config = lib.mkIf cfg.enable {
    services.pcscd.enable = true;
    services.udev.packages = with pkgs; [
      libu2f-host
      yubikey-personalization
    ];

    programs.gnupg.agent = {
      enable = true;
      enableSSHSupport = true;
    };
    # Use GPG agent instead.
    programs.ssh.startAgent = lib.mkDefault false;

    environment = {
      systemPackages = yubikey-pkgs;
    };

    security.sudo.extraRules = [
      {
        groups = [ "wheel" ];
        commands = [ { command = "${pkgs.systemd}/bin/systemctl restart pcscd"; options = [ "NOPASSWD" ]; } ];
      }
    ];
  };
}