at 23.11-pre 1.9 kB view raw
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 jwoudenberg ]; 17 18 options = { 19 20 services.yubikey-agent = { 21 enable = mkOption { 22 type = types.bool; 23 default = false; 24 description = lib.mdDoc '' 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 = literalExpression "pkgs.yubikey-agent"; 37 description = lib.mdDoc '' 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 wantedBy = [ 53 (if pinentryFlavor == "tty" || pinentryFlavor == "curses" then 54 "default.target" 55 else 56 "graphical-session.target") 57 ]; 58 }; 59 60 # Yubikey-agent expects pcsd to be running in order to function. 61 services.pcscd.enable = true; 62 63 environment.extraInit = '' 64 if [ -z "$SSH_AUTH_SOCK" -a -n "$XDG_RUNTIME_DIR" ]; then 65 export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/yubikey-agent/yubikey-agent.sock" 66 fi 67 ''; 68 }; 69}