diff --git a/nixos/modules/security/ssh-agent.nix b/nixos/modules/security/ssh-agent.nix new file mode 100644 index 0000000000000..271383e4ee62e --- /dev/null +++ b/nixos/modules/security/ssh-agent.nix @@ -0,0 +1,26 @@ +{ config, pkgs, lib, ... }: +let + cfg = config.security.SSHAgent; +in { + + options = { + security.SSHAgent = { + socket = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + description = "The path to the SSH agent socket"; + }; + }; + }; + + + config = lib.mkIf cfg.socket != null { + environment.extraInit = '' + if [ -z "$SSH_AUTH_SOCK" -a -n "$XDG_RUNTIME_DIR" ]; then + export SSH_AUTH_SOCK=${cfg.socket} + fi + ''; + }; + + +} \ No newline at end of file diff --git a/nixos/modules/services/desktops/gnome/gnome-keyring.nix b/nixos/modules/services/desktops/gnome/gnome-keyring.nix index 79bce0ade2fc5..1c66fdf5d8005 100644 --- a/nixos/modules/services/desktops/gnome/gnome-keyring.nix +++ b/nixos/modules/services/desktops/gnome/gnome-keyring.nix @@ -1,7 +1,9 @@ # GNOME Keyring daemon. { config, pkgs, lib, ... }: - +let + cfg = config.services.gnome.gnome-keyring; +in { meta = { @@ -24,6 +26,8 @@ ''; }; + SSHSupport.enable = lib.mkEnableOption "SSH agent support for GNOME Keyring by setting the SSH_AUTH_SOCK environment variable"; + }; }; @@ -31,7 +35,7 @@ ###### implementation - config = lib.mkIf config.services.gnome.gnome-keyring.enable { + config = lib.mkIf cfg.enable { environment.systemPackages = [ pkgs.gnome.gnome-keyring ]; @@ -48,6 +52,8 @@ source = "${pkgs.gnome.gnome-keyring}/bin/gnome-keyring-daemon"; }; + security.SSHAgent.socket = lib.mkIf cfg.SSHSupport.enable "$XDG_RUNTIME_DIR/keyring/ssh"; + }; }