When trying to revive old projects, sometimes I have to fish around for older Nixpkgs commits to get things started.
For example, most of my shell.nix files start like this,
{pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
# ...
}
that would import all expressions from the commit where the current channel points to, but after some time, there have been so many changes that my project won't build anymore; then I will have to find a commit that still works, and go from there.
$ nix-shell --arg pkgs \
> 'import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/0c0fe6d85b92c4e992e314bd6f9943413af9a309.tar.gz") {}'
It would probably be the best if I could just save the working commit from the channel at the time, and have something solid to fall back to when needed later.
To expand on the answer provided in the NixOS discourse thread How to see what commit is my channel on?:
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:
So if you just executed
nix-channel --updatebeforenix-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 tonix-envoperations (via the symlink~/.nix-defexpr/channels)".To see where the
~/.nix-defexpr/channelssymlink points to, usereadlink -fto follow the symlink chain and combine it withlsto get straight to the point:My channel's name is
nixos, and it points toand the commit hash is right after the MAJOR.MINOR.PATCH version number.
Aside: To construct the tarball URL for
fetchTarballin the question, use the following template:For example:
Alternatively, click the green "Code" button, and copy the URL of the "Download ZIP" link (and change the
zipextension totar.gz).Fun fact: if you did
nix-channel --updatebefore method 1, then URLshttps://github.com/NixOS/nixpkgs/tree/<branch-name>andhttps://github.com/NixOS/nixpkgs/tree/<channel-commit>will point to the same place in the Nixpkgs repo.