NixOS Workshop

1 the workshop machines

  • each participant has a virtual machine (Digital Ocean VM)
  • connect via SSH or via a Web-Browser at
    • the Web-UI has a sel-signed TLS certificate. The warning in the Browser is to be expected
    • when connecting via Web-Browser, after login select the Terminal
  • Login credentials
    • Username: user
    • Password: nixos

Name Machine
Deleted: list of 41 more names & virtual machines

2 start NixOS

  • on the virtual machines, the command sudo /usr/local/bin/nixos will start a Linux container running NixOS
    • technial background: the container is started as an ephermal container with systemd-nspawn. During startup, the filesystem of the container will be cloned, that takes a few extra seconds
    • the NixOS in the container is just installed, but not configured
  • Login to NixOS with username root and password nixos

3 creating a normal user

  • open the file /etc/nixos/configuration.nix with the nano text editor (we will install other editors soon)
  • find the part that describes the user accounts (example commented out), and enable the config for a normal user:
# Define a user account. Don't forget to set a password with ‘passwd’.
users.users.jane = {
   isNormalUser = true;
   extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
  • save the file
  • activate the new configuration
# nixos-rebuild switch
  • check that the new user exists
# id jane
  • set a password for the new user
passwd jane
  • exit the shell with exit and try to login with the new user
    • test that the new user can become super user with the sudo command

4 fixing the hardware configuration

  • the NixOS was originally installed inside an VirtualBox VM
  • the NixOS hardware autodetection found VirtualBox and automatically created a filesystem mount for the VirtualBox Guest Additions
  • now the NixOS runs inside a Systemd container, and the VirtualBox configuration creates an error message when building a new system configuration (and also during startup):
collision between 
  and `/nix/store/bjshbv71j3010pnhnhdxpwdyrj282wkw-VirtualBox-GuestAdditions-6.1.6-5.4.62/bin/mount.vboxsf'
  • open the NixOS hardware configuration in /etc/nixos/hardware-configuration.nix and find the line that configures the Virtual-Guest additions. Remove that line (delete or comment)
    • the file hardware-configuration.nix is included from the configuration.nix file and describes hardware configuration that can differ between machines.
  • rebuild the NixOS system configuration
  • check that the error message has gone

5 install some gobal packages

  • let's install some global packages that will be visible for all users of the system
  • open the file /etc/nixos/configuration.nix and fill in this block almost at the end, but before the last curly brace
environment.systemPackages = with pkgs; [
  • save the file, exit the editor and rebuild the NixOS system nixos-rebuild switch
  • test that the command htop is now available
  • use the command which htop to see where the command is located
  • use the command realpath on the full path to the htop tool to find its real place in the filesystem
  • use the command nix search <pgm-name> to find the name of some Linux tools (non GUI), for example your favorite text editor
    • add the names of the packages to the configuration.nix file
    • rebuild the configuration
    • verify that the software is installed

6 install home-manager

  • open the file /etc/nixos/configuration.nix with yout favorite text editor
  • add the package name home-manager to the list of installed packages
  • save the file and exit the editor, rebuild the NixOS system
  • logout as root and login as the unprivileged user created above

7 install user packages with home-manager

  • as the unprivileged user, create the directory ~/.config/nixpkgs
  • in that directory, use a text editor to create the file home.nix. This file contains the per-user configuration for home-manager.
  • add this content into the file. This will install the packages gnupg, gtop and unzip for this user
{ config, pkgs, ... }:
  home.packages = with pkgs; [
  • build the home-directory configuration with home-manager switch
  • verify that the command gtop exists
  • use the commands which and realpath on gtop to find out where in the filesystem the tools binary is stored
  • remove one of the tools from the home.nix file
  • rebuild the home-environment with home-manager switch
  • verify that the tool is gone from this users environment

8 using the Nix Shell

  • verify that no Python interpreter is currently installed
[jane@nixos:~]$ python
The program ‘python’ is currently not installed. You can install it by typing:
  nix-env -iA nixos.python3Minimal
  • enter a new Nix enviroment on the fly with nix-shell containing a current Python3 interpreter
$ nix-shell -p python 
  • verify that how this shell has access to the Python interpreter
[nix-shell:~]$ python
Python 2.7.18 (default, Apr 19 2020, 21:45:35) 
[GCC 9.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
  • other users, other shells of the same user, even the root user do not see this Python interpreter, because it is not linked into their environment