I am currently using home-manager in the standalone configuration. I am thinking about making some changes and need some feedback.
I would like to keep separate configuration.nix and home.nix files.
I would like to play around with Hyprland, and it is recommended to use a flake.
I would like to be able to build my entire system with one command (i.e. sudo nixos-rebuild switch).
I don’t use git to store my configuration, so this doesn’t need to be a consideration.
I think where I need to go is to switch to using home-manager as a module, perhaps as a flake? I don’t even really understand the difference or what that means.
So my questions are as follows:
How do I both run home-manager as a module and keep it as a separate file? Is this even possible? The documentation here 1.2. NixOS module only describes how to use home-manager as a module by putting all the home-manager config within configuration.nix.
When I setup home-manager as standalone, I was instructed to issue the following: nix-shell '<home-manager>' -A install. If I switch to home-manager as a module, do I need to undo this? If so, how? What did it do? What do I do with all the home-manager generations that have been collected (I think those are no longer generated as a module)?
Should I use a flake for my home-manager setup? If so, where does it go? The documentation here 3.3. NixOS module says it goes in /etc/nixos.
If I setup Hyprland using a flake, does it use the same flake.nix, or do you setup multiple flake.nix files? The answer to this might seem obvious to those familiar with flakes, but as a newbie, documentation for various programs always says things like “or you can use a flake.nix”. It’s unclear whether individual programs require their own flake.nix files, and if so, where they go.
I think I’ll stop there for now. If I can get these things answered, I am sure I will be able to make some progress before I need more help. Thanks.
OK. I found an old video by Wil T that addresses much of what I am looking to do: https://youtu.be/mJbQ--iBc1U. It is a very well done video, but unfortunately it is a little out of date (it is 1.5 years old) and I have run into a couple of stumbling blocks:
The first is that v22.11 made some changes to homeManagerConfiguration.
NixOS now wants to see it formatted slightly differently, as mentioned here E.2.1. Highlights. I have taken a stab at what the changes would look like below:
You’re converting to a flake, but still standalone, without a nixos configuration in sight, which is probably not what you want. All 4 combinations of flake/not + standalone/module are possible. It sounds like you want flake + module.
My advice would be to focus on one transition at a time. Either move to a module without trying to make it a flake, or make your nixos config a flake, then upon successfully doing that, incorporate home-manager as a module.
However, if you want to jump straight there, the most basic flake.nix you’ll need is something like this:
Hey, thanks so much for your reply. Yes, I made some progress between post 1 and post 2. My configuration now has home-manager running standalone as a flake. I am OK with that for now. Also, I just didn’t show my nixos configuration in those snippets, but it’s there and working fine.
My new questions revolve around how to install unfree and unstable packages with home-manager.
IIRC, home-manager, when used standalone in a flake like this, has allowUnfree broken for some reason. At least it did, and I’m assuming it hasn’t been fixed, since you’re having trouble with it. Use allowUnfreePredicate = pkg: true; instead, for now.
It’s difficult to help you without something clear to reference. You’ve posted snippets of code without full context, and have multiple things you’re considering doing. I’m never sure what you’re assuming.
Nothing to do with nixos… it’s home-manager that wants that.
As far as I know there’s some kind of black magic going on under the hood that makes it so setting it to nixpkgs.legacyPackages.${system} still allows configuration, but setting it to other instantiations of nixpkgs doesn’t. However, ever since that change, allowUnfree has been broken, but allowUnfreePredicate works as a workaround.
No, since you’re not using that pkgs value for home-manager in the first place (I think… again with the point of reference problem), it doesn’t matter.
If you set pkgs = nixpkgs.legacyPackages.${system};, then you need to configure nixpkgs with the home-manager options for that purpose. (nixpkgs.*) This normally works, but allowUnfree in particular didn’t at one point and may still not. The predicate thing is a workaround to this.
If you set pkgs = import nixpkgs { inherit system; config = ...; }; (directly or indirectly) then you configure it right there in that expression.
I’d like to query part of the OP’s first list of questions (that didn’t get addressed as far as I can tell)
One of your initial questions was:
When I setup home-manager as standalone, I was instructed to issue the following: nix-shell '<home-manager>' -A install. If I switch to home-manager as a module, do I need to undo this? If so, how? What did it do? What do I do with all the home-manager generations that have been collected (I think those are no longer generated as a module)?
I don’t think anyone actually answered this specifically… it’s related to where I get a little stuck in configuring home-manager as a module and implementing the config as a flake.
I’ve never yet done the standalone install of home-manager (as in nix-shell ‘’ -A install). It may be actually required to install home-manager via nix-shell… but I’ve yet to see this stated anywhere! nix-shell '<home-manager>' -A install? And, is there some ‘order’ I should have done all this? (eg: -install , then do home-manager as a module, then config in a flak?
I went deep with nixos by using it as my daily driver from day 1 (about a month ago). I’d like to code up all my dotfiles etc, before replacing all my linuxes with nixos… and doing home-manager without a flake sounds like something I’ll have to jump into at some point, so why not start now?
I really dig the design of nix… and wanna keep going in adoption.
You don’t need to do anything special when switching from a standalone install to a nixos module install. If you set home-manager.useUserPackages = true; in your nixos options, when using home-manager as a nixos module, you do need to delete the home-manager-path package from your nix-env/nix profile environment.
There’s no “order”. They’re just different ways home-manager can be set up. You can start with any of them, or switch later. The only switch that requires an extra step to clear up state issues is the userPackages thing afaik. Pick how you want to use home-manager, and run with that without going for any “in between” steps. There are none.
I’ve been reading the occasional reference to home-manager-path - but the exact way this ‘clicks in’ eluded me because I
1 started with nixos and /etc/nixos contents
2 read about home-manager and flakes and decided I needed to get there before I was confident enough to switch all my (within reason) linux boxes to this… getting a bit ahead of myself no doubt.
Have a daily driver on 1) above, trying to crack the code of everything I’d like to master on a test box… got to config in flake pretty quickly (with home-manager in module)…I guess I just went in circles before I go hardcore into coding up dotfiles etc.