If I do nix-env --list-generations
, I have to page through all the previous generations to get to the current one.
Is there a way to see the current generation number without listing all the previous ones?
If I do nix-env --list-generations
, I have to page through all the previous generations to get to the current one.
Is there a way to see the current generation number without listing all the previous ones?
You could always press G to jump to the end.
Alternatively you could run
> readlink "$(readlink ~/.nix-profile)"
which should spit out something like profile-66-link
, which means generation 66.
Or you could use grep
as in
$ nix-env --list-generations | grep current | awk '{print $1}'
565
Or use readlinks
$ readlinks ~/.nix-profile
/home/layus/.nix-profile
/nix/var/nix/profiles/per-user/layus/profile
/nix/var/nix/profiles/per-user/layus/profile-965-link
/nix/store/98g9gp49d7rq9s4gi0cnvzsppa1pq15l-user-environment
or use tree
$ tree /nix/var/nix/profiles
/nix/var/nix/profiles
βββ per-user
β βββ layus
β β βββ channels -> channels-8-link
β β βββ channels-8-link -> /nix/store/jnqmlqai4zsh9jl7nxxgrbq7hi08w7g4-user-environment
β β βββ profile -> profile-965-link
β β βββ profile-961-link -> /nix/store/j47259hsbcfyhfbi3cm2hhj1mdzk4a6h-user-environment
β β βββ profile-962-link -> /nix/store/cy87889ln7a64g43zpz0k8k6a2843gv3-user-environment
β β βββ profile-963-link -> /nix/store/2cbcd3n2zpdyjhli3qaa0p9yqbycm0h2-user-environment
β β βββ profile-964-link -> /nix/store/fvn0wnx0gr0mbq4src9pv2dj5ssnscmv-user-environment
β β βββ profile-965-link -> /nix/store/98g9gp49d7rq9s4gi0cnvzsppa1pq15l-user-environment
β βββ root
β βββ channels -> channels-52-link
β βββ channels-52-link -> /nix/store/41nvsyg6sjdswywmicr478wphqsgi5nc-user-environment
βββ system -> system-225-link
βββ system-223-link -> /nix/store/zav2p8819dbs1y80hvvf4dpkk45lp12n-nixos-system-ankh-morpork-19.09pre177651.aeb464dfd37
βββ system-224-link -> /nix/store/mjxa261axs2zsv3biyhi1xs7238va0g9-nixos-system-ankh-morpork-19.09pre177651.aeb464dfd37
βββ system-225-link -> /nix/store/kvh5fc2a57yi9m7nmkqdkkpkf33vc55i-nixos-system-ankh-morpork-19.09pre177651.aeb464dfd37
βββ system-profiles
This long post as a funny way to show you that this information is stored in the /nix/var/nix/profiles/per-user/$USER/profile
symlink ;-). Pick your way to extract it. I usually use tree for that, as it also shows you when it is time to collect garbage somewhere.
> nix search -u readlinks
error: no results for the given search term(s)!
Thanks for all the suggestions! Maybe this functionality could be added to Nix as:
nix-env --current-generation
Still needs a bit of polish, but it is now ready for packaging.
As you asked for it, here comes nix βintegrationβ
nix-build https://github.com/layus/readlinks/archive/master.tar.gz
Sorry to answer to this old question, but I took me a few minutes to understand why nixos-rebuild switch
was not creating new generation, and since this answer is the first one in google search I was thinking that it could be useful to others as well.
So the above code gives you the generations of the user profile (usually installed with nix-env
), but not the system generations (usually installed with nixos-rebuild switch
). To see list the generations of the system, use:
sudo nix-env --list-generations --profile /nix/var/nix/profiles/system
or if you just want to see the current one, you can use the trick given above in the thread, like:
sudo nix-env --list-generations --profile /nix/var/nix/profiles/system | grep current | awk '{print $1}'
Thats the correct command for new installations