-
-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add var.ssh_options to pass additional SSH options to nixos-rebuild #427
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,14 +14,16 @@ TARGET_PORT=$4 | |
IGNORE_SYSTEMD_ERRORS=$5 | ||
shift 3 | ||
|
||
TARGET="${TARGET_USER}@${TARGET_HOST}" | ||
|
||
workDir=$(mktemp -d) | ||
trap 'rm -rf "$workDir"' EXIT | ||
|
||
sshOpts=(-p "${TARGET_PORT}") | ||
sshOpts+=(-o UserKnownHostsFile=/dev/null) | ||
sshOpts+=(-o StrictHostKeyChecking=no) | ||
sshConfigFile="$workDir/ssh_config" | ||
cat >"$sshConfigFile" <<EOF | ||
Host $TARGET_HOST | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. As you have rightfully said, this will be an issue for users configuring private ssh keys and jump hosts in their ssh_config. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is a workaround for you specifically, could you not pass in -F in your case instead? terraform also allows to write files, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can add support for passing in an ssh config file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes this would work too. I changed the PR so that additional options are passed as a string to
I think passing flags is more flexible. As you suggested we can pass |
||
User $TARGET_USER | ||
Port $TARGET_PORT | ||
$(echo "$SSH_OPTIONS" | jq -r 'to_entries[] | " \(.key) \(.value)"') | ||
EOF | ||
|
||
set +x | ||
if [[ -n ${SSH_KEY+x} && ${SSH_KEY} != "-" ]]; then | ||
|
@@ -32,12 +34,12 @@ if [[ -n ${SSH_KEY+x} && ${SSH_KEY} != "-" ]]; then | |
echo "$SSH_KEY" >"$sshPrivateKeyFile" | ||
) | ||
unset SSH_AUTH_SOCK # don't use system agent if key was supplied | ||
sshOpts+=(-o "IdentityFile=${sshPrivateKeyFile}") | ||
echo " IdentityFile ${sshPrivateKeyFile}" >>"$sshConfigFile" | ||
fi | ||
set -x | ||
|
||
try=1 | ||
until NIX_SSHOPTS="${sshOpts[*]}" nix copy -s --experimental-features nix-command --to "ssh://$TARGET" "$NIXOS_SYSTEM"; do | ||
until NIX_SSHOPTS="-F $sshConfigFile" nix copy -s --experimental-features nix-command --to "ssh://$TARGET_HOST" "$NIXOS_SYSTEM"; do | ||
if [[ $try -gt 10 ]]; then | ||
echo "retries exhausted" >&2 | ||
exit 1 | ||
|
@@ -52,7 +54,7 @@ if [[ $TARGET_USER != "root" ]]; then | |
fi | ||
deploy_status=0 | ||
# shellcheck disable=SC2029 | ||
ssh "${sshOpts[@]}" "$TARGET" "$switchCommand" || deploy_status="$?" | ||
ssh -F "$sshConfigFile" "$TARGET_HOST" "$switchCommand" || deploy_status="$?" | ||
if [[ $IGNORE_SYSTEMD_ERRORS == "true" && $deploy_status == "4" ]]; then | ||
exit 0 | ||
fi | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the current behavior in nixos-anywhere, if you are not using terraform.