Skip to content

fix: ensure overlays are passed to all possible nixpkgs instances - #146

Merged
r-vdp merged 2 commits into
numtide:mainfrom
srounce:fix-overlays
Apr 15, 2026
Merged

fix: ensure overlays are passed to all possible nixpkgs instances#146
r-vdp merged 2 commits into
numtide:mainfrom
srounce:fix-overlays

Conversation

@srounce

@srounce srounce commented Feb 25, 2026

Copy link
Copy Markdown
Member

Tried to apply an overlay to get around the current boost 1.89 situation on nixpkgs only to find it wasn't actually being applied everywhere and neither was nixpkgs.config. Added an extra module to ensure that they are passed to config.nixpkgs too.

@devurandom devurandom left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would fix #115, where it is reported that the config is applied to Home Manager, but not to NixOS.

I was interested to compared the approach of this PR with how it works for Home Manager:

blueprint/lib/default.nix

Lines 231 to 237 in 06ee719

mkHomeUsersModule =
hostname: homeManagerModule:
let
module =
{ perSystem, config, ... }:
{
imports = [ homeManagerModule ];

blueprint/lib/default.nix

Lines 343 to 361 in 06ee719

hosts = importDir (src + "/hosts") (
entries:
let
loadDefaultFn = { class, value }@inputs: inputs;
loadDefault = hostName: path: loadDefaultFn (import path { inherit flake inputs hostName; });
loadNixOS = hostName: path: {
class = "nixos";
value = inputs.nixpkgs.lib.nixosSystem {
modules = [
perSystemModule
path
] ++ mkHomeUsersModule hostName home-manager.nixosModules.default;
specialArgs = specialArgs // {
inherit hostName;
};
};
};

home-manager.nixosModules.default is:

https://github.com/nix-community/home-manager/blob/7ba4ee4228ed36123c7cb75d50524b43514ef992/flake.nix#L13-L16

https://github.com/nix-community/home-manager/blob/7ba4ee4228ed36123c7cb75d50524b43514ef992/nixos/default.nix#L47

https://github.com/nix-community/home-manager/blob/7ba4ee4228ed36123c7cb75d50524b43514ef992/nixos/common.nix#L40-L47

https://github.com/nix-community/home-manager/blob/7ba4ee4228ed36123c7cb75d50524b43514ef992/modules/modules.nix#L82

https://github.com/nix-community/home-manager/blob/7ba4ee4228ed36123c7cb75d50524b43514ef992/modules/misc/nixpkgs-disabled.nix

I was unable to figure out how nixpkgs.config ends up being used by home-manager.nixosModules.default (under blueprint's setting of useGlobalPkgs = true, which sets useNixpkgsModule = false), neither in the code traced here nor in the surrounding code.

Could you please explain why this happens in the first place for NixOS / why it does not happen within home manager?

srounce and others added 2 commits April 15, 2026 12:07
Setting nixpkgs.config/overlays in the host module makes the
NixOS/nix-darwin module system import nixpkgs again per host with the
same settings blueprint already used for systemArgs.${system}.pkgs.
Hand that instance over via nixpkgs.pkgs instead so packages, devshells
and hosts share one evaluation.

Only injected when blueprint actually has nixpkgs.config/overlays set,
so hosts that manage their own nixpkgs.* are unaffected. mkDefault lets
a host override with its own nixpkgs.pkgs.

A host that previously set nixpkgs.overlays alongside blueprint's now
needs to extend the shared instance explicitly
(nixpkgs.pkgs = lib.mkForce (perSystem.nixpkgs.extend extra)) since the
NixOS module ignores nixpkgs.overlays when nixpkgs.pkgs is set.
@r-vdp

r-vdp commented Apr 15, 2026

Copy link
Copy Markdown
Member

Could you please explain why this happens in the first place for NixOS / why it does not happen within home manager?

You traced the HM-inside-NixOS path (home-manager.nixosModules.defaultuseGlobalPkgs = truenixpkgs-disabled.nix).
On that path the config is indeed never applied — HM just inherits the NixOS host's pkgs, and that pkgs is the unconfigured one (see below).

The path where it does work is the standalone HM entry point, which is what the #115 reporter inspected (legacyPackages.x86_64-linux.homeConfigurations."me@my-nixos"):

blueprint/lib/default.nix

Lines 330 to 341 in 06ee719

eachSystem (
{ pkgs, system, ... }:
{
homeConfigurations = lib.mapAttrs (
_name: homeData:
mkHomeConfiguration {
inherit (homeData) modulePath username;
inherit pkgs system;
}
) homesFlat;
}
);

blueprint/lib/default.nix

Lines 293 to 294 in 06ee719

home-manager.lib.homeManagerConfiguration {
inherit pkgs;

Here pkgs = systemArgs.${system}.pkgs (the instance blueprint built with the configured nixpkgs.config/overlays) is handed straight to homeManagerConfiguration.
HM's modules/misc/nixpkgs.nix then mirrors pkgs.config into config.nixpkgs.config, which is why the value shows up there.

loadNixOS on the other hand, calls nixosSystem with no pkgs at all:

blueprint/lib/default.nix

Lines 350 to 360 in 06ee719

loadNixOS = hostName: path: {
class = "nixos";
value = inputs.nixpkgs.lib.nixosSystem {
modules = [
perSystemModule
path
] ++ mkHomeUsersModule hostName home-manager.nixosModules.default;
specialArgs = specialArgs // {
inherit hostName;
};
};

So the NixOS module system instantiates its own from config.nixpkgs.hostPlatform, ignoring blueprint's settings — and HM-inside-NixOS inherits that via useGlobalPkgs.

I've pushed a follow-up commit that fixes it the same way standalone HM already works: hand over systemArgs.${system}.pkgs via nixpkgs.pkgs (rather than setting nixpkgs.config/overlays, which would make NixOS import nixpkgs a second time per host with the same settings).

Also rebased onto current main so CI passes (#151 fixed an unrelated template breakage).

@r-vdp r-vdp linked an issue Apr 15, 2026 that may be closed by this pull request
@r-vdp
r-vdp merged commit 0bd9312 into numtide:main Apr 15, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nixpkgs config is not passed from global blueprint configuration to hosts

3 participants