How to determine system nixpkgs version without sudo access?

I’d like to determine the system nixpkgs channel version on a machine on which I am a lowly non-sudo user. How does one accomplish this?

My usual go-to is sudo nix-channel --list but obviously this does not work. nix-info isn’t giving me any insight either:

 - system: `"x86_64-linux"`
 - host os: `Linux 5.4.0-150-generic, Ubuntu, 20.04.6 LTS (Focal Fossa), nobuild`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.13.3`
 - channels(samuelainsworth): `"home-manager-22.11.tar.gz"`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`

How do I figure out which channel it’s tracking and, ideally, the current commit or hash of that channel?

A snippet that I love to use to discover channel versions is this one, it does not properly work for channels derived from flakes or direct git downloads:

for chan in nixos nixpkgs; do
  printf "%s: %s\n" $chan $(nix-instantiate --eval --expr "(import <$chan> {}).lib.version" 2>/dev/null);
done

There is also nixos-version which tells you the exact version that the currently active system was built from.

1 Like

Beautiful! This should be in the standard tooling!

Alas this is not a NixOS machine…