| ID | 7ab35e32-c9e2-4b3e-9d0f-d519423165c4 |
|---|---|
| DeertopiaVisibility | public |
| ROAM_ALIASES | NixOS |
Nix
NixOS is a Linux distribution centered around Nix, the purely-functional programming language.
Finding what you need
Nix's documentation is vast, but shallow. Finding what you need can be tough.
Finding libraries: The
nix-indexpackage provides a commandnix-locate -w --top-level «library.so»which will search for packages providing«library.so».Finding executables: You can simply search Nixpkgs for the executable name. }:)
A third-party index of the Nixpkgs library and builtin functions
The Nix language
Path literals
In non-interactive use, path literals always resolve to a path copied in the Nix store. This may be unexpected at times, since they don't do that at the repl!
# CWD: /persist/dots
./file
# At the REPL:
# => "/persist/dots/file"
# Anywhere else:
# => "/nix/store/…-source/file"
No, this cannot be escaped by using builtins.toString.
This can be rather frustrating at times, as it often leaves you no choice but to hard-code you wish to use mutably.
Debugging
The REPL
Debugging Home-manager: browse nixosConfigurations.«host».config.home-manager.users.«user».
Derivations
Add pkgs.breakpointHook to your nativeBuildInputs. Upon build failure, a message like
build for nbb-1.3.200 failed in buildPhase with exit code 1
To attach, run the following command:
sudo /nix/store/m2mjhykymxr9d4caiwkwccp9332ksim7-attach/bin/attach 9501261
will be printed. Leave the build process running, and run the printed command to get a Bash shell in the build environment at the point of failure.Debug a failed derivation with breakpointHook and cntr
Cookbook
Run latest version of a package
$ nix run nixpkgs#«package» --override-flake nixpkgs 'github:NixOS/nixpkgs/nixpkgs-unstable'
Errors
"error: collision between X and Y"
This is most often seen as a harmless warning. As an error, it usually means e.g. a command name appears on $PATH twice.
Dev shells
mkShellpopulates $XDG_DATA_DIRS with the $out/share paths of eachnativeBuildInput.