Add git ssh key wrapper

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2025-02-22 00:12:17 +00:00
parent 2202f2bae8
commit 354e9937b6
2 changed files with 42 additions and 20 deletions

View File

@@ -2,7 +2,7 @@
user ? throw "user argument is required", user ? throw "user argument is required",
home ? throw "home argument is required", home ? throw "home argument is required",
}: }:
{ ... }: { lib, pkgs, ... }:
{ {
home-manager.users.${user} = { home-manager.users.${user} = {
sops.secrets = { sops.secrets = {
@@ -17,27 +17,33 @@
}; };
}; };
programs.ssh.matchBlocks = { programs = {
"github.com" = { git.extraConfig.core.sshCommand = lib.meta.getExe (
hostname = "github.com"; pkgs.writeShellApplication {
user = "git"; name = "git-ssh-key-wrapper";
identityFile = [ runtimeInputs = with pkgs; [ openssh ];
"${home}/.ssh/ssh_sas_ed25519_key" text = builtins.readFile ./git-ssh-key-wrapper.sh;
"${home}/.ssh/ssh_personal_ed25519_key" }
]; );
};
"gitlab.sas.com" = { ssh.matchBlocks = {
hostname = "gitlab.sas.com"; "github.com" = {
user = "git"; hostname = "github.com";
identityFile = "${home}/.ssh/ssh_sas_ed25519_key"; user = "git";
}; };
"gerrit-svi.unx.sas.com" = { "gitlab.sas.com" = {
hostname = "gerrit-svi.unx.sas.com"; hostname = "gitlab.sas.com";
user = "nikara"; user = "git";
port = 29418; identityFile = "${home}/.ssh/ssh_sas_ed25519_key";
identityFile = "${home}/.ssh/ssh_sas_ed25519_key"; };
"gerrit-svi.unx.sas.com" = {
hostname = "gerrit-svi.unx.sas.com";
user = "nikara";
port = 29418;
identityFile = "${home}/.ssh/ssh_sas_ed25519_key";
};
}; };
}; };
}; };

View File

@@ -0,0 +1,16 @@
# shellcheck shell=bash
key="$HOME/.ssh/ssh_personal_ed25519_key"
if [[ "$*" == *"git@github.com"* ]]; then
if [[ "$*" == *"sas-institute-rnd-product/"* ||
"$*" == *"sas-institute-rnd-internal/"* ||
"$*" == *"sas-institute-rnd-pipeline-test/"* ||
"$*" == *"_sasinst/"* ]]; then
key="$HOME/.ssh/ssh_sas_ed25519_key"
fi
exec ssh -i "$key" "$@"
fi
exec ssh "$@"