Messed up my home-manager installation by trying to run off of local nixpkgs

I was trying to play around with a few changes I had made in my local nixpkgs repository, and ran
NIXPKGS=/path/to/local/nixpkgs-repo home-manager switch -I nixpkgs=$NIXPKGS and this command ended up failing, and I didn’t pay it much mind and then went to rebuild my home-manager config with some other changes I’d made (just a regular home-manager switch), and ended up getting the following error:

building of '/nix/store/jdcsyf68pllqlhnw6svj82gh2sv0x91l-home-manager.drv': done
building of '/nix/store/a2qv6qj2hyy6021j8aihy7xzlyv1xmgi-stdenv-darwin.drv': init
building of '/nix/store/a2qv6qj2hyy6021j8aihy7xzlyv1xmgi-stdenv-darwin.drv': loading derivation
acquiring write lock on '/nix/var/nix/temproots/4597'
downgrading to read lock on '/nix/var/nix/temproots/4597'
building of '/nix/store/a2qv6qj2hyy6021j8aihy7xzlyv1xmgi-stdenv-darwin.drv': have derivation
acquiring write lock on '/nix/var/nix/temproots/4597'
downgrading to read lock on '/nix/var/nix/temproots/4597'
building of '/nix/store/a2qv6qj2hyy6021j8aihy7xzlyv1xmgi-stdenv-darwin.drv': done
substitution of '/nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25b-default-builder.sh': goal destroyed
building of '/nix/store/wn3akngcixc9nlnw672mixr6qqxb2gd5-bash-interactive-4.4-p23.drv': goal destroyed
building of '/nix/store/r35hhb4wxy7i4mpzf1rnh0h351nxkkzx-bash-4.4-p23.drv': goal destroyed
building of '/nix/store/a2qv6qj2hyy6021j8aihy7xzlyv1xmgi-stdenv-darwin.drv': goal destroyed
building of '/nix/store/jdcsyf68pllqlhnw6svj82gh2sv0x91l-home-manager.drv': goal destroyed

Creating initial Home Manager generation...

warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: infinite recursion encountered, at /nix/store/2rvfm90ydwrwfr02ddbv68y135xkb2gm-nixpkgs-21.03pre243111.51428e8d382/nixpkgs/lib/modules.nix:262:28
(use '--show-trace' to show detailed location information)
warning: Nix search path entry '/nix/var/nix/profiles/per-user/root/channels' does not exist, ignoring
error: infinite recursion encountered, at /nix/store/2rvfm90ydwrwfr02ddbv68y135xkb2gm-nixpkgs-21.03pre243111.51428e8d382/nixpkgs/lib/modules.nix:262:28
(use '--show-trace' to show detailed location information)
/nix/store/2v1qv6scb5b6bk19jb3h2qcks17yqjvj-home-manager/bin/home-manager: line 127: /var/folders/m6/fbrn9lkj3bzb7hng9t7q810m0000gn/T/home-manager-build.XbbmNNwRKD/news-info.sh: No such file or directory

I played around with it for a few minutes, but decided I’d just re-install nix, nix-darwin, and home-manager entirely in order to save myself an afternoon from debugging. When I went to re-install home-manager nix-shell --show-trace '<home-manager>' -A install I ended up with the same error again during the initial generation creation, and I’m stumped how to fix it. When I ran it before with --show-trace, it had a message about infinite recursion in pkgs.lib.modules, but I cannot figure out how to get the --show-trace to pass through to the home-manager installer. Everything built properly up until I’d tried the -I flag mentioned above.

The command you used expands $NIXPKGS into whatever value it has before that line. The NIXPKGS you set in that line, does not affect the expansion for -I.

That might cause trouble in the nixpkgs loading.

I’m kind of surprised that it’s still broken after removing everything (that I know of) and rebooting and reinstalling… Not sure if maybe something got written somewhere I don’t know about maybe?

What would be the correct way to try and force it to read nixpkgs from the channel?

Thanks to help from @rycee on IRC the real cause of the issue was due to a badly formed import statement, which was causing the recursion:

imports = if pkgs.stdenv.isLinux then [ ./linux-home.nix ] else [ ];