Setting up NixOS on vps2day

July 17 2021

I feel more and more limited by macOS when it comes to creative computational work. One of the systems I’ve read good things about, and that I fully support the philosophy around is NixOS. I decided to test it in a VPS.

NixOS is a DevOPS-inspired, Linux-based operating system built to be reproducible, declarative and reliable. It is also a package manager. To people that don’t know it I like to explain it like if Ansible was an operating system. Check it out on The official installation guide can be found at top recommended hoster of NixOS is vps2day, which seems like a basic but okay hoster for testing the capabilities of the OS. What I found was that there were no online installation for NixOS on vps2day. After a bit back and forth I found that other guides were also working on vps2day. This article describes the procedure to get the system up and running (following the standard installation guide).

The installation of NixOS was something new to me compared with the installer of other operating systems. NixOS by default only boots to a shell. With that shell the NixOS configuration files needs to be setup, which in turn installs things such as Grub on a given disk. In other words, when vps2day boots you into console the OS isn’t installed yet.

% sudo su

# partition the disk with swap
% parted /dev/vda -- mklabel msdos
% parted /dev/vda -- mkpart primary 1MiB -8GiB
% parted /dev/vda -- mkpart primary linux-swap -8GiB 100%

% mkfs.ext4 -L nixos /dev/vda1
% mkswap -L swap /dev/vda2

# mount the nixos disk and enable swap
% mount /dev/disk/by-label/nixos /mnt
% swapon /dev/vda2

# Generate configuration files
% nixos-generate-config --root /mnt

# Install a sensible text editor
% nix-env -f '<nixpkgs>' -iA emacs

% emacs /mnt/etc/nixos/configuration.nix

You are now in the configuration file which defines the installation. For vps2day the following works to get a minimal server up and running.:

