Introduction to Nix
This demo focuses on producing docker images and VMs to illustrate the main steps towards a full scale deployment on Grid'5000.
Getting started
This tutorial works best on Linux, especially for the VM part that needs a linux x86 system to be generated.
- Install nix: https://nixos.org/download#download-nix
- Append to /etc/nix/nix.conf:
extra-experimental-features = nix-command flakes max-jobs = auto cores = 0 log-lines = 50
- Now, from the root of this repository you can
nix develop
to enter the dev shell - Run
just
will list all available commands -
just container
will build the container (you needdocker
) - You can test the result using
docker run -p 8080:8080 tutosed
andcurl 127.0.0.1:8080
-
just vm
will boot the VM locally -
just ssh-in
will connect you inside - Check the systemd service with
systemctl status helloworld
- Check the service is responding using
curl 127.0.0.1:8080
orbrowsh http://127.0.0.1:8080
Enjoy
We are not going to grid'5000, because then, the complicated part is not Nix anymore, its Grid'5000 and small things to configure (and this problem will be the same using Guix, Packer or anything then).
Application used
The application is a straighforward HTMx helloworld I wrote.
You can check what the flake exports (and what can be used) with nix flake show github:volodiapg/gohtmxhelloworld/main
.
Architecture of the flake
In most of my flakes I use
flake-utils
to be able to target different system architecture.
Here, I define multiple flakes for the devenv, VM, modules for the VM.
Each is in its variable that is then injected in the last bit of code:
nixpkgs.lib.foldl nixpkgs.lib.recursiveUpdate {}
[
flakeDevEnv
flakeDocker
flakeModules
flakeVM
];
This part performs a deep merge of to generate the full outputs of the flake but preserve that some outputs are system specific (like the vm). You can check all the outputs with nix flake show
.