Equivalent of `nix-env --set-profile` with `nix profile`?

I’ve been fooling with this today and I almost just want to sanity check my understanding because of how often these change. Not complaining about changes JFC.

Is this a sin?

nix-env --set-profile ~/.dev-profile;
nix profile install 'nixpkgs#bar';
bar;
nix-env --set-profile ~/.work-profile;
nix profile install 'nixpkgs#foo' ;
foo;

nix-env --set-profile ~/.dev-profile;
bar;

Because the only alternative I really see without nix-env is:

nix profile install 'nixpkgs#foo' --profile ~/.work-profile;
nix profile install 'nixpkgs#bar' --profile ~/.dev-profile;
ln -sf ~/{work,nix}-profile;
# Activate manually or something? 
foo;
ln -sf ~/{dev,nix}-profile;
# Activate manually or something?
bar;

I’m just over here thinking nix-env and nix profile are mortal enemies that blow up your environment if you accidentally mix them; so I’m just making sure that this is the expected pattern.

I’d say you’re actually correct! nix-env --switch-profile $profile really is just:

ln -sf $profile $HOME/.nix-profile

And no there’s no extra ‘activate’ step. If you check the source code you can see:

This would remain true as long as generations work like the current design.

nix-env has two sides. One side is, as you mentioned, installs and uninstalls stuff from a profile and is the mortal enemy of nix profile. The other side with --set, --list-generations, etc. just juggles around a bunch of symlinks, which you can pretty much replicate with a few shell commands (or in this case, a single one).

1 Like

Cool just wanted to make sure it was sometimes kosher to mix these