The nix module in home-manager and nixos

I’m trying to get my head around the purpose of the home-manager nix module introduced in PR #2623. Looking at Issue #2324 which prompted the addition, it seems like it was based on the nix nixOS module. I’m trying find documentation on the nixos module in order to better understand the new home-manager module, but I can’t seem to find it anywhere. The nix nixos module specifically is ungoogleable, because the results are all about nixos modules in general.
Does this documentation exist?

Basically what I want to know is: Currently I have nix installed via nix profile (Non nixOS). Does the home-manager nix module provide a way of installing it declaratively in my home configuration instead? Is this an impulse that actually makes sense and is a good idea? 2324 mentions an enable setting, (presumably referencing something that exists in the nixos module) but it doesn’t seem to exist in the home-manager module.

2 Likes

The point is not (just) to install Nix itself declaratively, but to configure it declaratively.

The structural nix.settings will be used to generate nix.conf. For example,

{ config, ... }:
{
  nix.settings.experimental-features = [ "nix-command" "flakes" ];
}

will generate a nix.conf with

experimental-features = nix-command flakes

Aside from nix.conf, we still have nix.registry to generate registry.json declaratively, and the latter controls the local flake registry.

2 Likes

Luckily, there is NixOS Search :wink:

Sadly it looks like the configuration options link in the search results is broken, for now check nix.conf - Nix Reference Manual

1 Like

That makes sense, thanks. You say (just), implying that it is also for installing nix declaratively as well as configuring, right? Is this only functionality only available on nixOS?

More generally, I was hoping to learn how to learn these sorts of things without posting on the forum. Is this stuff documented anywhere?

Most of the documentation for nix modules is in their option descriptions. If you look at the .enable result in the search I linked, for example, you get an answer to your first question:

Whether to enable Nix. Disabling Nix makes the system hard to modify and the Nix programs and configuration will not be made available by NixOS itself.

And that is enabled by default. So yes, if you disable this, nix will not be installed on NixOS - refer to the home-manager options docs for how it interacts with this, I suspect it is also capable of managing the nix installation for the user (and thereby shadowing the system version).

Ah, nice, I forgot I could search for modules not just packages, thanks! (Since I’m not a nixOS user)

1 Like

Yeah, that would have been my assumption, which was why I was confused that there doesn’t seem to be an analogous enable option. I guess it must be the nix.package option, and perhaps I’m supposed to also add nix to my home.packages? I find the docs a little confusing here. I guess I’ll have to experiment.

Hm, I had a quick look, the nix module isn’t very complex: https://github.com/nix-community/home-manager/blob/ff5133843c26979f8abb5dd801b32f40287692fa/modules/misc/nix.nix#L215

Seems like it doesn’t manage the installed nix version. I’ve not seen any references to it elsewhere either, looks like you do indeed need to add it to your home.packages. That surprises, me, I could have sworn I’ve managed to update nix via home-manager before.

Probably worth opening a PR to clarify this in the docs, or maybe even to add an enable option.

1 Like

I decided to ask about the rationale for the lack of the enable option on the PR that added the module. Perhaps there’s a good reason for it that should inform how the docs ought to be updated.

That PR only adds nix.registry which is already really cumbersome to use in NixOS. I would highly recommend to just use the nix registry command and a dotfile manager that is not in your way like yadm, stow or similar.

It should work as long as you get the modular system concerned work on your platform. That is, if you’re doing the configuration inside Home Manager, the Nix package should be installed as long as Home Manager works alright.

Home Manager people are working to make it “NixOS Search”-able.

https://github.com/NixOS/nixos-search/issues/323

https://github.com/nix-community/home-manager/pull/2971

Before that, just take a look at the Home Manager Manual. Issues and PRs about the documentation also goes to the Home Manager GitHub page.

https://nix-community.github.io/home-manager/options.html#opt-nix.package

1 Like