Add rbw SSH socket support in home-manager modules

- Introduced a new module `rbw-ssh-socket.nix` to manage SSH_AUTH_SOCK for rbw.
- Updated `default.nix` to utilize the new SSH socket variable for session management.
- Refactored Bash and Fish shell configurations to use the new module for setting SSH_AUTH_SOCK, improving maintainability and consistency across shell environments.
This commit is contained in:
2026-06-22 12:28:25 -03:00
parent 1524100ff5
commit 3b5c031619
4 changed files with 39 additions and 31 deletions
+30
View File
@@ -0,0 +1,30 @@
{ ... }: {
flake.lib.rbwSshSocket =
let
bashSnippet = ''
if [ -z "''${SSH_AUTH_SOCK:-}" ]; then
if [ -n "''${XDG_RUNTIME_DIR:-}" ]; then
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/rbw/ssh-agent-socket"
else
export SSH_AUTH_SOCK="/run/user/$(id -u)/rbw/ssh-agent-socket"
fi
fi
'';
fishSnippet =
pkgs: ''
if test -z "$SSH_AUTH_SOCK"
if test -n "$XDG_RUNTIME_DIR"
set -gx SSH_AUTH_SOCK "$XDG_RUNTIME_DIR/rbw/ssh-agent-socket"
else
set -l _hm_uid (${pkgs.coreutils}/bin/id -u)
set -gx SSH_AUTH_SOCK "/run/user/$_hm_uid/rbw/ssh-agent-socket"
end
end
'';
in
{
inherit bashSnippet fishSnippet;
sessionVariable = "$XDG_RUNTIME_DIR/rbw/ssh-agent-socket";
activationPath = "/run/user/$(id -u)/rbw/ssh-agent-socket";
};
}
+2 -2
View File
@@ -56,14 +56,14 @@
} }
{ {
home.packages = with pkgs; [ rbw pinentry-gtk2 ]; home.packages = with pkgs; [ rbw pinentry-gtk2 ];
home.sessionVariables.SSH_AUTH_SOCK = "$XDG_RUNTIME_DIR/rbw/ssh-agent-socket"; home.sessionVariables.SSH_AUTH_SOCK = self.lib.rbwSshSocket.sessionVariable;
home.file = inventory.mkIdentityFiles selectedHosts; home.file = inventory.mkIdentityFiles selectedHosts;
programs.ssh.enable = lib.mkIf cfg.manageSshConfig false; programs.ssh.enable = lib.mkIf cfg.manageSshConfig false;
home.activation.rbwSshConfig = lib.mkIf cfg.manageSshConfig (lib.hm.dag.entryAfter [ "writeBoundary" ] '' home.activation.rbwSshConfig = lib.mkIf cfg.manageSshConfig (lib.hm.dag.entryAfter [ "writeBoundary" ] ''
mkdir -p "$HOME/.ssh" mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh" chmod 700 "$HOME/.ssh"
RBW_SSH_SOCK="/run/user/$(id -u)/rbw/ssh-agent-socket" RBW_SSH_SOCK="${self.lib.rbwSshSocket.activationPath}"
cat > "$HOME/.ssh/config" <<'EOF' cat > "$HOME/.ssh/config" <<'EOF'
${sshConfigTemplate} ${sshConfigTemplate}
EOF EOF
+4 -19
View File
@@ -1,9 +1,10 @@
{ ... }: { { self, ... }: {
flake.homeManagerModules.wisdomShellBash = flake.homeManagerModules.wisdomShellBash =
{ config, lib, ... }: { config, lib, ... }:
let let
root = config.chiasson.home; root = config.chiasson.home;
cfg = config.chiasson.home.shell.bash; cfg = config.chiasson.home.shell.bash;
rbw = self.lib.rbwSshSocket;
in in
{ {
options.chiasson.home.shell.bash.enable = lib.mkEnableOption "Bash + rbw SSH socket env in profile/init." // { options.chiasson.home.shell.bash.enable = lib.mkEnableOption "Bash + rbw SSH socket env in profile/init." // {
@@ -13,24 +14,8 @@
config = lib.mkIf (root.enable && cfg.enable) { config = lib.mkIf (root.enable && cfg.enable) {
programs.bash = { programs.bash = {
enable = true; enable = true;
profileExtra = '' profileExtra = rbw.bashSnippet;
if [ -z "''${SSH_AUTH_SOCK:-}" ]; then initExtra = rbw.bashSnippet;
if [ -n "''${XDG_RUNTIME_DIR:-}" ]; then
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/rbw/ssh-agent-socket"
else
export SSH_AUTH_SOCK="/run/user/$(id -u)/rbw/ssh-agent-socket"
fi
fi
'';
initExtra = ''
if [ -z "''${SSH_AUTH_SOCK:-}" ]; then
if [ -n "''${XDG_RUNTIME_DIR:-}" ]; then
export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/rbw/ssh-agent-socket"
else
export SSH_AUTH_SOCK="/run/user/$(id -u)/rbw/ssh-agent-socket"
fi
fi
'';
}; };
}; };
}; };
+3 -10
View File
@@ -1,9 +1,10 @@
{ ... }: { { self, ... }: {
flake.homeManagerModules.wisdomShellFish = flake.homeManagerModules.wisdomShellFish =
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let let
root = config.chiasson.home; root = config.chiasson.home;
cfg = config.chiasson.home.shell.fish; cfg = config.chiasson.home.shell.fish;
rbw = self.lib.rbwSshSocket;
in in
{ {
options.chiasson.home.shell.fish = { options.chiasson.home.shell.fish = {
@@ -19,21 +20,13 @@
}; };
config = lib.mkIf (root.enable && cfg.enable) { config = lib.mkIf (root.enable && cfg.enable) {
# `fishPlugins.grc` only installs the plugin; the wrapper invokes the `grc` binary.
home.packages = [ pkgs.grc ]; home.packages = [ pkgs.grc ];
programs.fish = { programs.fish = {
enable = true; enable = true;
interactiveShellInit = '' interactiveShellInit = ''
set fish_greeting "" set fish_greeting ""
if test -z "$SSH_AUTH_SOCK" ${rbw.fishSnippet pkgs}
if test -n "$XDG_RUNTIME_DIR"
set -gx SSH_AUTH_SOCK "$XDG_RUNTIME_DIR/rbw/ssh-agent-socket"
else
set -l _hm_uid (${pkgs.coreutils}/bin/id -u)
set -gx SSH_AUTH_SOCK "/run/user/$_hm_uid/rbw/ssh-agent-socket"
end
end
''; '';
plugins = [ plugins = [
{ {