Skip to content

nixos-rebuild-ng: use nix-env --list-generations everywhere - #567183

Draft
thiagokokada wants to merge 2 commits into
NixOS:staging-nixosfrom
thiagokokada:nixos-rebuild-ng-use-nix-env-for-list-generations-everywhere
Draft

thiagokokada wants to merge 2 commits into
NixOS:staging-nixosfrom
thiagokokada:nixos-rebuild-ng-use-nix-env-for-list-generations-everywhere

Conversation

@thiagokokada

Copy link
Copy Markdown
Contributor

Now that NixOS/nix#16523 is merged, we can remove the previous nix.get_generations() that was basically an reimplementation of nix-env --list-generations in Python. This renames the previous nix.get_generations_from_nix_env() to nix.get_generations() too.

For context, the reason we had nix.get_generations{,from_nix_env}
before was:

  • For nixos-rebuild list-generations, we want to run it as a normal (i.e., non-root) user.
  • For nixos-rebuild switch --rollback, it doesn't matter if the user is root or not, but we want to also allow the user to run this for remote hosts (the Python code only worked locally).

So nix.get_generations() covered the first case (locally without root), and nix.get_generations_from_nix_env() covered the second case (remotely with root). Now nix-env --list-generations works without root we can always use it.

Fix #435555.

Things done

Now that NixOS/nix#16523 is merged, we can
remove the previous `nix.get_generations()` that was basically an
reimplementation of `nix-env --list-generations` in Python. This renames
the previous `nix.get_generations_from_nix_env()` to
`nix.get_generations()` too.

For context, the reason we had `nix.get_generations{,from_nix_env}`
before was:
- For `nixos-rebuild list-generations`, we want to run it as a normal
  (i.e., non-root) user.
- For `nixos-rebuild switch --rollback`, it doesn't matter if the user
  is root or not, but we want to also allow the user to run this for
  remote hosts (the Python code only worked locally).

So `nix.get_generations()` covered the first case (locally without
root), and `nix.get_generations_from_nix_env()` covered the second case
(remotely with root). Now `nix-env --list-generations` works without
root we can always use it.
This check is incorrect for remote targets (we need to check the remote
not the local if the profile path exists).

Moving the check to the callers of the function instead when we return
no generations.
@thiagokokada

Copy link
Copy Markdown
Contributor Author

Waiting until NixOS/nix#16523 is released in a stable version and that version becomes the default in nixpkgs (I imagine this will be the Nix 2.36).

@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. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS labels Sep 26, 2026
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.

1 participant