Repository: danth/stylix
Pull request #1048: stylix: add overlay module
Author: login: 0xda157
Created: 2025-03-22T19:25:55Z | Merged: 2025-03-31T17:36:36Z

~~Not really sure how to import overlays in standalone home manager but not when home manager is a nixos/darwin/droid module.~~

supersedes #866
cc: @brckd @trueNAHO @danth 


Diff:
diff --git a/docs/src/modules.md b/docs/src/modules.md
index 8da82730a..dd1e8defa 100644
--- a/docs/src/modules.md
+++ b/docs/src/modules.md
@@ -73,6 +73,34 @@ one of the following applies:
 - There is no reliable way to detect whether the target is installed, *and*
   enabling it unconditionally would cause problems.
 
+### Overlays
+
+If your module is provided as an overlay it uses a special format, where config
+is transparently passed to the platform (e.g. nixos) and overlay is a function
+taking two arguments and returning an attrset:
+
+```nix
+{
+  lib,
+  config,
+  ...
+}:
+{
+  options.stylix.targets.«name».enable =
+    config.lib.stylix.mkEnableOverlay "«human readable name»";
+
+  overlay =
+    final: prev:
+    lib.optionalAttrs
+      (config.stylix.enable && config.stylix.targets.«name».enable)
+      {
+        «name» = prev.«name».overrideAttrs (oldAttrs: {
+
+        });
+      };
+}
+```
+
 ## How to apply colors
 
 Refer to the [style guide](./styling.md) to see how colors are named,
diff --git a/modules/gnome-text-editor/common.nix b/modules/gnome-text-editor/common.nix
deleted file mode 100644
index 8d72ecc73..000000000
--- a/modules/gnome-text-editor/common.nix
+++ /dev/null
@@ -1,28 +0,0 @@
-{ config, lib, ... }:
-
-let
-  style = config.lib.stylix.colors {
-    template = ../gedit/template.xml.mustache;
-    extension = "xml";
-  };
-in
-{
-  options.stylix.targets.gnome-text-editor.enable =
-    config.lib.stylix.mkEnableTarget "GNOME Text Editor" true;
-
-  config =
-    lib.mkIf
-      (config.stylix.enable && config.stylix.targets.gnome-text-editor.enable)
-      {
-        nixpkgs.overlays = [
-          (_: prev: {
-            gnome-text-editor = prev.gnome-text-editor.overrideAttrs (oldAttrs: {
-              postFixup = ''
-                ${oldAttrs.postFixup or ""}
-                cp ${style} $out/share/gnome-text-editor/styles/stylix.xml
-              '';
-            });
-          })
-        ];
-      };
-}
diff --git a/modules/gnome-text-editor/hm.nix b/modules/gnome-text-editor/hm.nix
index b9fb01d99..ab878e61e 100644
--- a/modules/gnome-text-editor/hm.nix
+++ b/modules/gnome-text-editor/hm.nix
@@ -1,8 +1,5 @@
 { config, lib, ... }:
