Skip to content

nixos-rebuild-ng: replace get_generations with a shell-based approach - #560972

Closed
thiagokokada wants to merge 1 commit into
NixOS:staging-nixosfrom
thiagokokada:unify-get-generations
Closed

thiagokokada wants to merge 1 commit into
NixOS:staging-nixosfrom
thiagokokada:unify-get-generations

Conversation

@thiagokokada

Copy link
Copy Markdown
Contributor

Port the old Python logic to POSIX's shell and remove the usage of nix-env --list-generations.

While the original objective of nixos-rebuild-ng was to avoid having logic written in shell scripting, the only way to unify the two separate approaches of get_generations was to write this in shell, because we also need to run this remotely, but sadly calling nix-env --list-generations needs root (NixOS/nix#5144).

This also fixes a long standing issue of nix-collect-garbage causing the nixos-rebuild list-generations to report the wrong build-date after a nix-collect-garbage or nix store optimise.

Fix #435555.

Things done

@thiagokokada
thiagokokada marked this pull request as ready for review September 7, 2026 18:09
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes. 9.needs: reviewer This PR currently has no reviewers requested and needs attention. 2.status: merge-bot eligible This PR can be merged by commenting "@NixOS/nixpkgs-merge-bot merge". 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS labels Sep 7, 2026
@thiagokokada
thiagokokada force-pushed the unify-get-generations branch 3 times, most recently from 2c4a0d3 to b863045 Compare September 7, 2026 18:28
@thiagokokada

Copy link
Copy Markdown
Contributor Author

CC @r-vdp could you help review this PR?

@r-vdp

r-vdp commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

CC @r-vdp could you help review this PR?

I'm currently on holidays for another 10 days trying to stay away from my laptop as much as possible. But I'll take a look and test this once I'm back home!

@thiagokokada
thiagokokada requested a review from r-vdp September 11, 2026 12:16
@thiagokokada
thiagokokada force-pushed the unify-get-generations branch 3 times, most recently from 4f44831 to 209d185 Compare September 11, 2026 12:29
@nixpkgs-ci nixpkgs-ci Bot removed the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Sep 11, 2026
@thiagokokada

Copy link
Copy Markdown
Contributor Author

I'm currently on holidays for another 10 days trying to stay away from my laptop as much as possible. But I'll take a look and test this once I'm back home!

Friendly ping @r-vdp. Hope you got some good holidays.

Comment thread pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py Outdated
Comment thread pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py
Comment thread pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/get_generations.sh Outdated
Comment thread pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/get_generations.sh Outdated
@nixpkgs-ci nixpkgs-ci Bot removed the 2.status: merge-bot eligible This PR can be merged by commenting "@NixOS/nixpkgs-merge-bot merge". label Sep 24, 2026
Port the old Python logic to POSIX's shell and remove the usage of
`nix-env --list-generations`.

While the original objective of `nixos-rebuild-ng` was to avoid having
logic written in shell scripting, the only way to unify the two separate
approaches of get_generations was to write this in shell, because we
also need to run this remotely, but sadly calling `nix-env
--list-generations` needs root (NixOS/nix#5144).

This also fixes a long standing issue of `nix-collect-garbage` causing
the `nixos-rebuild list-generations` to report the wrong build-date
after a `nix-collect-garbage` or `nix store optimise`.

Fix NixOS#435555.
@thiagokokada

Copy link
Copy Markdown
Contributor Author

@r-vdp Done, can I get a re-review?

@thiagokokada

thiagokokada commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor Author

So I got the issue that made using nix-env --list-generations fixed at nix: NixOS/nix#16523.

I assume we will get this fixed in the next nix release. Once this is done and the new nix version becomes the default I can remove the nix.get_generations() and keep just nix.get_generations_from_nix_env() only.

@thiagokokada
thiagokokada deleted the unify-get-generations branch September 26, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 11.by: package-maintainer This PR was created by a maintainer of all the package it changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants