I’ve found a similar report from a while ago related to the Nix manual, but nothing else.
This is the output I get:
$ nixos-version
24.05pre-git (Uakari)
My NixOS configuration is based on flakes, is there any particular configuration needed to get the Git hash in the version back?
1 Like
Here’s the script that looks for @version@
: nixpkgs/nixos/modules/installer/tools/nixos-version.sh at 5c0c6e14926c39d5c90073f01ca7fa6d24e3671b · NixOS/nixpkgs · GitHub
If I understand correctly, this is the script used to get that version: nixpkgs/nixos/modules/installer/tools/get-version-suffix at 5c0c6e14926c39d5c90073f01ca7fa6d24e3671b · NixOS/nixpkgs · GitHub
Running the command to get the nixpkgs
instance as that script I get this:
$ nix-instantiate --find-file nixpkgs "$@"
/nix/store/nra828scc8qs92b9pxra5csqzffb6hpl-source
Which doesn’t actually have a .git
folder that the script is trying to find to get the revision:
$ ls -la /nix/store/nra828scc8qs92b9pxra5csqzffb6hpl-source
total 27120
dr-xr-xr-x 8 root root 4096 Jan 1 1970 .
drwxrwxr-t 26902 root nixbld 27635712 May 10 13:16 ..
-r--r--r-- 2 root root 36168 Jan 1 1970 CONTRIBUTING.md
-r--r--r-- 6 root root 1097 Jan 1 1970 COPYING
-r--r--r-- 25 root root 971 Jan 1 1970 default.nix
dr-xr-xr-x 15 root root 4096 Jan 1 1970 doc
-r--r--r-- 5 root root 2916 Jan 1 1970 .editorconfig
-r--r--r-- 5 root root 4353 Jan 1 1970 flake.nix
-r--r--r-- 12 root root 662 Jan 1 1970 .gitattributes
-r--r--r-- 3 root root 3289 Jan 1 1970 .git-blame-ignore-revs
dr-xr-xr-x 4 root root 4096 Jan 1 1970 .github
-r--r--r-- 2 root root 524 Jan 1 1970 .gitignore
dr-xr-xr-x 6 root root 4096 Jan 1 1970 lib
-r--r--r-- 7 root root 950 Jan 1 1970 .mailmap
dr-xr-xr-x 3 root root 4096 Jan 1 1970 maintainers
dr-xr-xr-x 7 root root 4096 Jan 1 1970 nixos
dr-xr-xr-x 20 root root 4096 Jan 1 1970 pkgs
-r--r--r-- 5 root root 5186 Jan 1 1970 README.md
lrwxrwxrwx 5 root root 12 Jan 1 1970 .version -> lib/.version
If this is the actual script, then it seems to be making wrong assumptions, no?
If you use legacyPackages
, the version info should be detected automatically:
If you create custom Nixpkgs instance, you can change system.configurationRevision
NixOS option, example:
1 Like
Thank you! That points me in the right direction
Any reason why you’re using self.rev
there? I just tried to set it to inputs.nixpkgs.rev
but it didn’t change anything even after rebooting…
FWIW I also tried doing the same as you (setting system.configurationRevision ) without success, nixos-version
still reports the same output
Another thing I tried was to set this option when I instantiate nixpkgs:
pkgs = import inputs.nixpkgs {
inherit overlays system;
config.allowUnfree = true;
config.system.configurationRevision = inputs.nixpkgs.rev or "dirty-${inputs.nixpkgs.lastModifiedDate}";
};
Still no luck…
Ah, sorry I misremembered. What I am doing is to get nixos-version --configuration-revision
. Just nixos-version
works for me without any special considerations:
$ nixos-version
24.05.20240507.b211b39 (Uakari)
But checking my Nixpkgs instance, it does not have the info you want either:
nix-repl> :lf /home/jtojnar/Projects/nixfiles
Added 17 variables.
nix-repl> outputs.legacyPackages.x86_64-linux.lib.version
"24.05pre-git"
I have updated my flake to provide this information.
But the fact that nixos-version
shows the correct revision even without that probably means that I am using nixpkgs.lib
somewhere instead of lib
from my overlaid Nixpkgs. Edit: I do that here:
inherit (nixpkgs) lib;
mkConfig = { hostName, platform, managedHome ? false, ... }:
lib.nixosSystem {
1 Like
Thank you! I just realized I needed that overlay too because I’m extending lib
as well, so I’ve come to the same solution
Hmm, looks like the difference between our configs is that you are passing lib
to nixosSystem
, whereas I did not do that:
As a result nixosSystem
fell back to nixpkgs.lib
on my system:
That’s correct, because I have a few custom lib functions. Fixed here by extending the versions overlay