-
 {
-  imports = [ ./common.nix ];
-
   config =
     lib.mkIf
       (config.stylix.enable && config.stylix.targets.gnome-text-editor.enable)
diff --git a/modules/gnome-text-editor/nixos.nix b/modules/gnome-text-editor/nixos.nix
deleted file mode 100644
index 6e953ddc5..000000000
--- a/modules/gnome-text-editor/nixos.nix
+++ /dev/null
@@ -1,3 +0,0 @@
-{
-  imports = [ ./common.nix ];
-}
diff --git a/modules/gnome-text-editor/overlay.nix b/modules/gnome-text-editor/overlay.nix
new file mode 100644
index 000000000..ec723ac5c
--- /dev/null
+++ b/modules/gnome-text-editor/overlay.nix
@@ -0,0 +1,24 @@
+{ config, lib, ... }:
+let
+  style = config.lib.stylix.colors {
+    template = ../gedit/template.xml.mustache;
+    extension = "xml";
+  };
+in
+{
+  options.stylix.targets.gnome-text-editor.enable =
+    config.lib.stylix.mkEnableOverlay "GNOME Text Editor";
+
+  overlay =
+    _: prev:
+    lib.optionalAttrs
+      (config.stylix.enable && config.stylix.targets.gnome-text-editor.enable)
+      {
+        gnome-text-editor = prev.gnome-text-editor.overrideAttrs (oldAttrs: {
+          postFixup = ''
+            ${oldAttrs.postFixup or ""}
+            cp ${style} $out/share/gnome-text-editor/styles/stylix.xml
+          '';
+        });
+      };
+}
diff --git a/modules/nixos-icons/nixos.nix b/modules/nixos-icons/nixos.nix
deleted file mode 100644
index e45d774c7..000000000
--- a/modules/nixos-icons/nixos.nix
+++ /dev/null
@@ -1,31 +0,0 @@
-{
-  pkgs,
-  config,
-  lib,
-  ...
-}:
-{
-  options.stylix.targets.nixos-icons.enable =
-    config.lib.stylix.mkEnableTarget "the NixOS logo" true;
-
-  config.nixpkgs.overlays =
-    lib.mkIf (config.stylix.enable && config.stylix.targets.nixos-icons.enable)
-      [
-        (_: super: {
-          nixos-icons = super.nixos-icons.overrideAttrs (oldAttrs: {
-            src = pkgs.applyPatches {
-              inherit (oldAttrs) src;
-              prePatch = with config.lib.stylix.colors; ''
-                substituteInPlace logo/nix-snowflake-white.svg --replace-fail '#ffffff' '#${base05}'
-
-                # Insert attribution comment after the XML prolog
-                sed \
-                  --in-place \
-                  '2i<!-- The original NixOS logo from ${oldAttrs.src.url} is licensed under https://creativecommons.org/licenses/by/4.0 and has been modified to match the ${scheme} color scheme. -->' \
-                  logo/nix-snowflake-white.svg
-              '';
-            };
-          });
-        })
-      ];
-}
diff --git a/modules/nixos-icons/overlay.nix b/modules/nixos-icons/overlay.nix
new file mode 100644
index 000000000..087641ff3
--- /dev/null
+++ b/modules/nixos-icons/overlay.nix
@@ -0,0 +1,31 @@
+{
+  pkgs,
+  config,
+  lib,
+  ...
+}:
+{
+  options.stylix.targets.nixos-icons.enable =
+    config.lib.stylix.mkEnableOverlay "the NixOS logo";
+
+  overlay =
+    _: super:
+    lib.optionalAttrs
+      (config.stylix.enable && config.stylix.targets.nixos-icons.enable)
+      {
+        nixos-icons = super.nixos-icons.overrideAttrs (oldAttrs: {
+          src = pkgs.applyPatches {
+            inherit (oldAttrs) src;
+            prePatch = with config.lib.stylix.colors; ''
+              substituteInPlace logo/nix-snowflake-white.svg --replace-fail '#ffffff' '#${base05}'
+
+              # Insert attribution comment after the XML prolog
+              sed \
+                --in-place \
+                '2i<!-- The original NixOS logo from ${oldAttrs.src.url} is licensed under https://creativecommons.org/licenses/by/4.0 and has been modified to match the ${scheme} color scheme. -->' \
+                logo/nix-snowflake-white.svg
+            '';
+          };
+        });
+      };
+}
diff --git a/stylix/darwin/default.nix b/stylix/darwin/default.nix
index 58063455c..7de7db7cf 100644
--- a/stylix/darwin/default.nix
+++ b/stylix/darwin/default.nix
@@ -1,5 +1,9 @@
 inputs:
-{ lib, config, ... }:
+{
+  lib,
+  config,
+  ...
+}:
 
 # Imported modules which define new options must use an absolute path based
 # on ${inputs.self}, otherwise those options will not appear in the generated
@@ -19,6 +23,7 @@ in
     "${inputs.self}/stylix/pixel.nix"
     "${inputs.self}/stylix/target.nix"
     "${inputs.self}/stylix/release.nix"
+    (import "${inputs.self}/stylix/overlays.nix" inputs)
   ] ++ autoload;
   config.warnings =
     lib.mkIf
diff --git a/stylix/droid/default.nix b/stylix/droid/default.nix
index cc6e07570..b1afb2bcc 100644
--- a/stylix/droid/default.nix
+++ b/stylix/droid/default.nix
@@ -12,6 +12,7 @@ in
     "${inputs.self}/stylix/palette.nix"
     "${inputs.self}/stylix/pixel.nix"
     "${inputs.self}/stylix/target.nix"
+    (import "${inputs.self}/stylix/overlays.nix" inputs)
   ] ++ autoload;
 
   # See https://github.com/nix-community/nix-on-droid/issues/436
