summaryrefslogtreecommitdiff
path: root/overlays/sshpass-secret.nix
blob: 1fec5cf321712c969513e1fce16155d754b2d09b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
final: prev: {
  sshpassSecret = prev.writeScriptBin "sshpass-secret" ''
    #!${final.zsh}/bin/zsh -e

    typeset -a cmd
    cmd=()

    while
      if [[ "$#" -le 0 ]]; then
        echo "Insufficient arguments" >&2
        exit 2
      fi
      arg="''${1}"
      shift
    do
      [[ "''${arg}" == '--' ]] && break
      user=''${arg%@*}
      host=''${arg#*@}
      exec {fdnum}<<<$(${final.gnome.libsecret}/bin/secret-tool lookup service sshpass host "''${host}" user "''${user}")
      cmd+=(${final.sshpass}/bin/sshpass -d ''${fdnum} -P "''${user}@''${host}'s password:")
    done

    cmd+=($@)
    exec -a ''${cmd[1]} -- $cmd
  '';
}