Skip to content

Commit

Permalink
copy over ssh host keys
Browse files Browse the repository at this point in the history
  • Loading branch information
tie committed Sep 27, 2023
1 parent bb058eb commit 72e10df
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Options:
use another kexec tarball to bootstrap NixOS
* --post-kexec-ssh-port <ssh_port>
after kexec is executed, use a custom ssh port to connect. Defaults to 22
* --no-copy-host-keys
do not copy over existing /etc/ssh/ssh_host_* host keys to the installation
* --stop-after-disko
exit after disko formatting, you can then proceed to install manually or some other way
* --extra-files <file...>
Expand Down Expand Up @@ -119,6 +121,10 @@ while [[ $# -gt 0 ]]; do
post_kexec_ssh_port=$2
shift
;;
--no-copy-host-keys)
no_copy_host_keys=y
shift
;;
--debug)
enable_debug="-x"
print_build_logs=y
Expand Down Expand Up @@ -450,13 +456,22 @@ fi

step Installing NixOS
ssh_ bash <<SSH
set -efu ${enable_debug}
set -eu ${enable_debug}
# when running not in nixos we might miss this directory, but it's needed in the nixos chroot during installation
export PATH=\$PATH:/run/current-system/sw/bin
export PATH="\$PATH:/run/current-system/sw/bin"
# needed for installation if initrd-secrets are used
mkdir -p /mnt/tmp
chmod 777 /mnt/tmp
if [[ ${no_copy_host_keys-n} == "n" ]]; then
# NB nixos-kexec-installer preserves host keys, so do we. Run before install
# since tools like nix-sops need secrets for activation.
mkdir -m 755 -p /mnt/etc/ssh
for p in /etc/ssh/ssh_host_*; do
test -e "\$p" || continue
cp -a "\$p" /mnt/etc/ssh
done
fi
nixos-install --no-root-passwd --no-channel-copy --system "$nixos_system"
if command -v zpool >/dev/null; then
zpool export -a || : # we always want to export the zfs pools so people can boot from it without force import
Expand Down

0 comments on commit 72e10df

Please sign in to comment.