diff --git a/stylix/hm/default.nix b/stylix/hm/default.nix
index 0df2301b8..69f5686f2 100644
--- a/stylix/hm/default.nix
+++ b/stylix/hm/default.nix
@@ -1,5 +1,9 @@
 inputs:
-{ lib, config, ... }:
+{
+  lib,
+  config,
+  ...
+}:
 
 # Imported modules which define new options must use an absolute path based
 # on ${inputs.self}, otherwise those options will not appear in the generated
@@ -22,6 +26,7 @@ in
     "${inputs.self}/stylix/pixel.nix"
     "${inputs.self}/stylix/target.nix"
     "${inputs.self}/stylix/release.nix"
+    (import "${inputs.self}/stylix/overlays.nix" inputs)
   ] ++ autoload;
   config.warnings =
     lib.mkIf
diff --git a/stylix/home-manager-integration.nix b/stylix/home-manager-integration.nix
index 6f2019a57..c4efa4f30 100644
--- a/stylix/home-manager-integration.nix
+++ b/stylix/home-manager-integration.nix
@@ -208,11 +208,18 @@ in
     };
   };
 
-  config = lib.optionalAttrs (options ? home-manager) (
-    lib.mkIf config.stylix.homeManagerIntegration.autoImport {
+  config = lib.optionalAttrs (options ? home-manager) lib.mkMerge [
+    (lib.mkIf config.stylix.homeManagerIntegration.autoImport {
       home-manager.sharedModules =
-        [ config.stylix.homeManagerIntegration.module ]
+        [
+          config.stylix.homeManagerIntegration.module
+        ]
         ++ (lib.optionals config.stylix.homeManagerIntegration.followSystem copyModules);
-    }
-  );
+    })
+    (lib.mkIf config.home-manager.useGlobalPkgs {
+      home-manager.sharedModules = lib.singleton {
+        config.stylix.overlays.enable = false;
+      };
+    })
+  ];
 }
diff --git a/stylix/nixos/default.nix b/stylix/nixos/default.nix
index 32180f3fd..7f5f3e79c 100644
--- a/stylix/nixos/default.nix
+++ b/stylix/nixos/default.nix
@@ -1,5 +1,9 @@
 inputs:
-{ lib, config, ... }:
+{
+  lib,
+  config,
+  ...
+}:
 
 # Imported modules which define new options must use an absolute path based
 # on ${inputs.self}, otherwise those options will not appear in the generated
@@ -21,6 +25,7 @@ in
     "${inputs.self}/stylix/pixel.nix"
     "${inputs.self}/stylix/target.nix"
     "${inputs.self}/stylix/release.nix"
+    (import "${inputs.self}/stylix/overlays.nix" inputs)
   ] ++ autoload;
   config.warnings =
     lib.mkIf
diff --git a/stylix/overlays.nix b/stylix/overlays.nix
new file mode 100644
index 000000000..af7b8da5c
--- /dev/null
+++ b/stylix/overlays.nix
@@ -0,0 +1,26 @@
+inputs:
+{
+  lib,
+  pkgs,
+  config,
+  ...
+}:
+{
+  options.stylix.overlays.enable = config.lib.stylix.mkEnableTarget "packages via overlays" true;
+
+  imports = map (
+    f:
+    let
+      file = import f;
+      attrs =
+        if builtins.typeOf file == "lambda" then
+          file { inherit lib pkgs config; }
+        else
+          file;
+    in
+    {
+      options = attrs.options or { };
+      config.nixpkgs.overlays = [ attrs.overlay ];
+    }
+  ) (import ./autoload.nix { inherit lib inputs; } "overlay");
+}
diff --git a/stylix/target.nix b/stylix/target.nix
index 12b8494b3..fa12bb02a 100644
--- a/stylix/target.nix
+++ b/stylix/target.nix
@@ -35,7 +35,7 @@
     let
       cfg = config.stylix;
     in
-    {
+    rec {
       mkEnableTarget =
         humanName: autoEnable:
         lib.mkEnableOption "theming for ${humanName}"
@@ -57,5 +57,7 @@
         // lib.optionalAttrs autoEnable {
           defaultText = lib.literalMD "`stylix.image != null`";
         };
+      mkEnableOverlay =
+        humanName: mkEnableTarget humanName config.stylix.overlays.enable;
     };
 }


Reviews:
user: login: trueNAHO
body: Thanks for taking the initiative in this soon urgent matter.

