How does HomeManager know nixpkgs version if it's a flake which has its own imports?

I am experimenting with system configuration and home-manager flakes, and I’ve hit a dead end.

flake.nix:

# ...
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };
# ...

This is my first time installing HM. So, when I ran this code, I saw a warning:

trace: warning: monkpatch profile: You are using

  Home Manager version 24.05 and
  Nixpkgs version 23.11.

I came to a conclusion, that because of inputs.nixpkgs.follows, home-manager’s nixpkgs have version 23.11 (as my nixpkgs that I imported a few lines above), while it depends on unstable nixpkgs.

Okay, I decided to remove the this line. When I removed flake.lock and rebuilt, in the new flake.lock I had two entries with nixpkgs - one from my flake.nix (version 23.11) and one which HM uses (version unstable).
So, I supposed that had to remove the warnings, because now home-manager uses the nixpkgs it wants to use (unstable). But it didn’t!

I started looking into some source codes to understand, why does our nixpkgs version affect home-manager’s anything. Okay, I went to HM’s github and found this line.
So, it treats lib.trivial.release as the version of nixpkgs.
But as lib comes from nixpkgs, and home-manager imports unstable one, why does it have 23.11 version? Or did I not understand the code correctly? I’m completely confused right now.

Your are using inputs.nixpkgs.follows to override the nixpkgs version for home-manager. So you are using the unstable/master branch of home-manager, but feeding it nixpkgs on the nixos-23.11 branch.

If you intend on staying on the stable channel, you should add /release-23.11 to the end of the home-manager url so that the channels match.

If I remove inputs.nixpkgs.follows, the warning still appears. But in flake.lock (still, only if I remove that line) it says that home-manager references nixpkgs of version unstable. I can upload the flake.lock file if it helps.

No need for the flake.lock. Do you use the home-manager as a NixOS module? Perhaps that would be how it knows what version of nixpkgs you are using.

I found the answer!

line 20:
Was before (gave warning):

nixosConfigurations.default = nixpkgs.lib.nixosSystem { modules = [ ./configuration.nix home-manager.nixosModules.home-manager ]; };

Now (doesn’t give warning):

nixosConfigurations.default = home-manager.inputs.nixpkgs.lib.nixosSystem {modules = [ ./configuration.nix home-manager.nixosModules.home-manager ]; };

So, I suppose, nixosSystem when imported home-manager, passed its nixpkgs, which are in first case local ones, and in the second case, the ones that home-manager imported.
So before it passed local 23.11 nixpkgs and now it passes unstable so warning disappears.
Do I understand this correctly?

Seems like the nixpkgs is passed through to home-manager when imported that way.

Is there any reason you are running NixOS and home-manager on different channels?

I configure my system inside a flake, and as far as my intuition goes, channels don’t really matter in this case.

Someone in Discord also answered me. nixosSystem passes down to modules its own nixpkgs, so they are the same, the same on which lib.nixosSystem is called. (So, two code snippets above with two different versions passed there).

So, if I use regular nixpkgs (23.11) to call lib.nixosSystem, then inside home-manager it passes nixpkgs (23.11). And if I call (home-manager.inputs.nixpkgs) to call lib.nixosSystem, then home-manager gets exactly the version it wants.

Why not use home-manager from the release-23.11 branch instead of master?

Sure, with flakes the channel functionality does not matter, but you still specify which branch of each flake input you are using.

Right now the flake inputs are mismatched, you can continue to use the follows functionality, switch home-manager to 23.11 to match nixpkgs on nixos-23.11, then it won’t matter how you call lib.nixosSystem, and it won’t complain.

Yes, thanks, this works, and it solves the initial problem I encountered.

My question was rather because of curiosity, to better understand how everything works.

Have a great day!

1 Like