Skip to content

Instantly share code, notes, and snippets.

@monadplus
Created March 4, 2020 08:47
Show Gist options
  • Save monadplus/b9d984f29ba142ed09434207f9f409ac to your computer and use it in GitHub Desktop.
Save monadplus/b9d984f29ba142ed09434207f9f409ac to your computer and use it in GitHub Desktop.
Where is <nixpkgs> ?

Nix looks for expressions at NIX_PATH.

NIX_PATH is very similar to PATH but used by nix expressions (an expression is search on the NIX_PATH from left to right)

$ nix-instantiate --eval -E '<nixpkgs>'
/nix/var/nix/profiles/per-user/root/channels/nixos
$ echo $NIX_PATH
nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels

<nixpkgs> is refering to a path in our filesystem specified by NIX_PATH

$ nix-instantiate --eval -E '<ping>' # Obviously not found.

# But if we add it to the `NIX_PATH`
$ NIX_PATH=$PATH nix-instantiate --eval -E '<ping>'

# NIX_PATH has this handy syntax:
$ NIX_PATH="ping=/bin/ping" nix-instantiate --eval -E '<ping>'

<ping> equivalent to ./ping but for nix expressions.

To find where is exactly on the system:

$ nix-instantiate --find-file nixpkgs
# Then, print .version and .version-suffix

About nix-env

nix-env is a little different than nix-instantiate/nix-build.

nix-env uses ~/.nix-defexpr instead of NIX_PATH (though NIX_PATH usually includes .nix-defexpr).

An error occurs while fetching sources from an url, how do I fix it ?

Try this in order:

$ nix-channel --update
# and try to rebuild

$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable  nixos-unstable
$ nix-channel --update nixos-unstable # Now you can import <nixos-unstable> {};
# and try to rebuild

# Navigate to your channel's expressions (google it) and find the package
$ vim default.nix $ alter the url and the sha256 (use `nix-prefetch-url url` to get the sha256)

On NixOS, you must run those commands as root because the channels are at root level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment