135 lines
4.1 KiB
Markdown
135 lines
4.1 KiB
Markdown
|
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]: 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 https://nixos.org
|
|||
|
|
|||
|
|
|||
|
[^installation guide]: The official installation guide can be
|
|||
|
found at
|
|||
|
https://nixos.org/manual/nixos/stable/index.html#sec-configuration-syntax
|
|||
|
|
|||
|
The 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 =
|
|||
|
[
|
|||
|
./hardware-configuration.nix
|
|||
|
];
|
|||
|
|
|||
|
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
|
|||
|
];
|
|||
|
|
|||
|
programs.mtr.enable = 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.
|
|||
|
|
|||
|
[^nixos-version]: 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 https://nixos.org/channels/nixos-21.05 nixos
|
|||
|
% nix-channel --list | grep nixos
|
|||
|
% nixos-rebuild switch --upgrade
|
|||
|
% reboot
|
|||
|
```
|
|||
|
|
|||
|
[^drist]: 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
|
|||
|
https://dataswamp.org/\~solene/page-drist-official-website.html
|
|||
|
|
|||
|
What 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.
|