Skip to content

Comments

treewide: migrate overlay autoloading to general mkTarget modules#2174

Open
trueNAHO wants to merge 1 commit intonix-community:masterfrom
trueNAHO:treewide-migrate-overlay-autoloading-to-general-mk-target-modules
Open

treewide: migrate overlay autoloading to general mkTarget modules#2174
trueNAHO wants to merge 1 commit intonix-community:masterfrom
trueNAHO:treewide-migrate-overlay-autoloading-to-general-mk-target-modules

Conversation

@trueNAHO
Copy link
Member

@trueNAHO trueNAHO commented Jan 30, 2026

Migrate the /modules/<MODULE>/overlay.nix overlay autoloading to general
mkTarget modules by guarding them with the 'overlays' config argument.

Closes: https://github.com/nix-community/stylix/issues/2155

Important

Although nix build .#{doc,testbed:kitty:dark} works and the logic looks sound to me, this PR should be properly tested, especially with the /modules/{gtksourceview,nixos-icons}/ modules having no testbeds.

The schemeless testbeds are failing, which can be minimally reproduced in NixOS modules with the following config group:

{ colors }: { nixpkgs.overlays = []; }

Maybe the colors generated from stylix.image infinite recurse with nixpkgs.overlays declarations. I will try to look into this.

CC: @0xda157, @OsiPog, @astreaprtcl


Migrate the /modules/<MODULE>/overlay.nix overlay autoloading to general
mkTarget modules by guarding them with the 'overlays' config argument.

Closes: nix-community#2155
@stylix-automation stylix-automation bot added topic: documentation Documentation additions or improvements topic: nixos NixOS target topic: home-manager Home Manager target topic: overlay Overlay changes topic: modules /modules/ subsystem topic: stylix /stylix/ subsystem labels Jan 30, 2026
Copy link
Contributor

@0xda157 0xda157 left a comment

Choose a reason for hiding this comment

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

stylix.overlays.enable should still be respected. I suspect this will also fix the checks failing.

@trueNAHO
Copy link
Member Author

trueNAHO commented Jan 31, 2026

stylix.overlays.enable should still be respected. I suspect this will also fix the checks failing.

Actually, none of the stylix.targets.${target}.${argument}.enable options currently follow their global stylix.${argument} (or lib.stylix.colors) complement, which is necessary to resolve #929, in order to avoid partial and inconsistent global guarding. The following patch should be applied once the treewide mkTarget migration is complete, resulting in consistent global guarding:

