summaryrefslogtreecommitdiff
path: root/config/yubikey.nix
blob: 20ed513667bc1f7376bb116f04d5d00321ec1b08 (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
53
54
55
56
57
58
59
60
{ config, lib, pkgs, ... }:
let
  yubikey-pkgs = with pkgs; [
    ccid
    libu2f-host
    libusb
    rng_tools
    yubikey-manager
    yubikey-personalization
    gnupg
    pinentry
    libu2f-host
  ];
in
{
  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 = false;

  # systemd.user.services.gpg-agent = {
  #   path = [ pkgs.gnupg ];
  #   description = "SSH Agent";
  #   wantedBy = [ "default.target" ];
  #   serviceConfig = {
  #     ExecStartPre = ''
  #       ${pkgs.gnupg}/bin/gpgconf --create-socketdir
  #       ${pkgs.coreutils}/bin/rm -f %t/gnupg/S.gpg-agent.ssh
  #     '';
  #     ExecStart =
  #         "${pkgs.gnupg}/bin/gpg-agent --enable-ssh-support --daemon";
  #     Type = "forking";
  #     Restart = "on-failure";
  #   };
  # };

  environment = {
    systemPackages = yubikey-pkgs;

    # Without this, the gpg-agent has no way to ask the user for a password
    # when invoked from ssh.
    # See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=851440
    extraInit = ''
      gpg-connect-agent updatestartuptty /bye
    '';

    # variables = {
    #   SSH_AUTH_SOCK =
    #       ''''${XDG_RUNTIME_DIR:-"/run/user/\$(id -u)"}/gnupg/S.gpg-agent.ssh'';
    # };
  };
}