Remotely deploying NixOS configuration using SSH Jump Host

Published by Philipp Schuster on

nixos-rebuild --target-host <user@host> is a powerful tool to remotely deploy a NixOS configuration. However, there are scenarios where you can’t reach a machine directly but need an SSH jump host.

Suppose you want to deploy to the host 192.168.124.42, which is only reachable from the host ssh-gate. Then your nixos-rebuild invocation might look as follows:

NIX_SSHOPTS="-J user1@ssh-gate" nixos-rebuild switch --flake ".#target-host" \
      --target-host "user2@192.168.124.42" \
      --use-remote-sudo \
      --use-substitutes \
      --verbose

It’s simple as that. Using -J <jumphost> option (see man page), we instruct SSH to find the right remote via the jump host.


Philipp Schuster

Hi, I'm Philipp and interested in Computer Science. I especially like low level development, making ugly things nice, and de-mystify "low level magic".

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *