Mentions légales du service

Skip to content
Snippets Groups Projects

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.

  1. Install nix: https://nixos.org/download#download-nix
  2. Append to /etc/nix/nix.conf:
    extra-experimental-features = nix-command flakes
    max-jobs = auto
    cores = 0
    log-lines = 50
  3. Now, from the root of this repository you can nix develop to enter the dev shell
  4. Run just will list all available commands
  5. just container will build the container (you need docker)
  6. You can test the result using docker run -p 8080:8080 tutosed and curl 127.0.0.1:8080
  7. just vm will boot the VM locally
  8. just ssh-in will connect you inside
  9. Check the systemd service with systemctl status helloworld
  10. Check the service is responding using curl 127.0.0.1:8080 or browsh 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.