How to make nix shell use my home-manager flake input?

I have nixpkgs as a flake input to my home-manager configuration flake.

How can I configure my registry so that nix shell nixpkgs#... will use the input that is locked in my configuration flake?

There is a gotcha when pinning nixpkgs registry entry to a hardcoded path in the /nix/store. That is, any flakes you develop locally which reference nixpkgs indirectly via the registry will lock your store path, possibly breaking downstream consumers. Because of this, on my nixos system, I pin a nixos registry entry instead. If you are only using home-manager you could call it whatever you what, like localpkgs or something.

Try nix shell --inputs-from ~/.config/home-manager foobar

It won’t touch your registry though. Works just for this command.

The problem is relying on the registry in your flake…

The registry is nice to use on the CLI, but a footgun within a flakes input. I use flakes for 3ish years now, and am still (or even more) the opinion that we should remove flake:* input URLs and especially “implicit” inputs through the argument set.

1 Like

I have

nix.registry = {
       nixos = {
         from = { type = "indirect"; id = "nixos"; };
         flake = args.nixpkgs;

in my hm config to avoid re-download and re-evaluation of nixpkgs every time I do a nix search nixos foobar and to avoid massive downloads on every nix shell invocation.


Can you expand on that? Are you using the flake version of home-manager? Because in my flake based config there is no args.

Yes, I’m using a flake based setup.

Using the HM-Module on NixOS my HM config starts with args@{ config, pkgs, ... }: and I pass nixpkgs from the system flake.

Similar on a Ubuntu machine where I have only HM-flake. I have extraSpecialArgs = { inherit (inputs) nixpkgs }; which is captured in args as above.

1 Like