Last active
January 8, 2025 10:58
-
-
Save IvanChepurnyi/08d7e5fbc83a45efb122e7c147c6ae60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Commands coming from https://nixos.wiki/wiki/Install_NixOS_on_Hetzner_Online and adjusted to automate SSH key | |
apt-get install -y sudo | |
mkdir -p /etc/nix | |
echo "build-users-group =" > /etc/nix/nix.conf | |
curl -L https://nixos.org/nix/install | sh | |
. $HOME/.nix-profile/etc/profile.d/nix.sh | |
EXISTING_AUTHORIZED_KEYS=$(cat $HOME/.ssh/authorized_keys) | |
VERSION=${1:-1.8.0} | |
# Install nixos-generators | |
# This might take a while, so the verbose flag `-v` is included to monitor progress | |
nix-env -f https://github.com/nix-community/nixos-generators/archive/$VERSION.tar.gz -i -v | |
# Create a initial config, just to kexec into | |
cat <<EOF > /root/config.nix | |
{ | |
services.openssh.enable = true; | |
users.users.root.openssh.authorizedKeys.keys = [ | |
# Replace with your public key | |
"$EXISTING_AUTHORIZED_KEYS" | |
]; | |
} | |
EOF | |
# Generate the kexec script | |
nixos-generate -o /root/result -f kexec-bundle -c /root/config.nix | |
# Switch to the new system | |
/root/result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment