Home Manager no home.nix and do not have home-manager command

I must be missing something basic. I’m following the official guide and installed as a module. (The docs didn’t say anything about stateVersion at this point so the instructions actually failed, but I got past that bit.)

But I hit chapter 2 which said I should have a file .config/home-manager/home.nix, which I didn’t. Okay, I’ll create one. Then I realized I don’t have the command home-manager. I do have a command homectl, but that seems to give dbus errors and other systemctl ones.

systemctl status "home-manager-$USER.service" shows the service enabled and active.

I’d appreciate any help on this. Thanks.

3 Likes

Hm, second person complaining about stateVersion, I guess there’s a path through the manual that isn’t exactly clear, probably should write an issue about this.

When installing home-manager as a NixOS module, you’re supposed to use it like a NixOS module, i.e., you don’t use the home-manager command at all. You also don’t use a ~/.config/home-manager/home.nix file, instead, you define your settings in the NixOS module.

I would recommend doing this, where the home-manager manual recommends setting a function:

home-manager.users.eve = import ./home.nix;

Then you can copy out the example home.nix, and continue from there.

Where the manual recommends home-manager switch, use nixos-rebuild switch instead. Rollbacks will also just function as they do on NixOS, there is no separate rollback for home-manager.

1 Like

Thank you very much. Knowing which command to run for “switch” definitely helps.

Since I’m new to this, could you confirm my undestanding that:

  1. When you say “use it like a module” you mean do everything in the /etc/nixos/configuration.nix file?

  2. The work-around you suggest isn’t necessary if I just edit the /etc/nixos/configuration.nix?

I appreciate your time,
Brian

PS. About the stateVersion, the error message was clear, and how to set it was just a little further down in the document. It just could have been mentioned earlier since following along exactly resulted in failure (with learning :-).

Yes. Files like /etc/nixos/configuration.nix are referred to as modules, which is a NixOS concept. Modules define options, which are then ultimately merged together and turned into derivations as well as an “activation” script which nix builds and runs when you use nixos-rebuild switch.

The derivations are generally small configuration files, systemd units, etc., and the activation script is in charge of putting them in the right places (and substituting all the symlinks) for your system to “switch” to the new configuration.

Modules can be attrsets (the things in {} that look like JSON objects) or functions that return an attrset (e.g. { pkgs, config, lib, ...}: {}).

All NixOS configuration is done in modules.

Technically the home-manager command also builds modules, but it is a separate module system with a different default entrypoint, and therefore the command doesn’t work if you use home-manager’s NixOS module.

Yes, instead of putting your module in a separate file, you can keep the little function definition as you have it now, and just paste all the example configuration in there instead. import just means “take everything from this file and put it here”.

I recommend keeping a separate file because it will grow and quickly become unmanageable. I also figure it makes it easier to copy around the example home.nix file, and generally follow the documentation which seems to assume you’re using home-manager standalone. It’s up to you, though.

1 Like

Ok, so it wasn’t a work-around, it was a recommendation. I’ll go with that.

As a general consideration, Is it best practice to do my system changes primarily in a .nix file somewhere else and import it into the primary /etc/nixos/configuration.nix file? I can see how such a file could quickly grow. I have a programming background and the idea of splitting big things into smaller things which are imported seems natural to me. Since nix is a programming language (right?) this would seem logical.

Brian

Yep, generally people do that, however usually using imports rather than individual imports. It’ll make more sense to tell you to look at my config than for me to try and explain that: https://github.com/TLATER/dotfiles/blob/128f6b3165d53afbaa5743fc0c5d71c698e3aa6c/nixos-config/yui/default.nix#L10

Basically, imports defines a list of modules to merge into this one. This will automatically concatenate any list options, for example, and throw errors if you set an option twice if it cannot be automatically merged. You’re probably already using it for hardware-configuration.nix.

The home-manager module cannot be included in a NixOS modules’ imports, because it is a separate module system. You can add an imports to your home-manager module, though, to import more home-manager modules.

Yep, it’s intended to be a DSL for software build instructions rather than a general-purpose language though. Doesn’t stop some people…

1 Like

Cool. Thanks for sharing your file. Worth a thousand words, as they say. Much obliged.

Get BlueMail for Android