`home-manager switch` not compatible with nix-env?

I recently added a package to my home-manager configuration, and on home-manager switch I get this output:

/nix/store/6670viw5i1jch7bm9iz01qg2d3sj1hzd-home-manager-generation
Starting home manager activation
Activating checkFilesChanged
Activating checkLinkTargets
Activating writeBoundary
Activating installPackages
error: --- Error ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- nix-env
profile '/nix/var/nix/profiles/per-user/roni/profile' is incompatible with 'nix-env'; please use 'nix profile' instead

I believe this started happening after I used nix profile to install a flake-based package (see this topic for my explorations in that area).

This wiki page explains how to “switch back” to nix-env after using nix profile, but the recommendation is to manually intervene in the profile directory on disk, and I don’t want to do that without first understanding how my problem actually originated.

So, my main question is:

  • How do I get home-manager working again?

And, a bonus question:

  • How do I install a flake-based package via home-manager?

Thanks!

And that’s exactly how I would do it, and then just run home-manager switch again. If your home-manager does not come from your NixOS system environment, you may need to call it into place one way or another, such as with nix-shell -p home-manager.

If you ask me, nix-env (as a front-end tool) and any reference to it should be killed with fire. It just confuses the hell out of people: both in terms of this kind of breakage, as well as, and more importantly, by creating the impression that it makes any sense at all to interact with a nix environment imperatively. (It’s something else to interact imperatively with the declarations, such as niv does.)

1 Like

Home manager currently uses nix-env to manage the home-manager profile and it’s generations.

You can not use home manager any more after you made your user environment managed through nix profile until you switch back to nix-env.

You can install from flakes using home manager by making it a flake itself or by wrapping the flake you want to install from in flake-compat.

2 Likes

I destroyed my profile, then reactivated home-manager and things are back how they were; thank you both for that advice.

@NobbZ, would you mind pointing me to an example of both “making it a flake itself”, and of using flake-compat? I have googled and not found any good examples to use as a springboard for my own setup. Thanks in advance!

My config would be an example of making the HM config itself a flake.

It is currently written in a way that I can’t use home-manager … --flake, but instead I build the activationPackage manually and then run the activation script from ./result/activate.

Since everything is currently in the process of getting joined with my system flake (not config though!) It’s some messy piece of s*** right now :wink: I really need to tidy it up.

I sadly can’t give you an example of how to use flake compat though. I know about it’s existence, but never used it. I did a full switch to flakes and never needed any compatibility tooling.

1 Like

Thank you!

I have asked enough of you already, @NobbZ, but if you have capacity and desire to do so, I’d love a deeper understanding of how this works, and specifically how you wire this into your running system. Or perhaps that question is not worthwhile to answer until you’ve had that chance to “tidy it up”.

Thanks again!