diff --git a/stylix/mk-target.nix b/stylix/mk-target.nix
index 2edf705d..5014f1c7 100644
--- a/stylix/mk-target.nix
+++ b/stylix/mk-target.nix
@@ -286,10 +286,19 @@ let
                   }`";
                 in
                 {
-                  enable = lib.mkEnableOption "${config} for ${humanName}" // {
-                    default = true;
-                    example = false;
-                  };
+                  enable =
+                    let
+                      default =
+                        if argument == "colors" then
+                          config.lib.stylix.colors
+                        else
+                          config.stylix.${argument};
+                    in
+                    lib.mkEnableOption "${config} for ${humanName}"
+                    // {
+                      inherit default;
+                      example = !default;
+                    };

                   override = lib.mkOption {
                     default = null;

Either way, the missing stylix.overlays.enable guard should have no impact on the current infinite recursion error.

The infinite recursion error can be minimalistically removed from nix eval .#testbed:kitty:schemeless by either entirely removing both NixOS overlay modules with rm modules/{gtksourceview,nixos-icons}/nixos.nix, or removing the overlay imports in the NixOS modules as follows:

diff --git a/modules/gtksourceview/nixos.nix b/modules/gtksourceview/nixos.nix
index 48e93b2a..06df73ae 100644
--- a/modules/gtksourceview/nixos.nix
+++ b/modules/gtksourceview/nixos.nix
@@ -1,2 +1,2 @@
 { lib, mkTarget, ... }:
-mkTarget { config = import ./common.nix { inherit lib; }; }
+mkTarget { config = [ ]; }
diff --git a/modules/nixos-icons/nixos.nix b/modules/nixos-icons/nixos.nix
index eac5361b..229ff1dd 100644
--- a/modules/nixos-icons/nixos.nix
+++ b/modules/nixos-icons/nixos.nix
@@ -4,4 +4,4 @@
   pkgs,
   ...
 }:
-mkTarget { config = import ./common.nix { inherit lib pkgs; }; }
+mkTarget { config = [ ]; }

However, neither rm modules/{gtksourceview,nixos-icons}/hm.nix nor the following remove the infinite recursion error:

diff --git a/modules/gtksourceview/hm.nix b/modules/gtksourceview/hm.nix
index eeebef4b..19cf5fd8 100644
--- a/modules/gtksourceview/hm.nix
+++ b/modules/gtksourceview/hm.nix
@@ -24,6 +24,5 @@ mkTarget {
         );
       }
     )
-    (import ./common.nix { inherit lib; })
   ];
 }
diff --git a/modules/nixos-icons/hm.nix b/modules/nixos-icons/hm.nix
index eac5361b..229ff1dd 100644
--- a/modules/nixos-icons/hm.nix
+++ b/modules/nixos-icons/hm.nix
@@ -4,4 +4,4 @@
   pkgs,
   ...
 }:
-mkTarget { config = import ./common.nix { inherit lib pkgs; }; }
+mkTarget { config = [ ]; }

While unconditional declaring nixpkgs.overlays in the NixOS modules with

diff --git a/modules/gtksourceview/nixos.nix b/modules/gtksourceview/nixos.nix
index 48e93b2a..c0fef191 100644
--- a/modules/gtksourceview/nixos.nix
+++ b/modules/gtksourceview/nixos.nix
@@ -1,2 +1,2 @@
 { lib, mkTarget, ... }:
-mkTarget { config = import ./common.nix { inherit lib; }; }
+mkTarget { config.nixpkgs.overlays = [ ]; }
diff --git a/modules/nixos-icons/nixos.nix b/modules/nixos-icons/nixos.nix
index eac5361b..7fee00fe 100644
--- a/modules/nixos-icons/nixos.nix
+++ b/modules/nixos-icons/nixos.nix
@@ -4,4 +4,4 @@
   pkgs,
   ...
 }:
-mkTarget { config = import ./common.nix { inherit lib pkgs; }; }
+mkTarget { config.nixpkgs.overlays = [ ]; }

works, conditionally declaring them based on colors does not work:

diff --git a/modules/gtksourceview/nixos.nix b/modules/gtksourceview/nixos.nix
index 48e93b2a..a5434397 100644
--- a/modules/gtksourceview/nixos.nix
+++ b/modules/gtksourceview/nixos.nix
@@ -1,2 +1,2 @@
 { lib, mkTarget, ... }:
-mkTarget { config = import ./common.nix { inherit lib; }; }
+mkTarget { config = { colors }: { nixpkgs.overlays = [ ]; }; }
diff --git a/modules/nixos-icons/nixos.nix b/modules/nixos-icons/nixos.nix
index eac5361b..b653e395 100644
--- a/modules/nixos-icons/nixos.nix
+++ b/modules/nixos-icons/nixos.nix
@@ -4,4 +4,4 @@
   pkgs,
   ...
 }:
-mkTarget { config = import ./common.nix { inherit lib pkgs; }; }
+mkTarget { config = { colors }: { nixpkgs.overlays = [ ]; }; }

Note that conditionally declaring them based on overlays works:

diff --git a/modules/gtksourceview/nixos.nix b/modules/gtksourceview/nixos.nix
index 48e93b2a..deecf040 100644
--- a/modules/gtksourceview/nixos.nix
+++ b/modules/gtksourceview/nixos.nix
@@ -1,2 +1,2 @@
 { lib, mkTarget, ... }:
-mkTarget { config = import ./common.nix { inherit lib; }; }
+mkTarget { config = { overlays }: { nixpkgs.overlays = [ ]; }; }
diff --git a/modules/nixos-icons/nixos.nix b/modules/nixos-icons/nixos.nix
index eac5361b..90d28233 100644
--- a/modules/nixos-icons/nixos.nix
+++ b/modules/nixos-icons/nixos.nix
@@ -4,4 +4,4 @@
   pkgs,
   ...
 }:
-mkTarget { config = import ./common.nix { inherit lib pkgs; }; }
+mkTarget { config = { overlays }: { nixpkgs.overlays = [ ]; }; }

Maybe the colors generated from stylix.image infinite recurse with nixpkgs.overlays declarations.

More specifically, I suspect the following infinite recursion caused by pkgs, and therefore nixpkgs.overlays, being part of the entire NixOS closure, while Home Manager treats pkgs as an external input: colors -> config.lib.stylix.colors -> pkgs.runCommand (generate colors from image) -> pkgs -> nixpkgs.overlays -> colors (infinite recursion).

Indeed, the infinite recursion can be reproduced with either of the following patches on the master branch (aad90ca):

  • diff --git a/modules/gtksourceview/overlay.nix b/modules/gtksourceview/overlay.nix
    index 8c8d5b75..6372bb62 100644
    --- a/modules/gtksourceview/overlay.nix
    +++ b/modules/gtksourceview/overlay.nix
    @@ -25,6 +25,7 @@ in
             config.stylix.enable
             && config.stylix.targets ? gtksourceview
             && config.stylix.targets.gtksourceview.enable
    +        && config.lib.stylix.colors != null
           )
           {
             gnome2 = prev.gnome2 // {
  • diff --git a/modules/nixos-icons/overlay.nix b/modules/nixos-icons/overlay.nix
    index 537b7e58..f44294fb 100644
    --- a/modules/nixos-icons/overlay.nix
    +++ b/modules/nixos-icons/overlay.nix
    @@ -11,7 +11,7 @@
       overlay =
         _: super:
         lib.optionalAttrs
    -      (config.stylix.enable && config.stylix.targets.nixos-icons.enable)
    +      (config.stylix.enable && config.stylix.targets.nixos-icons.enable && config.lib.stylix.colors != null)
           {
             nixos-icons = super.nixos-icons.overrideAttrs (oldAttrs: {
               src = pkgs.applyPatches {

In other words, the infinite recursion error is not necessarily a technical limitation, but rather how we want to handle this from a design perspective.

I suppose adding the colors guard to the overlays is the correct and intended behavior to ensure consistent guarding. In that case, is removing overlay support for those modules on standalone NixOS the only viable option?

CC: @0xda157, @danth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: documentation Documentation additions or improvements topic: home-manager Home Manager target topic: modules /modules/ subsystem topic: nixos NixOS target topic: overlay Overlay changes topic: stylix /stylix/ subsystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants