User Tools

Site Tools


howto:nix_hosts

This is an old revision of the document!


Working on NixOS hosts / Core services

Our 'core services' (the stuff we're more scared of changing), are mostly managed with Nix - a functional programming language, build system, configuration tool, and hard disk stress tester wrapped into one.

A lot of this is specific to Tardis core services nix, and is mostly geared towards people needing to make superficial changes, that probably haven't learnt Nix.

'I-just-want-to-add-a-vhost-why-is-this-so-hard'

Our core services is setup to deploy whatever's on main to all of our machines. This means if you know exactly what you need to change, you can probably avoid doing any actual building or deploying locally.

With that said, you should still use a syntax checker / linter. You can download alejandra, our linter. Make your changes, then run alejandra . to check syntax, and format it. Double check your changes to make sure you haven't completely changed the meaning of the file - if the indentation is the same everywhere else you're probably fine.

Here is a small cheatsheet for the nix language - alternatively, just look at the parts around what you're editing. Here are some common files you might need to edit:

You won't be able to merge directly into main, for hopefully obvious reasons. Make a branch and an MR, then ask someone else to approve it.

Prolonged work

If you're doing a lot of work and want to deploy and redeploy without pushing to CI, you'll need to do some local setup. Fortunately - you don't need a lot of disk space (all of our hosts take up about 11G). We can do all the actual building remotely, and only do some local config to make Nix forward things properly.

Installing Nix

You'll need something running *nix - either a VM or WSL. MacOS (Darwin) should work, but we haven't tested it.

We recommend the determinate systems nix installer, which can be run as simple as:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

It gives you basically the same setup as the official Nix installer (which you can use if you have any problems), but it enables some extra commands, and especially flakes.

If you do use the official Nix installer, add extra-experimental-features = flakes nix-command so you can use these extra features. Don't worry - they're barely experimental anymore and are pretty widely deployed.

Extra Setup

Remote building works like this:

  1. Upload your sources to our build server
  2. Have it build it
  3. When you deploy, everything gets downloaded from the build server

For packages we're not building (most packages that we haven't modified), we want the build server to download it directly from Nix's cache, as opposed to the default where you download it then copy to the build server. To fix this, add builders-use-substitutes = true to /etc/nix/nix.conf.

Lastly, we need root to have passwordless ssh to nixbuild.internal.tardisproject.uk. This involves proxying through our SSH bastion. You can find more details here, but you'll need to add something like this to /etc/ssh/ssh_config:

Host tardis
    User USERNAME
    IdentityFile /path/to/your/ssh_key
    HostName tardisproject.uk

Host nixbuild.internal.tardisproject.uk
    User root
    HostName nixbuild.internal.tardisproject.uk
    ProxyJump tardis
    IdentityFile /path/to/tardis/admin/key

This page has more info on Nix build servers, and how they're used.

Finally, for deployment, you'll need to be able to ssh (from your user) into <hostname>.tardisproject.uk without any password. This is covered here.

If you've gotten this far, test everything with these commands:

# Test using the remote build server
nix store ping --store ssh://nixbuild.internal.tardisproject.uk
# Test passwordless SSH to root@ wherever youre deploying
ssh web.tardisproject.uk

Doing the thing

Now that you're all setup, you can use the 3 scripts in our repo for most tasks:

  • scripts/eval_system <hostname> evaluates a given hostname and does some basic checks like that options exist, etc. Nothing gets built, and this doesnt even require remote building.
  • colmena apply switch –on=<hostname> builds and deploys the given hostname - all remotely. Skip the on flag if you want to deploy everything.
  • colmena apply build –on=<hostname> just builds the given hostname, but doesn't switch to it.

And some routine Nix tasks:

  1. nix flake update - Update all inputs
  2. nix flake lock –update-input <name> - Update a specific input, ie sonic-screwdriver
howto/nix_hosts.1685830028.txt.gz · Last modified: 2023/06/03 22:07 by tcmal