To expand on the answer provided in the NixOS discourse thread How to see what commit is my channel on?:
Note: Before trying any of these methods, make sure that you are issuing commands with the right user!
No harm done either way, but if you are on NixOS and manage things declaratively (as root
when rebuilding the system) then you might get a different commit hash than what you need. (Especially if you ever issued nix-channel --update
without sudo
, which will set up a channel for your user profile as well.)
Method 0
According to the NixOS wiki's Nix channels entry, "a channel is a name for the latest "verified" git commits in Nixpkgs". That is, at any given time, a channel points to a specific commit in the Nixpkgs git repository on Github; each Nix channel is actually a git branch in the repo:
$ nix-channel --list
nixos https://nixos.org/channels/nixos-20.09
----- -----------
(name) (branch-name)
# |
# V
# https://github.com/NixOS/nixpkgs/tree/<branch-name>
# i.e. https://github.com/NixOS/nixpkgs/tree/nixos-20.09
So if you just executed nix-channel --update
before nix-shell
, and it works, just look up the last commit in the channel branch in the Nixpkgs repo.
Method 1
"Chapter 12. Channels" of the Nix manual mentions that nix-channel --update
"makes the union of each channel’s Nix expressions available by default to nix-env
operations (via the symlink ~/.nix-defexpr/channels
)".
To see where the ~/.nix-defexpr/channels
symlink points to, use readlink -f
to follow the symlink chain and combine it with ls
to get straight to the point:
$ ls -l $(readlink -f ~/.nix-defexpr/channels)
total 6432
dr-xr-xr-x 2 root root 4096 Jan 1 1970 ./
drwxrwxr-t 8191 root nixbld 6569984 Feb 9 15:51 ../
lrwxrwxrwx 1 root root 78 Jan 1 1970 nixos -> /nix/store/k737c631q19n54fhjmnf68frg5dar14w-nixos-20.09.3009.8e78c2cfbae/nixos/
lrwxrwxrwx 1 root root 60 Jan 1 1970 manifest.nix -> /nix/store/a5wl1fri2sasnsb1i5zscni5h7kjg7d6-env-manifest.nix
My channel's name is nixos
, and it points to
/nix/store/k7..4w-nixos-20.09.3009.8e78c2cfbae/nixos/
-----------
^
|
channel-commit
and the commit hash is right after the MAJOR.MINOR.PATCH version number.
Aside: To construct the tarball URL for fetchTarball
in the question, use the following template:
https://github.com/<user>/<repo>/archive/<full-or-abbr-commit-hash>.tar.gz
For example:
https://github.com/NixOS/nixpkgs/archive/8e78c2cfbae.tar.gz
Alternatively, click the green "Code" button, and copy the URL of the "Download ZIP" link (and change the zip
extension to tar.gz
).
Fun fact: if you did nix-channel --update
before method 1, then URLs https://github.com/NixOS/nixpkgs/tree/<branch-name>
and https://github.com/NixOS/nixpkgs/tree/<channel-commit>
will point to the same place in the Nixpkgs repo.