Skip to content

Instantly share code, notes, and snippets.

@ldesgoui
Last active July 7, 2020 05:11
Show Gist options
  • Save ldesgoui/598648a1af42a451c23657b548b250db to your computer and use it in GitHub Desktop.
Save ldesgoui/598648a1af42a451c23657b548b250db to your computer and use it in GitHub Desktop.
# This isn't meant to be ran as a script, but line-by-line
# Props to Binary (benary.org) for helping me with this
# 0: Create a Scaleway instance and SSH into it
ssh root@...
# 1: Install Nix
adduser user # set a password, doesn't matter what because it's not staying long
adduser user sudo
su -l user
curl https://nixos.org/nix/install | sh
source ~/.nix-profile/etc/profile.d/nix.sh
# 2: Build a NixOS tarball (this takes a while)
nix-build '<nixpkgs/nixos/release-combined.nix>' -A nixos.containerTarball.x86_64-linux
cp result/tarball/nixos-system-x86_64-linux.tar.xz nixos.tar.xz
# 3: Set Scaleway server to boot in rescue script and reboot
# read: https://www.scaleway.com/docs/perform-rescue-action-on-my-server/
exit
reboot
# -: Wait a bit and reconnect
!ssh
# 4: Mount your volume and fetch the tarball
mount /dev/vda /mnt
mv /mnt/home/user/nixos.tar.xz .
# 5: Replace volume contents with NixOS
rm -rf /mnt/* # takes a few moments
tar xf nixos.tar.xz -C /mnt/ # same for this
mkdir /mnt/sbin
ln -s /mnt/init /mnt/sbin/init
# 6: Set the bootscript back to normal (pick whichever option is named stable)
reboot
# 7: Use the Scaleway terminal to configure your OS
# Replace the current configuration with a nixos-generate-config
# Delete anything related to grub2 and add those options:
boot.isContainer = true; # LOOK UP WHAT THIS DOES (disable kmod and therefore iptables, a bunch of other things)
boot.loader.initScript.enable = true;
# You also probably should replace the root shell by a nologin -- ONLY AFTER OTHER USERS AND SUDO IS SET UP
users.users.root.shell = pkgs.nologin;
# Enjoy
@yogsototh
Copy link

yogsototh commented Nov 20, 2017

ha, tar was missing after the rm -rf /mnt/* command. I think I missed the rescue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment