Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix profile is missing a way to switch profiles #8560

Open
iFreilicht opened this issue Jun 21, 2023 · 0 comments
Open

nix profile is missing a way to switch profiles #8560

iFreilicht opened this issue Jun 21, 2023 · 0 comments
Labels
feature Feature request or proposal

Comments

@iFreilicht
Copy link
Contributor

Is your feature request related to a problem? Please describe.

To stabilize the new CLI, the new CLI commands should have feature parity with the ones they replace. nix profile in particular is missing a way to switch profiles like it is possible with nix-env --switch-profile.

Describe the solution you'd like

I would like there to be the following command:

nix profile switch-profile <profile-path>

It should change the default profile symlink as nix-env --switch-profile already does.

The command should output what the current profile being switched from is, what the profile being switched to is, and which symlink got changed as a result. This is important, as there are multiple default locations for the profile symlink and profile directory depending on configuration options and user.
The command should also output what was removed from the user environment during the switch. For now, a simple diff-closures would be enough. Not sure how this would work with an empty profile. If #1807 was fixed, we could diff against the 0th generation.

If the profile doesn't exist yet and the session is interactive, the user should be informed about the absolute path the profile will be written to on the first nix profile install invoaction, explain that profile generations will be created side-by-side and asked to confirm the location. I believe this is necessary to protect users from flooding a directory with symlinks if they don't expect it and to ensure they are not confused when they try to access the profile through the symlink before installing anything and get an error.

Describe alternatives you've considered

Calling the command nix profile switch. This is possible, as switching generations is covered by nix profile rollback. But nix-env uses the verb switch in both --switch-generation and --switch-profile, so this could be very confusing for users that are transitioning. Both the manual and the CLI itself also already use the verb switch for this action:

  • Switch your default profile to version 510:
# nix profile rollback --to 510
switching profile from version 518 to 510

From the nix profile rollback docs

Additionally, switching profiles is not as common of an action as switching generations, so in the light of all of that, I'd rather leave the option open of making switch an alias for rollback --to.

Other command verbs could be change-default, make-default, set-to, set-default. I don't have a strong opinion about this yet.

I was considering whether a --dry-run flag might be a good idea, but nix-env --switch-profiles didn't support it, so it's not required for feature parity. It might still be a good idea, as switching profile is a potentially destructive action.

In light of the different configurable defaults, a --to-default option might also make sense, but I think it's out-of-scope and would be a separate feature request.

I thought about creating a 0th profile generation automatically with this command to make the diff-closures functionality easier and fix #1807 at the same time, but this opens a huge can of worms and comes with many open questions and potential issues.

Additional context

This is part of a general effort to improve the nix profile UX, see #7966.

Priorities

Add 👍 to issues you find important.

@iFreilicht iFreilicht added the feature Feature request or proposal label Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal
Projects
None yet
Development

No branches or pull requests

1 participant