Getting Started with Nix... / Author : Martial Tola
Table of contents
1. Introduction
2. Installation (single user mode)
2.1. Linux
2.2. macOS
2.3. Docker
3. Uninstall
3.1. Linux
3.2. macOS
3.3. Docker
4. Activate the "profiles" feature (extra configuration required)
5. Nix usage
5.1. Manipulate and select channels
5.2. Working with profiles : create several user environments
5.3. Nix basics
5.4. Problem with CMake... (Linux sample)
6. nix-shell command
6.1. CIs
6.1.1. Preparation
6.1.2. Test (Linux sample)
6.1.3. In MEPP2/.gitlab-ci.yml (macOS sample)
6.1.4. Towards reproducibility...
6.2. Interesting use : declarative shell environments with shell.nix file and pinning nixpkgs (Linux sample)
1. Introduction
It is no longer useful to do this nowadays.
So, I'll let you ask that to a fucking shitty AI. ;-)
2. Installation (single user mode)
2.2. macOS
Intel :
Apple silicon :
Or another version, see here : https://releases.nixos.org/?prefix=nix/
Add :
after the line #!/usr/bin/env bash at the top of create-darwin-volume.sh file.
Search and replace :
by :
in install file.
...
Only under Apple silicon :
Only if no ~/.zprofile file :
...
...
...
...
...
...
...
2.3. Docker (with this Dockerfile)
...
...
3.3. Docker
Same as Linux.
4. Activate the "profiles" feature (extra configuration required)
Linux : Nix init is in ~/.profile
macOS : Nix init is in ~/.bash_profile
If you are under macOS, also add :
5. Nix usage
Linux :
macOS :
Docker :
5.1. Manipulate and select channels
Linux :
macOS :
...
However, this had the effect to completely override the unstable channel.
But the unstable channel can be added back with another name...
Linux :
macOS (you can see here that it's the same channel name for Linux and macOS, not very consistent, isn't it ?) :
...
Or, maybe what follows is better for a second channel...
Linux :
macOS :
...
...
So, now we can clean up a little...
...
5.2. Working with profiles : create several user environments
...
...
...
What are my available profiles ?
5.3. Nix basics
nix-env --install | -i
Add packages to user environment.
nix-env --uninstall | -e (again, very consistent, isn't it ?)
Remove packages from user environment.
nix-env --query | -q
Display information about packages.
--available | -a
The query operates on the derivations that are available.
--attr-path | -P
Print the attribute path of the derivation, which can be used to unambiguously select it.
Linux :
macOS :
nix-env --upgrade | -u
Upgrade packages in user environment.
5.4. Problem with CMake... (Linux sample)
But for example there is no problem with cgal, CGALConfig.cmake is here : /nix/store/sx1ifck2d5kyqnrcmyfrhkg3d9zxhb35-cgal-5.6.1/lib/cmake/CGAL/CGALConfig.cmake
6. nix-shell command
nix-shell --packages | -p
Set up an environment in which the specified packages are present.
The command line arguments are interpreted as attribute names inside the Nix Packages collection.
Thus, nix-shell --packages boost cgal will start a shell in which the packages denoted by the attribute names boost and cgal are present.
--pure
If this flag is specified, the environment is almost entirely cleared before the interactive shell is started, so you get an environment that more closely corresponds to the "real" Nix build.
A few variables, in particular HOME, USER and DISPLAY, are retained.
6.1.1. Preparation
Linux :
macOS :
...
6.1.2. Test (Linux sample)
...
6.1.3. In MEPP2/.gitlab-ci.yml (macOS sample)
6.1.4. Towards reproducibility...
nix-shell -I
Determines what to use as a source of package declarations.
Here we provided a specific Git revision of nixpkgs, leaving no doubt about which version of the packages in that collection will be used.
6.2. Interesting use : declarative shell environments with shell.nix file and pinning nixpkgs (Linux sample)
Create a file called shell.nix with these contents :
Enter the environment by running nix-shell in the same directory as shell.nix.
Note : the first invocation of nix-shell on this file may take a while to download all dependencies.