Skip to content

Instantly share code, notes, and snippets.

@MelleB
Forked from ldesgoui/nixos-on-scaleway.sh
Last active May 2, 2019 15:48
Show Gist options
  • Save MelleB/cbacce55ad21f44ab345573d5e28e1c5 to your computer and use it in GitHub Desktop.
Save MelleB/cbacce55ad21f44ab345573d5e28e1c5 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
# Amended for ubuntu 18
# 0: Create a Scaleway instance and SSH into it
ssh root@...
# 0: Install sudo
apt install sudo
export EDITOR=vim
# Add line to enable user as sudo users (disabled by default)
visudo
%sudo ALL=(ALL:ALL) ALL
# 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/en/docs/activate-rescue-mode-on-my-server/
exit
reboot
# -: Wait a bit and reconnect
!ssh
# 4: Mount your volume and fetch the tarball
mkdir -p /mnt/data
mount /dev/vda1 /mnt/data
mv /mnt/data/home/user/nixos.tar.xz .
# 5: Replace volume contents with NixOS
rm -rf /mnt/data/* # takes a few moments
tar xf nixos.tar.xz -C /mnt/data/ # 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment