Understanding home-manager api

Hi all.

I was wondering if someone could help me understand home-manager a little better.
I’ve noticed that a few people use home-manager.lib.homeManagerConfiguration instead of home-manager.nixosModules.home-manager as mentioned in the home-manager manual.
For example I wanted to setup NVF to manage neovim configs and came across this lib.homeManagerConfiguration syntax in their documentation:
https://notashelf.github.io/nvf/#sec-example-installation-hm

Since it’s not mentioned in the manual I tried to understand the flake source:

I got stuck pretty quickly by they fact that home-manager.nixOSModules.home-manager appears to be a function instead of a path? How does this work?

      nixosModules = rec {
        home-manager = ./nixos;
        default = home-manager;
      };

In a repl:

:t inputs.home-manager.nixosModules.home-manager
a function

Perhaps, it has something to do with the overrides at that bottom of the file?

I’m more trying to get a better understanding of how things work than trying to just use NVF.
TIA

Both options are mentioneed in the manual:

And on top of that there is also the nix-darwin module.

homeManagerConfiguration does not appear to be mentioned in that section or on that page at all.
So I’m guessing you just know this from experience?

I should be able to do exactly the same thing with a NixOS module that I would do with the standalone setup?

I tried this:
home.nix

  imports = [
    inputs.nvf.homeManagerModules.default
    ...
  ]

This result in an infinite recursion error

error:
       … while calling the 'head' builtin
         at /nix/store/f30jn7l0bf7a01qj029fq55i466vmnkh-source/lib/attrsets.nix:1574:11:
         1573|         || pred here (elemAt values 1) (head values) then
         1574|           head values
             |           ^
         1575|         else

       … while evaluating the attribute 'value'
         at /nix/store/f30jn7l0bf7a01qj029fq55i466vmnkh-source/lib/modules.nix:816:9:
          815|     in warnDeprecation opt //
          816|       { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |         ^
          817|         inherit (res.defsFinal') highestPrio;

       … while evaluating the option `system.build.toplevel':

       … while evaluating definitions from `/nix/store/f30jn7l0bf7a01qj029fq55i466vmnkh-source/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `assertions':

       … while evaluating definitions from `/nix/store/cd0q2vk9vqwjg9rcilymm4x8f4n673zi-source/nixos/common.nix':

       … while evaluating the module argument `inputs' in ":anon-5:anon-1":

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: infinite recursion encountered
       at /nix/store/f30jn7l0bf7a01qj029fq55i466vmnkh-source/lib/modules.nix:515:28:
          514|         addErrorContext (context name)
          515|           (args.${name} or config._module.args.${name})
             |                            ^
          516|       ) (functionArgs f);

I think I must be missing something fundamental :frowning:

In my memories some earlier version of the manual bootstrapped the flake “manually” rather than using a generator.

Where does inputs come from?

1 Like

Or from the standalone template in the HM repo.

And if you go one folder up, there are other templates for the nixos module setup as well as nix-darwin.

Yes, you didn’t pass inputs into the module system via home-manager.extraSpecialArgs.
It’s vaguely alluded to here:

1 Like

I think home-manager.lib.homeManagerConfiguration is when you use a standalone homemanager.

Use home-manager.nixosModules.home-manager if you run nixos and to update home-manager with nixos-rebuild

2 Likes

Okay, thanks that was indeed the issue.

I had specialArgs passing inputs to lib.nixosSystem, so I thought that was sufficient.

Why does this end in infinite recursion though and not just a parameter not defined?

None the less, thanks @waffle8946 and @NobbZ for the help.