1# Global configuration for yubikey-agent.
2
3{ config, lib, pkgs, ... }:
4
5with lib;
6
7let
8 cfg = config.services.yubikey-agent;
9
10 # reuse the pinentryFlavor option from the gnupg module
11 pinentryFlavor = config.programs.gnupg.agent.pinentryFlavor;
12in
13{
14 ###### interface
15
16 meta.maintainers = with maintainers; [ philandstuff rawkode ];
17
18 options = {
19
20 services.yubikey-agent = {
21 enable = mkOption {
22 type = types.bool;
23 default = false;
24 description = ''
25 Whether to start yubikey-agent when you log in. Also sets
26 SSH_AUTH_SOCK to point at yubikey-agent.
27
28 Note that yubikey-agent will use whatever pinentry is
29 specified in programs.gnupg.agent.pinentryFlavor.
30 '';
31 };
32
33 package = mkOption {
34 type = types.package;
35 default = pkgs.yubikey-agent;
36 defaultText = "pkgs.yubikey-agent";
37 description = ''
38 The package used for the yubikey-agent daemon.
39 '';
40 };
41 };
42 };
43
44 config = mkIf cfg.enable {
45 environment.systemPackages = [ cfg.package ];
46 systemd.packages = [ cfg.package ];
47
48 # This overrides the systemd user unit shipped with the
49 # yubikey-agent package
50 systemd.user.services.yubikey-agent = mkIf (pinentryFlavor != null) {
51 path = [ pkgs.pinentry.${pinentryFlavor} ];
52 };
53
54 environment.extraInit = ''
55 if [ -z "$SSH_AUTH_SOCK" -a -n "$XDG_RUNTIME_DIR" ]; then
56 export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/yubikey-agent/yubikey-agent.sock"
57 fi
58 '';
59 };
60}