The overall approach looks very nice :)

Cc: @danth

state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-03-24T21:53:21Z
user: login: 0xda157
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T21:56:07Z
user: login: 0xda157
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-24T22:29:08Z
user: login: trueNAHO
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-25T09:28:01Z
user: login: trueNAHO
body: LGTM, except for one nitpick.
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-03-27T12:48:02Z
user: login: 0xda157
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-27T19:04:58Z
user: login: trueNAHO
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-31T12:09:31Z

Review comments:
diff_hunk: @@ -0,0 +1,20 @@
+{
+  lib,
+  inputs,
+  config,
+  ...
+}@args:
+(lib.singleton {
+  options.stylix.overlays.enable = config.lib.stylix.mkEnableTarget "Enable theming of some packages via overlays" true;
+})
path: stylix/overlays.nix
user: login: trueNAHO
body: I believe these parentheses are not mandatory:

```suggestion
lib.singleton {
  options.stylix.overlays.enable = config.lib.stylix.mkEnableTarget "Enable theming of some packages via overlays" true;
}
```
created_at: 2025-03-24T19:48:08Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,20 @@
+{
+  lib,
+  inputs,
+  config,
+  ...
+}@args:
+(lib.singleton {
+  options.stylix.overlays.enable = config.lib.stylix.mkEnableTarget "Enable theming of some packages via overlays" true;
+})
+++ builtins.map (
path: stylix/overlays.nix
user: login: trueNAHO
body: ```suggestion
++ map (
```
created_at: 2025-03-24T19:48:17Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,20 @@
+{
+  lib,
+  inputs,
+  config,
+  ...
+}@args:
+(lib.singleton {
+  options.stylix.overlays.enable = config.lib.stylix.mkEnableTarget "Enable theming of some packages via overlays" true;
+})
+++ builtins.map (
+  f:
+  let
+    file = import f;
+    attrs = if (builtins.typeOf file == "lambda") then file args else file;
path: stylix/overlays.nix
user: login: trueNAHO
body: Not sure why the statix pre-commit hook is not flagging this:

```suggestion
    attrs = if builtins.typeOf file == "lambda" then file args else file;
```
created_at: 2025-03-24T19:53:20Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,20 @@
+{
+  lib,
+  inputs,
+  config,
+  ...
+}@args:
+(lib.singleton {
+  options.stylix.overlays.enable = config.lib.stylix.mkEnableTarget "Enable theming of some packages via overlays" true;
+})
+++ builtins.map (
+  f:
+  let
+    file = import f;
+    attrs = if (builtins.typeOf file == "lambda") then file args else file;
+  in
+  {
+    options = lib.optionalAttrs (attrs ? options) attrs.options;
path: stylix/overlays.nix
user: login: trueNAHO
body: ```suggestion
    options = attrs.options or [];
```
created_at: 2025-03-24T19:55:35Z
author_association: MEMBER
diff_hunk: @@ -0,0 +1,20 @@
+{
+  lib,
+  inputs,
+  config,
+  ...
+}@args:
+(lib.singleton {
+  options.stylix.overlays.enable = config.lib.stylix.mkEnableTarget "Enable theming of some packages via overlays" true;
path: stylix/overlays.nix
user: login: trueNAHO
body: `config.lib.stylix.mkEnableTarget` generates the following:

```nix
description: "Whether to enable theming for ${description}."
```

With that in mind, the description should be changed to something like:

```suggestion
  options.stylix.overlays.enable = config.lib.stylix.mkEnableTarget "packages via overlays" true;
```

created_at: 2025-03-24T21:43:30Z
author_association: MEMBER
diff_hunk: @@ -9,17 +14,27 @@ let
   autoload = import ../autoload.nix { inherit lib inputs; } "darwin";
 in
 {
-  imports = [
-    "${inputs.self}/stylix/darwin/fonts.nix"
-    "${inputs.self}/stylix/darwin/palette.nix"
-    "${inputs.self}/stylix/fonts.nix"
-    "${inputs.self}/stylix/home-manager-integration.nix"
-    "${inputs.self}/stylix/opacity.nix"
-    "${inputs.self}/stylix/palette.nix"
-    "${inputs.self}/stylix/pixel.nix"
-    "${inputs.self}/stylix/target.nix"
-    "${inputs.self}/stylix/release.nix"
-  ] ++ autoload;
+  imports =
+    [
+      "${inputs.self}/stylix/darwin/fonts.nix"
+      "${inputs.self}/stylix/darwin/palette.nix"
+      "${inputs.self}/stylix/fonts.nix"
+      "${inputs.self}/stylix/home-manager-integration.nix"
+      "${inputs.self}/stylix/opacity.nix"
+      "${inputs.self}/stylix/palette.nix"
+      "${inputs.self}/stylix/pixel.nix"
+      "${inputs.self}/stylix/target.nix"
+      "${inputs.self}/stylix/release.nix"
+    ]
+    ++ autoload
+    ++ (import ../overlays.nix {
path: stylix/darwin/default.nix
user: login: trueNAHO
body: To align with commit e87bf16df961 ("stylix: use absolute paths for module imports"), apply the following change also to the other relevant files:


```suggestion
    ++ (import "${inputs.self}/stylix/overlays.nix" {
```
created_at: 2025-03-24T21:45:57Z
author_association: MEMBER
diff_hunk: @@ -9,17 +14,27 @@ let
   autoload = import ../autoload.nix { inherit lib inputs; } "darwin";
 in
 {
-  imports = [
-    "${inputs.self}/stylix/darwin/fonts.nix"
-    "${inputs.self}/stylix/darwin/palette.nix"
-    "${inputs.self}/stylix/fonts.nix"
-    "${inputs.self}/stylix/home-manager-integration.nix"
-    "${inputs.self}/stylix/opacity.nix"
-    "${inputs.self}/stylix/palette.nix"
-    "${inputs.self}/stylix/pixel.nix"
-    "${inputs.self}/stylix/target.nix"
-    "${inputs.self}/stylix/release.nix"
-  ] ++ autoload;
+  imports =
+    [
+      "${inputs.self}/stylix/darwin/fonts.nix"
+      "${inputs.self}/stylix/darwin/palette.nix"
+      "${inputs.self}/stylix/fonts.nix"
+      "${inputs.self}/stylix/home-manager-integration.nix"
+      "${inputs.self}/stylix/opacity.nix"
+      "${inputs.self}/stylix/palette.nix"
+      "${inputs.self}/stylix/pixel.nix"
+      "${inputs.self}/stylix/target.nix"
+      "${inputs.self}/stylix/release.nix"
+    ]
+    ++ autoload
+    ++ (import ../overlays.nix {
+      inherit
+        lib
+        pkgs
+        config
+        inputs
+        ;
path: stylix/darwin/default.nix
user: login: trueNAHO
body: Are these attributes not automatically provided when simply adding `/stylix/overlays.nix` to `imports`, similar to how the existing files are doing it:

```nix
imports = ["${inputs.self}/stylix/overlays.nix"];
```

This should also be applied to the other relevant files.
created_at: 2025-03-24T21:48:12Z
author_association: MEMBER
diff_hunk: @@ -9,17 +14,27 @@ let
   autoload = import ../autoload.nix { inherit lib inputs; } "darwin";
 in
 {
-  imports = [
-    "${inputs.self}/stylix/darwin/fonts.nix"
-    "${inputs.self}/stylix/darwin/palette.nix"
-    "${inputs.self}/stylix/fonts.nix"
-    "${inputs.self}/stylix/home-manager-integration.nix"
-    "${inputs.self}/stylix/opacity.nix"
-    "${inputs.self}/stylix/palette.nix"
-    "${inputs.self}/stylix/pixel.nix"
-    "${inputs.self}/stylix/target.nix"
-    "${inputs.self}/stylix/release.nix"
-  ] ++ autoload;
+  imports =
+    [
+      "${inputs.self}/stylix/darwin/fonts.nix"
+      "${inputs.self}/stylix/darwin/palette.nix"
+      "${inputs.self}/stylix/fonts.nix"
+      "${inputs.self}/stylix/home-manager-integration.nix"
+      "${inputs.self}/stylix/opacity.nix"
+      "${inputs.self}/stylix/palette.nix"
+      "${inputs.self}/stylix/pixel.nix"
+      "${inputs.self}/stylix/target.nix"
+      "${inputs.self}/stylix/release.nix"
+    ]
+    ++ autoload
+    ++ (import ../overlays.nix {
+      inherit
+        lib
+        pkgs
+        config
+        inputs
+        ;
path: stylix/darwin/default.nix
user: login: 0xda157
body: putting it in imports will not include `inputs` as an arg
created_at: 2025-03-24T21:56:07Z
author_association: CONTRIBUTOR
diff_hunk: @@ -9,17 +14,27 @@ let
   autoload = import ../autoload.nix { inherit lib inputs; } "darwin";
 in
 {
-  imports = [
-    "${inputs.self}/stylix/darwin/fonts.nix"
-    "${inputs.self}/stylix/darwin/palette.nix"
-    "${inputs.self}/stylix/fonts.nix"
-    "${inputs.self}/stylix/home-manager-integration.nix"
-    "${inputs.self}/stylix/opacity.nix"
-    "${inputs.self}/stylix/palette.nix"
-    "${inputs.self}/stylix/pixel.nix"
-    "${inputs.self}/stylix/target.nix"
-    "${inputs.self}/stylix/release.nix"
-  ] ++ autoload;
+  imports =
+    [
+      "${inputs.self}/stylix/darwin/fonts.nix"
+      "${inputs.self}/stylix/darwin/palette.nix"
+      "${inputs.self}/stylix/fonts.nix"
+      "${inputs.self}/stylix/home-manager-integration.nix"
+      "${inputs.self}/stylix/opacity.nix"
+      "${inputs.self}/stylix/palette.nix"
+      "${inputs.self}/stylix/pixel.nix"
+      "${inputs.self}/stylix/target.nix"
+      "${inputs.self}/stylix/release.nix"
+    ]
+    ++ autoload
+    ++ (import ../overlays.nix {
+      inherit
+        lib
+        pkgs
+        config
+        inputs
+        ;
path: stylix/darwin/default.nix
user: login: 0xda157
body: I could change the args of  `overlays.nix` to this `inputs: { config, lib, ...}:` and have it be imported like this: `imports = [ (import "${inputs.self}/stylix/overlays.nix" inputs) ];`
created_at: 2025-03-24T22:29:08Z
author_association: CONTRIBUTOR
diff_hunk: @@ -9,17 +14,27 @@ let
   autoload = import ../autoload.nix { inherit lib inputs; } "darwin";
 in
 {
-  imports = [
-    "${inputs.self}/stylix/darwin/fonts.nix"
-    "${inputs.self}/stylix/darwin/palette.nix"
-    "${inputs.self}/stylix/fonts.nix"
-    "${inputs.self}/stylix/home-manager-integration.nix"
-    "${inputs.self}/stylix/opacity.nix"
-    "${inputs.self}/stylix/palette.nix"
-    "${inputs.self}/stylix/pixel.nix"
-    "${inputs.self}/stylix/target.nix"
-    "${inputs.self}/stylix/release.nix"
-  ] ++ autoload;
+  imports =
+    [
+      "${inputs.self}/stylix/darwin/fonts.nix"
+      "${inputs.self}/stylix/darwin/palette.nix"
+      "${inputs.self}/stylix/fonts.nix"
+      "${inputs.self}/stylix/home-manager-integration.nix"
+      "${inputs.self}/stylix/opacity.nix"
+      "${inputs.self}/stylix/palette.nix"
+      "${inputs.self}/stylix/pixel.nix"
+      "${inputs.self}/stylix/target.nix"
+      "${inputs.self}/stylix/release.nix"
+    ]
+    ++ autoload
+    ++ (import ../overlays.nix {
+      inherit
+        lib
+        pkgs
+        config
+        inputs
+        ;
path: stylix/darwin/default.nix
user: login: trueNAHO
body: > I could change the args of `overlays.nix` to this `inputs: { config, lib, ...}:` and have it be imported like this: `imports = [ (import "${inputs.self}/stylix/overlays.nix" inputs) ];`

Yes, that would be nice. This pattern seems to be already used in some places, like `/stylix/nixos/default.nix`:

https://github.com/danth/stylix/blob/b4feb69fd2c1b6ef02a6a81761a62af62ac7bf1b/stylix/nixos/default.nix#L1-L2

created_at: 2025-03-25T09:28:01Z
author_association: MEMBER
diff_hunk: @@ -72,6 +72,30 @@ one of the following applies:
 - There is no reliable way to detect whether the target is installed, *and*
   enabling it unconditionally would cause problems.
 
+### Overlays
+
+If your module is provided as an overlay it uses a special format, where config
+is transparently passed to the platform (e.g. nixos) and overlay is a function
+taking two arguments and returning an attrset:
+
+```nix
+{ lib, pkgs, config, ... }:
+{
+  options.stylix.targets.«name».enable =
+    config.lib.stylix.mkEnableOverlay "«human readable name»";
+
+  overlay =
+    final: prev:
+    lib.optionalAttrs
+      (config.stylix.enable && config.stylix.targets.«name».enable)
+      {
+        «name» = prev.«name».overrideAttrs (oldAttrs: {
+
+        });
+      };
+}
path: docs/src/modules.md
user: login: trueNAHO
body: To align with commit 421e09fc7351 ("doc: format Nix code in Maintainers section according to our formatter (#1024)"):

```suggestion
{
  lib,
  config,
  ...
}:
{
  options.stylix.targets."name".enable =
    config.lib.stylix.mkEnableOverlay "«human readable name»";

  overlay =
    final: prev:
    lib.optionalAttrs (
      config.stylix.enable && config.stylix.targets."name".enable
    ) { "name" = prev."name".overrideAttrs (oldAttrs: { }); };
}
```

created_at: 2025-03-27T12:42:19Z
author_association: MEMBER
diff_hunk: @@ -72,6 +72,30 @@ one of the following applies:
 - There is no reliable way to detect whether the target is installed, *and*
   enabling it unconditionally would cause problems.
 
+### Overlays
+
+If your module is provided as an overlay it uses a special format, where config
+is transparently passed to the platform (e.g. nixos) and overlay is a function
+taking two arguments and returning an attrset:
+
+```nix
+{ lib, pkgs, config, ... }:
+{
+  options.stylix.targets.«name».enable =
+    config.lib.stylix.mkEnableOverlay "«human readable name»";
+
+  overlay =
+    final: prev:
+    lib.optionalAttrs
+      (config.stylix.enable && config.stylix.targets.«name».enable)
+      {
+        «name» = prev.«name».overrideAttrs (oldAttrs: {
+
+        });
+      };
+}
path: docs/src/modules.md
user: login: 0xda157
body: I prefer keeping the body formatted as it would be in an actually module
created_at: 2025-03-27T19:04:58Z
author_association: CONTRIBUTOR

PR comments:
user: login: brckd
created_at: 2025-03-22T19:46:21Z
body: Nice, so this implements the separate overlays modules as discussed in the linked PR!

> Not really sure how to import overlays in standalone home manager but not when home manager is a nixos/darwin/droid module.

I would add an option to manually enable or disable overlays. This option could automatically be disabled by the home integration on NixOS and Darwin.
author_association: CONTRIBUTOR
user: login: 0xda157
created_at: 2025-03-22T20:09:55Z
body: currently stuck on `home-manager-integration.nix` not getting `inputs` as an arg which is required for `autoload.nix`
author_association: CONTRIBUTOR
user: login: 0xda157
created_at: 2025-03-22T20:33:19Z
body: > I would add an option to manually enable or disable overlays. This option could automatically be disabled by the home integration on NixOS and Darwin.

Done

> currently stuck on home-manager-integration.nix not getting inputs as an arg which is required for autoload.nix

Reworked things so this shouldn't be an issue anymore

Also had to do a janky inherit thing in `stylix/<platform>/default.nix` cause otherwise pkgs won't be included in the args.
author_association: CONTRIBUTOR
user: login: 0xda157
created_at: 2025-03-22T20:44:54Z
body: I can also interactive rebase this into `stylix: add overlay module` and `treewide: migrate to overlay.nix` if people would prefer two commits.
author_association: CONTRIBUTOR
user: login: trueNAHO
created_at: 2025-03-31T14:24:02Z
body: Does anyone know what the CI is waiting on:

![image](https://github.com/user-attachments/assets/28f08e42-61b2-4443-b9be-c20d99d52dfa)

The same "problem" affects https://github.com/danth/stylix/pull/1058.

Cc: @danth
author_association: MEMBER
user: login: danth
created_at: 2025-03-31T15:01:00Z
body: > Does anyone know what the CI is waiting on:

#1069 means that we now always run the same 4 checks regardless of what the packages are named, which made it possible to mark the checks as required in branch protection.

This PR was last pushed before that change, so the new checks haven't been run. As they are required, GitHub is just infinitely waiting for them to start. Feel free to just bypass the branch protection for these older PRs (hopefully you have that permission if I set things up correctly), or update the branch to trigger the new checks.
author_association: MEMBER