diff --git a/hosts/elara/users/nikara/configs/console/git/default.nix b/hosts/elara/users/nikara/configs/console/git/default.nix index 5edce76..7c1f4f8 100644 --- a/hosts/elara/users/nikara/configs/console/git/default.nix +++ b/hosts/elara/users/nikara/configs/console/git/default.nix @@ -2,7 +2,7 @@ user ? throw "user argument is required", home ? throw "home argument is required", }: -{ ... }: +{ lib, pkgs, ... }: { home-manager.users.${user} = { sops.secrets = { @@ -17,27 +17,33 @@ }; }; - programs.ssh.matchBlocks = { - "github.com" = { - hostname = "github.com"; - user = "git"; - identityFile = [ - "${home}/.ssh/ssh_sas_ed25519_key" - "${home}/.ssh/ssh_personal_ed25519_key" - ]; - }; + programs = { + git.extraConfig.core.sshCommand = lib.meta.getExe ( + pkgs.writeShellApplication { + name = "git-ssh-key-wrapper"; + runtimeInputs = with pkgs; [ openssh ]; + text = builtins.readFile ./git-ssh-key-wrapper.sh; + } + ); - "gitlab.sas.com" = { - hostname = "gitlab.sas.com"; - user = "git"; - identityFile = "${home}/.ssh/ssh_sas_ed25519_key"; - }; + ssh.matchBlocks = { + "github.com" = { + hostname = "github.com"; + user = "git"; + }; - "gerrit-svi.unx.sas.com" = { - hostname = "gerrit-svi.unx.sas.com"; - user = "nikara"; - port = 29418; - identityFile = "${home}/.ssh/ssh_sas_ed25519_key"; + "gitlab.sas.com" = { + hostname = "gitlab.sas.com"; + user = "git"; + 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"; + }; }; }; }; diff --git a/hosts/elara/users/nikara/configs/console/git/git-ssh-key-wrapper.sh b/hosts/elara/users/nikara/configs/console/git/git-ssh-key-wrapper.sh new file mode 100755 index 0000000..bdade5a --- /dev/null +++ b/hosts/elara/users/nikara/configs/console/git/git-ssh-key-wrapper.sh @@ -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 "$@"