Skip to content

Commit

Permalink
feat: send initrd SSH keys if available
Browse files Browse the repository at this point in the history
  • Loading branch information
flexiondotorg committed Oct 16, 2024
1 parent 105dbcb commit e463fed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions nixos/_mixins/scripts/install-anywhere/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let
runtimeInputs = with pkgs; [
coreutils-full
git
tree
];
text = builtins.readFile ./install-anywhere.sh;
};
Expand Down
28 changes: 24 additions & 4 deletions nixos/_mixins/scripts/install-anywhere/install-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,36 @@ else
echo "- WARN! Wiping disks"
fi

EXTRA_FILES=0
# https://github.com/nix-community/nixos-anywhere/blob/main/docs/howtos/secrets.md
if [ -e "$HOME/.config/sops/age/keys.txt" ] && [ "$VM_TEST" -eq 0 ]; then
if [ -e "$HOME/.config/sops/age/keys.txt" ]; then
install -d -m755 "$FILES/$HOME/.config/sops/age"
cp "$HOME/.config/sops/age/keys.txt" "$FILES/$HOME/.config/sops/age/keys.txt"
EXTRA+=" --extra-files $FILES"
chmod 600 "$FILES/$HOME/.config/sops/age/keys.txt"
chown 1000:100 "$FILES/$HOME/.config/sops/age/keys.txt"
echo "- INFO: Sending SOPS keys"
EXTRA_FILES=1
else
echo "- WARN! No SOPS keys found"
fi

if [ -e "$HOME/Keybase/private/wimpress/Secrets/ssh/initrd_ssh_host_ed25519_key" ]; then
install -d -m755 "$FILES/etc/ssh"
cp "$HOME/Keybase/private/wimpress/Secrets/ssh/initrd_ssh_host_ed25519_key" "$FILES/etc/ssh/"
cp "$HOME/Keybase/private/wimpress/Secrets/ssh/initrd_ssh_host_ed25519_key.pub" "$FILES/etc/ssh/"
chmod 600 "$FILES/etc/ssh/initrd_ssh_host_ed25519_key"
chmod 644 "$FILES/etc/ssh/initrd_ssh_host_ed25519_key.pub"
echo "- INFO: Sending initrd SSH keys"
EXTRA_FILES=1
else
echo "- WARN! No initrd SSH keys found"
fi

if [ "$EXTRA_FILES" -eq 1 ]; then
EXTRA+=" --extra-files $FILES"
tree -a "$FILES"
fi

REPLY="n"
read -p "Proceed with remote install? [y/N]" -n 1 -r
echo
Expand All @@ -78,6 +98,6 @@ fi

pushd "$HOME/Zero/nix-config" || exit 1
# shellcheck disable=2086
nix run github:nix-community/nixos-anywhere -- \
$EXTRA --flake ".#$HOST" "root@$REMOTE_ADDRESS"
#nix run github:nix-community/nixos-anywhere -- \
# $EXTRA --flake ".#$HOST" "root@$REMOTE_ADDRESS"
popd || true

0 comments on commit e463fed

Please sign in to comment.