From bb46e7792c79de99675a8894a4405c0572cb4268 Mon Sep 17 00:00:00 2001 From: bricked Date: Sun, 16 Feb 2025 22:38:48 +0100 Subject: [PATCH] treewide: add overlays option Adds the `stylix.overlays.enable` option which can be disabled to remove all overlays. This is to handle scenarios where overlays cannot be set, because the configuration doesn't handle its own nixpkgs instance. Fixes #865. --- modules/gnome-text-editor/common.nix | 30 +++++++++++++++------------- modules/gnome/nixos.nix | 2 +- modules/nixos-icons/nixos.nix | 7 ++++++- stylix/home-manager-integration.nix | 19 +++++++++++++----- stylix/target.nix | 11 ++++++++++ 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/modules/gnome-text-editor/common.nix b/modules/gnome-text-editor/common.nix index 3fc8d3f26..91402eb30 100644 --- a/modules/gnome-text-editor/common.nix +++ b/modules/gnome-text-editor/common.nix @@ -10,19 +10,21 @@ in options.stylix.targets.gnome-text-editor.enable = config.lib.stylix.mkEnableTarget "GNOME Text Editor" true; - config = + config.nixpkgs.overlays = 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 - ''; - }); - }) - ]; - }; + ( + config.stylix.enable + && config.stylix.targets.gnome-text-editor.enable + && config.stylix.overlays.enable + ) + [ + (_: 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/nixos.nix b/modules/gnome/nixos.nix index 63887a567..a57ae0c24 100644 --- a/modules/gnome/nixos.nix +++ b/modules/gnome/nixos.nix @@ -33,7 +33,7 @@ in # which will then download the pack regardless of its exclusion below. environment.gnome.excludePackages = [ pkgs.gnome-backgrounds ]; - nixpkgs.overlays = [ + nixpkgs.overlays = lib.mkIf config.stylix.overlays.enable [ (_: super: { gnome-shell = super.gnome-shell.overrideAttrs (oldAttrs: { # Themes are usually applied via an extension, but extensions are diff --git a/modules/nixos-icons/nixos.nix b/modules/nixos-icons/nixos.nix index e2fc72148..5ee205aab 100644 --- a/modules/nixos-icons/nixos.nix +++ b/modules/nixos-icons/nixos.nix @@ -12,7 +12,12 @@ with config.lib.stylix.colors; config.lib.stylix.mkEnableTarget "the NixOS logo" true; config.nixpkgs.overlays = - lib.mkIf (config.stylix.enable && config.stylix.targets.nixos-icons.enable) + lib.mkIf + ( + config.stylix.enable + && config.stylix.targets.nixos-icons.enable + && config.stylix.overlays.enable + ) [ (_: super: { nixos-icons = super.nixos-icons.overrideAttrs (oldAttrs: { diff --git a/stylix/home-manager-integration.nix b/stylix/home-manager-integration.nix index 3f2a10d7d..cafcafa0a 100644 --- a/stylix/home-manager-integration.nix +++ b/stylix/home-manager-integration.nix @@ -6,6 +6,10 @@ }: let + disableOverlaysModule = { + config.stylix.overlays.enable = false; + }; + copyModules = builtins.map ( @@ -222,10 +226,15 @@ in }; config = lib.optionalAttrs (options ? home-manager) ( - lib.mkIf config.stylix.homeManagerIntegration.autoImport { - home-manager.sharedModules = - [ config.stylix.homeManagerIntegration.module ] - ++ (lib.optionals config.stylix.homeManagerIntegration.followSystem copyModules); - } + lib.mkMerge [ + (lib.mkIf config.stylix.homeManagerIntegration.autoImport { + home-manager.sharedModules = + [ config.stylix.homeManagerIntegration.module ] + ++ (lib.optionals config.stylix.homeManagerIntegration.followSystem copyModules); + }) + (lib.mkIf config.home-manager.useGlobalPkgs { + home-manager.sharedModules = [ disableOverlaysModule ]; + }) + ] ); } diff --git a/stylix/target.nix b/stylix/target.nix index 12b8494b3..bb2f45012 100644 --- a/stylix/target.nix +++ b/stylix/target.nix @@ -29,6 +29,17 @@ default = true; example = false; }; + + overlays.enable = lib.mkOption { + description = '' + Whether to enable overlays. + + When this is `false`, no overlays are set. This may be required if the configuration doesn't manage its own nixpkgs instance. + ''; + type = lib.types.bool; + default = true; + example = false; + }; }; config.lib.stylix =