# Install NixOS on OCI # The hostname of the to-be-installed machine. # It's used to select the configuration. name=example # The IP address or domain name of the to-be-installed machine. target=INSERT_YOUR_PUBLIC_IP_HERE # The machine hardware name of the target machine. # Supported values: aarch64, x86_64 machine=aarch64 kexec_tarball=$(nix-build --no-out-link '' -A config.system.build.kexec_tarball -I nixos-config=./kexec.nix) scp $kexec_tarball/tarball/nixos-system-$machine-linux.tar.xz ubuntu@$target:/tmp/ ssh ubuntu@$target sudo tar -C / -xf /tmp/nixos-system-$machine-linux.tar.xz ssh ubuntu@$target sudo /kexec_nixos sed -i "/^$target /d" ~/.ssh/known_hosts ssh root@$target # If the VM doesn't have enough memory, add a swap device and # increase the size of the kexec's Nix store. if test "$(free -m | awk '/^Mem:/{print$2}')" -lt 1024; then printf '%s\n' label:gpt ,512M,U ,4G,S ,,L | sfdisk /dev/sda mkfs.fat -F 32 -n boot /dev/sda1 mkswap -L swap /dev/sda2 mkfs.ext4 -L root /dev/sda3 swapon /dev/disk/by-label/swap mount -o remount,size=800M /nix/.rw-store/ else printf '%s\n' label:gpt ,512M,U ,,L | sfdisk /dev/sda mkfs.fat -F 32 -n boot /dev/sda1 mkfs.ext4 -L root /dev/sda2 fi mkdir -m 0000 -p /mnt && mount /dev/disk/by-label/root /mnt mkdir -m 0000 -p /mnt/boot && mount /dev/disk/by-label/boot /mnt/boot nix-channel --add https://nixos.org/channels/nixos-23.05 nixpkgs nix-channel --update ssh root@$target mkdir -p /mnt/etc/nixos rsync -va "$name"/ root@$target:/mnt/etc/nixos/ nixos-install --no-root-passwd shutdown -r now sed -i "/^$target /d" ~/.ssh/known_hosts ssh root@$target