Hello. I pinned nixpkgs in home manager and I want to use imports like in the following example to break configuration down into manageable pieces. I can’t find docs on how it works exactly.
Do the arguments to functions { config, pkgs, ... }: in the imported files come from channels? Or from files that imported them?
##### home.nix #####
# The pkgs var that come from channels is overshadowed
# and essentially discarded in the let closure.
{ config, pkgs, ... }:
let
pkgs = import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/bca9437d1eae9519b61a58f2593f25f65494f8e9.tar.gz";
}) {};
in
{
imports = [ ./emacs.nix ];
# ...
}
##### emacs.nix #####
# Where does the pkgs var come from: from the let closure above?
# Or from channels?
{ config, pkgs, ... }:
in
{
home.packages = [
pkgs.emacs
];
}
Should I copy the let closure to all imported files?
Ah, sorry, I misread your message when I was writing my previous message. You wrote “hm+flakes is broken” not “hm+npins is broken”. Hm. This means I should stick with npins then.
The blogpost already explains how to set NIX_PATH correctly. Your let expression will cause problems because there’s a mismatch between pkgs the module arg and what you want to use as your nixpkgs instance, because things like programs.whatever.enable will still use the module arg’s value.
@waffle8946, what do you think about the approach in this config? It’s close to what’s described in the blog post, yet different, and to me, it’s much simpler. It seems it can be adopted to be used with home-manager.
Yes, there’s multiple (though ultimately similar) approaches to this. sanix is doing the same thing (setting nix.path to affect NIX_PATH) but instead of an indirection via the flake registry it’s just using pkgs.path directly.
Oh I thought you’d need to doubly rebuild w/ sanix but it seems like that’s addressed via this script:
Of course you’ll have to tweak nixpkgs/path.nix slightly for npins.
That’s similar to jade’s script under “Fixing the UX issues”, which achieves the same effect. Doesn’t seem like sanix is simpler, the complexity appears to be similar.
Yeah, not simpler, but easier to me personally, because I’m not familiar with flakes at all.
Do I understand correctly that in my case I should mostly replace the very last line in the script and use something like this? And remove all mentions of nixos-config, because they are not needed?
exec home-manager "$@" -I nixpkgs="$nixpkgsPath"
I mean, besides removing channels and other steps.
Should work, though depending on where your hm config is located, you’ll also want to add -I home-manager="/path/to/your/hm/config.nix" to that command
I’d like to set nix.nixPath just like in the sanix example.
# Makes commands default to the same Nixpkgs, config, overlays and NixOS configuration
nix.nixPath = [
"nixpkgs=${pkgs.path}"
"nixos-config=${toString ./root.nix}"
"nixpkgs-overlays=${toString ./nixpkgs/overlays.nix}"
];
But the nix.nixPath only exists in the home-manager unstable, not in 24.05, nor any other: