So if you use flake, you can run:
$ nix eval --inputs-from . --raw nixpkgs#hello
/nix/store/zwnmwns242s7zzm2f4p0ndqdsxw1jb78-hello-2.12.1
and it will tell you the current version of hello
in the flake located at the current path.
More generally, you can also look at the flake.lock
file:
$ cat /etc/nixos/flake.lock
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1675115703,
"narHash": "sha256-4zetAPSyY0D77x+Ww9QBe8RHn1akvIvHJ/kgg8kGDbk=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2caf4ef5005ecc68141ecb4aac271079f7371c44",
"type": "github"
},
"original": {
"id": "nixpkgs",
"ref": "nixos-unstable",
"type": "indirect"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}
or run:
$ nix flake info
Resolved URL: git+file:///etc/nixos
Locked URL: git+file:///etc/nixos?ref=refs%2fheads%2fmaster&rev=a9cbc07dc20920bdfef45fe11ea9b555861bcfd2
Description: The configuration of my system
Path: /nix/store/zj1sa8c6dyaxw44n8chn5yq2zcb5igbj-source
Revision: a9cbc07dc20920bdfef45fe11ea9b555861bcfd2
Revisions: 55
Last modified: 2023-07-14 19:58:37
Inputs:
└───nixpkgs: github:NixOS/nixpkgs/2caf4ef5005ecc68141ecb4aac271079f7371c44
to get the hash of nixpkgs in use. You can see that on this example, it depends on 2caf4ef5005ecc68141ecb4aac271079f7371c44
. From this, you have multiple ways to check the version of a package (maybe more that I don’t know):
- You can use:
$ nix eval --raw "github:NixOS/nixpkgs/2caf4ef5005ecc68141ecb4aac271079f7371c44#hello"
/nix/store/zwnmwns242s7zzm2f4p0ndqdsxw1jb78-hello-2.12.1
So here you see that it provides the version 2.12.1.
- Another option (works best on small flake repositories) is to run something like
nix flake show "github:NixOS/nixpkgs/2caf4ef5005ecc68141ecb4aac271079f7371c44"
and it will list all packages available in this package. By default it will hide all “legacy” (non-flake) inputs, that you need to enable with --legacy
, but note that the list might be huge for nix.
- You can also evaluate it in in interactive shell, like:
$ nix repl
nix-repl> :lf github:NixOS/nixpkgs/2caf4ef5005ecc68141ecb4aac271079f7371c44
nix-repl> legacyPackages.aarch64-linux.hello.version
"2.12.1"
- If you feel adventurous, you can also directly checkout the corresponding version on github and read the source of the program…
To know what package you will get after the rebuild, one option is to simply backup the current flake.lock
(I typically use git for that, possibly using git stash
if you don’t want to commit it), then run again nix flake update
, and then follow again the above instructions. You can also realize that nix flake update
will pick the latest commit in nixos-unstable
(cf the nodes > nixpkgs > original > ref
id from above), and then go to https://status.nixos.org/ to check the current commit pointed to by nixos-unstable
. Once you have it, follow again the above instructions.
You might also like Nix Package Versions to find which channel contains which version.
Note also that if you install the same package from different sources (e.g. from home-manager, or custom $PATH
…), you might use the version from this source instead of the system-installed package. To be sure, just run:
$ readlink -f $(which firefox)
/nix/store/xldghvr9g34x470l93pzdvrkxp1qbqv7-firefox-109.0.1/bin/firefox
so that you can know exactly where your executable is run from.
The difference between /run/current-system
and /run/booted-system
is that you might have upgraded your system since you booted, so booted-system
might point to an older repository. For instance, the kernel you are currently running is the one from booted-system
, not current-system
.