{ config, pkgs, ... }:

  imports =

  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;
  boot.loader.grub.device = "/dev/vda"; # or "nodev" for efi only

  # networking.hostName = "nixos"; # Define your hostname.
  networking.useDHCP = false;
  networking.interfaces.ens3.useDHCP = true;

  time.timeZone = "Europe/Oslo";

  environment.systemPackages = with pkgs; [
    wget vim emacs
  ]; = true;
  programs.gnupg.agent = { enable = true; enableSSHSupport = true; };

  services.openssh.enable = true;

  networking.firewall.allowedTCPPorts = [ 22 ];

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.thetom = {
     isNormalUser = true;
     extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.

  system.stateVersion = "19.09";


With that configuration, the provisioning of the server is ready.

# Install bootloader and other according to configuration.nix
% nixos-install
% reboot

The login prompt should be up and running and you can SSH into the server after the reboot.

The current version of NixOS can be checked with the command nixos-version.Finally upgrade to the current version according to the docs:

% nix-channel --add nixos
% nix-channel --list | grep nixos
% nixos-rebuild switch --upgrade
% reboot

Drist is a configuration management/deployment tool which is complementary to NixOS. While NixOS does all the setup on the server, Drist can be used to deploy configuration.nix and trigger rebuilds. Find Drist at is nice with this setup is that the configuration options are be documented in configuration.nix - so if we ever need to this again it can be simply achieved with a script in e.g. Drist.

Tags: #nixos #vps2day #installation
Read with Gemini

Booting a Mac Mini (OCT 2014) with Debian 8.0

February 06 2015

There are a lot of guides on booting Linux on an Mac Mini, and the Mac Mini is absolutely great. There’s also a lot of guides which takes some unnecessary steps on the way from the native OS X experience to the bloated, and difficult-to-setup Linux on OS X. Some of them are good on certain points though.

So, not surprising, I will tell you how to make it work with both a native EFI installation and the Broadcom BCM4366 up and running.

Everything will be done on the command line, so this will work great on servers as well. Of course you won’t run wifi on the work server though (!).

First, take note that this will wipe almost everything Apple from you box except the Firmware. You may roll back through pressing the ALT-key while booting.

Second, you should use Debian 8.0 “Jessie” (which is currently in RC1). This is important since Wheezy doesn’t support the Broadcom chipset.

Prerequisites for this article are:

  • A Mac Mini, tested on an OCT 2014 model
  • A keyboard
  • A USB memory stick of at least 2GB (speed is the key)

1. Install Debian - and Change Boot Order

You should create a bootable USB stick for your Debian installation. When you’ve downloaded the ISO, you can make it bootable without hassle through Unetbootin [1]. That one works on OS X 10.10 “Yosemite” as well.

When you’ve got that one ready insert it into the Mini, holding the ALT-key while booting. You will get to the boot menu, choose the “EFI” one. This will initiate GRUB from the stick.

Do the installation as you would on any other machine. Since your mac is still setup to boot to OS X, we need to change that next in order to make it point to the Debian installation instead.

When rebooting, get into the boot menu by holding the ALT-key again. Select that same GRUB menu again, BUT instead of choosing to install it you should now press “c” to get to the GRUB command line.

It is now time to locate the boot directory [2] on the right disk. Vary X (disk) and Y (partition table) until you find the right combination:

grub> ls (hdX,gptY)/boot/grub

That may for instance result in:

grub> ls (hd2,gpt2)/boot/grub

Set the root to that disk and partition table, and boot it:

grub> set root=(hd2,gpt2)
grub> ls -l (hd2,gpt2)
grub> linux /boot/vmlinux[...].efi.signed root=UUID=[uuid from above command]
grub> initrd /boot/initrd[...]
grub> boot

You will now boot to the one you just installed. It is time to make it persistent and change the boot order with efibootmgr. First list your current settings by:

sudo efibootmgr

Now change the boot order (may vary, point being that Debian should come first):

sudo efibootmgr -o 0,1

Now reboot and enjoy the darkness without wifi.

2. Get Wifi Up and Running (Offline)

The current Broadcom chipset is quite new, so you’ll need to step it up to Debian “Jessie” to get it working. Cutting this a bit short, you will probably need this part to be offline. Showing you a small trick you can get all those dependencies on a vmware installation (run the same image as the one you installed, remember to simulate that you don’t have network on that virtual installation):

apt-get -qq --print-uris install build-essential linux-headers-$(uname -r) broadcom-sta-dkms patch bzip2 wpasupplicant | cut -d\' -f 2 > urls.txt

This will produce a file of urls that are all the packages requested and its dependencies, get the stick, format it with FAT - and grab the packages to it:

wget -i urls.txt

Unmounting that from the virtual installation, insert it into the physical installation:

cd /mnt/usb
dpkg -i *.deb

Remove all modules that may conflict (and blacklist them in /etc/modprobe.d/blacklist.config):

modprobe -r b44 b43 b43legacy ssb brcmsmac

Load the Broadcom module:

modprobe wl
echo wl >> /etc/modules

Everything that’s left now is configuring and starting wpasupplicant:

wpa_passphrase <ssid> [passphrase] > /etc/wpa_supplicant.conf
wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant.conf

To make it persistent enable the interface in /etc/network/interfaces by appending:

auto wlan0
iface wlan0 inet dhcp
    wpa-conf /etc/wpa_supplicant.conf

If you have made an exception in your DHCP pool, you should also make it static (basic stuff, but anyways):

auto wlan0
iface wlan0 inet static
    wpa-conf /etc/wpa_supplicant.conf

That’s basically it. Enjoy the show!

Edit 1, FEB 7th 2015: So I got to play with systemd, since it turns out a service isn’t a service the way it used to be. In order to start services in Debian “Jessie”, you’ll need to use systemd. Here’s an example for znc [3]:

Description=An advanced IRC bouncer oidentd.socket
ExecStart=/usr/bin/znc -f $ZNC_OPTIONS
ExecReload=/bin/kill -HUP $MAINPID

Also create the directory and drop the following line into /etc/conf.d/znc: ZNC_OPTIONS="-d /var/lib/znc"

Edit 2, FEB 7th 2015: To enable the Mac Mini to auto-restart after power failure set the following PCI value [4]:

setpci -s 0:1f.0 0xa4.b=0


Tags: #macmini #mac #apple #debian #boot #installation #os
Read with Gemini

This blog is powered by cl-yag and Tufte CSS!