diff --git a/modules/feh/hm.nix b/modules/feh/hm.nix index 62fccb0a7..4630c1751 100644 --- a/modules/feh/hm.nix +++ b/modules/feh/hm.nix @@ -1,15 +1,18 @@ { pkgs, config, lib, ... }: { - options.stylix.targets.feh.enable = - config.lib.stylix.mkEnableTarget - "the desktop background using Feh" - true; + options.stylix.targets.feh = { + enable = config.lib.stylix.mkEnableTarget + "the desktop background using Feh" + true; + wallpaper = config.lib.stylix.mkEnableWallpaper "Feh" true; + }; config.xsession.initExtra = lib.mkIf ( config.stylix.enable && config.stylix.targets.feh.enable + && config.stylix.targets.feh.wallpaper && ( with config.xsession.windowManager; bspwm.enable diff --git a/modules/feh/nixos.nix b/modules/feh/nixos.nix index 74f668858..4ad4b3511 100644 --- a/modules/feh/nixos.nix +++ b/modules/feh/nixos.nix @@ -1,15 +1,18 @@ { pkgs, config, lib, ... }: { - options.stylix.targets.feh.enable = - config.lib.stylix.mkEnableTarget - "the desktop background using Feh" - true; + options.stylix.targets.feh = { + enable = config.lib.stylix.mkEnableTarget + "the desktop background using Feh" + true; + wallpaper = config.lib.stylix.mkEnableWallpaper "Feh" true; + }; config.services.xserver.displayManager.sessionCommands = lib.mkIf ( config.stylix.enable && config.stylix.targets.feh.enable + && config.stylix.targets.feh.wallpaper && ( with config.services.xserver.windowManager; xmonad.enable diff --git a/modules/gnome/hm.nix b/modules/gnome/hm.nix index c0cfd2293..82b5586f4 100644 --- a/modules/gnome/hm.nix +++ b/modules/gnome/hm.nix @@ -6,8 +6,10 @@ let documentFontSize = toString (config.stylix.fonts.sizes.applications - 1); in { - options.stylix.targets.gnome.enable = - config.lib.stylix.mkEnableTarget "GNOME" true; + options.stylix.targets.gnome = { + enable = config.lib.stylix.mkEnableTarget "GNOME" true; + wallpaper = config.lib.stylix.mkEnableWallpaper "GNOME" true; + }; config = lib.mkIf (config.stylix.enable && config.stylix.targets.gnome.enable) { dconf.settings = { @@ -26,8 +28,8 @@ in { then "centered" # Seemingly no tile support... :( else "zoom"; - picture-uri = "file://${config.stylix.image}"; - picture-uri-dark = "file://${config.stylix.image}"; + picture-uri = lib.mkIf config.stylix.targets.gnome.wallpaper "file://${config.stylix.image}"; + picture-uri-dark = lib.mkIf config.stylix.targets.gnome.wallpaper "file://${config.stylix.image}"; }; "org/gnome/desktop/interface" = { diff --git a/modules/grub/nixos.nix b/modules/grub/nixos.nix index c95b13652..2ac8e525c 100644 --- a/modules/grub/nixos.nix +++ b/modules/grub/nixos.nix @@ -35,14 +35,20 @@ let # Grub doesn't seem to support tile else "crop"; in { + imports = [ + ( + lib.mkRenamedOptionModuleWith { + from = [ "stylix" "targets" "grub" "useImage" ]; + sinceRelease = 2505; + to = [ "stylix" "targets" "grub" "wallpaper" ]; + } + ) + ]; + options.stylix.targets.grub = { enable = config.lib.stylix.mkEnableTarget "GRUB" true; - useImage = lib.mkOption { - description = "Whether to use your wallpaper image as the GRUB background."; - type = lib.types.bool; - default = false; - }; + wallpaper = config.lib.stylix.mkEnableWallpaper "GRUB" false; }; config.boot.loader.grub = lib.mkIf (config.stylix.enable && config.stylix.targets.grub.enable) { @@ -107,7 +113,7 @@ in { mkdir $out cp $themeTxtPath $out/theme.txt - ${if config.stylix.targets.grub.useImage + ${if config.stylix.targets.grub.wallpaper # Make sure the background image is .png by asking to convert it then "${pkgs.imagemagick}/bin/convert ${config.stylix.image} png32:$out/background.png" diff --git a/modules/hyprland/hm.nix b/modules/hyprland/hm.nix index 27baaf78a..36c656220 100644 --- a/modules/hyprland/hm.nix +++ b/modules/hyprland/hm.nix @@ -1,9 +1,19 @@ { config, lib, ... }: { + imports = [ + ( + lib.mkRenamedOptionModuleWith { + from = [ "stylix" "targets" "hyprland" "hyprpaper" "enable" ]; + sinceRelease = 2505; + to = [ "stylix" "targets" "hyprland" "wallpaper" ]; + } + ) + ]; + options.stylix.targets.hyprland = { enable = config.lib.stylix.mkEnableTarget "Hyprland" true; - hyprpaper.enable = config.lib.stylix.mkEnableTarget "Hyprpaper" true; + wallpaper = config.lib.stylix.mkEnableWallpaper "Hyprland (using Hyprpaper)" true; }; config = let @@ -45,7 +55,7 @@ } ( - lib.mkIf cfg.hyprpaper.enable { + lib.mkIf cfg.wallpaper { services.hyprpaper.enable = true; stylix.targets.hyprpaper.enable = true; } diff --git a/modules/hyprlock/hm.nix b/modules/hyprlock/hm.nix index c54e46166..7bdf54b7d 100644 --- a/modules/hyprlock/hm.nix +++ b/modules/hyprlock/hm.nix @@ -2,11 +2,17 @@ with config.lib.stylix; { - options.stylix.targets.hyprlock.enable = mkEnableTarget "Hyprlock" true; + options.stylix.targets.hyprlock = { + enable = mkEnableTarget "Hyprlock" true; + wallpaper = mkEnableWallpaper "Hyprlock" true; + }; config = lib.mkIf (config.stylix.enable && config.stylix.targets.hyprlock.enable) { programs.hyprlock.settings = { - background.path = "${config.stylix.image}"; + background = { + path = lib.mkIf config.stylix.targets.hyprlock.wallpaper config.stylix.image; + color = "rgb(${base00})"; + }; input-field = with colors; { outer_color = "rgb(${base03})"; inner_color = "rgb(${base00})"; diff --git a/modules/hyprpaper/hm.nix b/modules/hyprpaper/hm.nix index dbb7b08a1..b62b467ca 100644 --- a/modules/hyprpaper/hm.nix +++ b/modules/hyprpaper/hm.nix @@ -1,10 +1,12 @@ { config, lib, ... }: { - options.stylix.targets.hyprpaper.enable = - config.lib.stylix.mkEnableTarget "Hyprpaper" true; + options.stylix.targets.hyprpaper = { + enable = config.lib.stylix.mkEnableTarget "Hyprpaper" true; + wallpaper = config.lib.stylix.mkEnableWallpaper "Hyprpaper" true; + }; config = lib.mkIf - (config.stylix.enable && config.stylix.targets.hyprpaper.enable) + (config.stylix.enable && config.stylix.targets.hyprpaper.enable && config.stylix.targets.hyprpaper.wallpaper) { services.hyprpaper.settings = { preload = [ "${config.stylix.image}" ]; diff --git a/modules/lightdm/nixos.nix b/modules/lightdm/nixos.nix index e0ea1d382..988e7ca4e 100644 --- a/modules/lightdm/nixos.nix +++ b/modules/lightdm/nixos.nix @@ -1,9 +1,11 @@ { config, lib, ... }: { - options.stylix.targets.lightdm.enable = - config.lib.stylix.mkEnableTarget "LightDM" true; + options.stylix.targets.lightdm = { + enable = config.lib.stylix.mkEnableTarget "LightDM" true; + wallpaper = config.lib.stylix.mkEnableWallpaper "LightDM" true; + }; config.services.xserver.displayManager.lightdm.background = - lib.mkIf (config.stylix.enable && config.stylix.targets.lightdm.enable) config.stylix.image; + lib.mkIf (config.stylix.enable && config.stylix.targets.lightdm.enable && config.stylix.targets.lightdm.wallpaper) config.stylix.image; } diff --git a/modules/regreet/nixos.nix b/modules/regreet/nixos.nix index 3b610c6b6..9bd675a13 100644 --- a/modules/regreet/nixos.nix +++ b/modules/regreet/nixos.nix @@ -6,14 +6,17 @@ }: { - options.stylix.targets.regreet.enable = config.lib.stylix.mkEnableTarget "ReGreet" true; + options.stylix.targets.regreet = { + enable = config.lib.stylix.mkEnableTarget "ReGreet" true; + wallpaper = config.lib.stylix.mkEnableWallpaper "ReGreet" true; + }; config = lib.mkIf (config.stylix.enable && config.stylix.targets.regreet.enable && pkgs.stdenv.hostPlatform.isLinux) { programs.regreet = { - settings.background = { + settings.background = lib.mkIf config.stylix.targets.regreet.wallpaper { path = config.stylix.image; fit = let inherit (config.stylix) imageScalingMode; diff --git a/modules/sway/hm.nix b/modules/sway/hm.nix index 6a201ccfb..ac1075f81 100644 --- a/modules/sway/hm.nix +++ b/modules/sway/hm.nix @@ -14,8 +14,10 @@ let }; in { - options.stylix.targets.sway.enable = - config.lib.stylix.mkEnableTarget "Sway" true; + options.stylix.targets.sway = { + enable = config.lib.stylix.mkEnableTarget "Sway" true; + wallpaper = config.lib.stylix.mkEnableWallpaper "Sway" true ; + }; config = lib.mkMerge [ (lib.mkIf (config.stylix.enable && config.stylix.targets.sway.enable) { @@ -54,7 +56,7 @@ in { }; }; - output."*".bg = "${config.stylix.image} ${config.stylix.imageScalingMode}"; + output."*".bg = lib.mkIf config.stylix.targets.sway.wallpaper "${config.stylix.image} ${config.stylix.imageScalingMode}"; seat."*".xcursor_theme = ''"${config.stylix.cursor.name}" ${toString config.stylix.cursor.size}''; }; }) diff --git a/modules/swaylock/hm.nix b/modules/swaylock/hm.nix index ad10cc676..570338fe4 100644 --- a/modules/swaylock/hm.nix +++ b/modules/swaylock/hm.nix @@ -13,14 +13,7 @@ let in { options.stylix.targets.swaylock = { enable = config.lib.stylix.mkEnableTarget "Swaylock" true; - useImage = lib.mkOption { - description = '' - Whether to use your wallpaper image for the Swaylock background. - If this is disabled, a plain color will be used instead. - ''; - type = lib.types.bool; - default = true; - }; + wallpaper = config.lib.stylix.mkEnableWallpaper "Swaylock" true; }; config = lib.mkIf (config.stylix.enable && config.stylix.targets.swaylock.enable && pkgs.stdenv.hostPlatform.isLinux) { @@ -48,7 +41,7 @@ in { text-caps-lock-color = text; text-ver-color = text; text-wrong-color = text; - } // lib.optionalAttrs config.stylix.targets.swaylock.useImage { + } // lib.optionalAttrs config.stylix.targets.swaylock.wallpaper { image = "${config.stylix.image}"; }; }; diff --git a/modules/wpaperd/hm.nix b/modules/wpaperd/hm.nix index c117d6f61..d79de3788 100644 --- a/modules/wpaperd/hm.nix +++ b/modules/wpaperd/hm.nix @@ -1,9 +1,12 @@ { config, lib, ... }: { - options.stylix.targets.wpaperd.enable = config.lib.stylix.mkEnableTarget "wpaperd" true; + options.stylix.targets.wpaperd = { + enable = config.lib.stylix.mkEnableTarget "wpaperd" true; + wallpaper = config.lib.stylix.mkEnableWallpaper "wpaperd" true; + }; - config = lib.mkIf (config.stylix.enable && config.stylix.targets.wpaperd.enable) { + config = lib.mkIf (config.stylix.enable && config.stylix.targets.wpaperd.enable && config.stylix.targets.wpaperd.wallpaper ) { programs.wpaperd.settings.any = { path = "${config.stylix.image}"; mode = let diff --git a/stylix/palette.nix b/stylix/palette.nix index e299d68dc..41799d6b0 100644 --- a/stylix/palette.nix +++ b/stylix/palette.nix @@ -4,7 +4,7 @@ let cfg = config.stylix; - paletteJSON = let + paletteJSON = lib.mkIf (cfg.image != null) ( let generatedJSON = pkgs.runCommand "palette.json" { } '' ${palette-generator}/bin/palette-generator \ "${cfg.polarity}" \ @@ -17,7 +17,7 @@ let template = ./palette.json.mustache; extension = ".json"; }; - in json; + in json); generatedScheme = lib.importJSON paletteJSON; in { @@ -35,13 +35,14 @@ in { }; image = lib.mkOption { - type = with lib.types; coercedTo package toString path; + type = with lib.types; nullOr (coercedTo package toString path); description = '' Wallpaper image. This is set as the background of your desktop environment, if possible, and used to generate a colour scheme if you don't set one manually. ''; + default = null; }; imageScalingMode = lib.mkOption { @@ -99,7 +100,7 @@ in { This can be a path to a file, a string of YAML, or an attribute set. ''; type = with lib.types; oneOf [ path lines attrs ]; - default = generatedScheme; + default = lib.mkIf (cfg.image != null) generatedScheme; defaultText = lib.literalMD '' The colors used in the theming. @@ -124,6 +125,14 @@ in { config = { # This attrset can be used like a function too, see # https://github.com/SenchoPens/base16.nix/blob/b390e87cd404e65ab4d786666351f1292e89162a/README.md#theme-step-22 + + assertions = [ + { + assertion = cfg.image != null || cfg.base16Scheme != null; + message = "One of `stylix.image` or `stylix.base16Scheme` must be set"; + } + ]; + lib.stylix.colors = (base16.mkSchemeAttrs cfg.base16Scheme).override cfg.override; lib.stylix.scheme = base16.mkSchemeAttrs cfg.base16Scheme; diff --git a/stylix/target.nix b/stylix/target.nix index c1908da82..e5099b784 100644 --- a/stylix/target.nix +++ b/stylix/target.nix @@ -31,18 +31,31 @@ }; }; - config.lib.stylix.mkEnableTarget = let + config.lib.stylix = let cfg = config.stylix; - in - humanName: - autoEnable: - lib.mkEnableOption - "theming for ${humanName}" - // { - default = cfg.enable && cfg.autoEnable && autoEnable; - example = !autoEnable; - } - // lib.optionalAttrs autoEnable { - defaultText = lib.literalMD "same as [`stylix.autoEnable`](#stylixautoenable)"; - }; + in { + mkEnableTarget = + humanName: + autoEnable: + lib.mkEnableOption + "theming for ${humanName}" + // { + default = cfg.enable && cfg.autoEnable && autoEnable; + example = !autoEnable; + } + // lib.optionalAttrs autoEnable { + defaultText = lib.literalMD "same as [`stylix.autoEnable`](#stylixautoenable)"; + }; + mkEnableWallpaper = + humanName: + autoEnable: + lib.mkOption { + default = (config.stylix.image != null) && autoEnable; + example = config.stylix.image == null; + description = "Whether to set the wallpaper for ${humanName}"; + } + // lib.optionalAttrs autoEnable { + defaultText = lib.literalMD "same as setting `stylix.image`"; + }; + }; } diff --git a/stylix/testbed.nix b/stylix/testbed.nix index 7fc738373..1a666d27e 100644 --- a/stylix/testbed.nix +++ b/stylix/testbed.nix @@ -96,7 +96,7 @@ let makeTestbed = testbed: stylix: let - name = "testbed-${testbed.name}-${stylix.polarity}"; + name = "testbed-${testbed.name}-${stylix.polarity}" + ( if stylix.image == null then "-imageless" else ""); system = lib.nixosSystem { inherit (pkgs) system; @@ -158,6 +158,12 @@ let base16Scheme = "${pkgs.base16-schemes}/share/themes/catppuccin-macchiato.yaml"; polarity = "dark"; } + { + enable = true; + image = null; + base16Scheme = "${pkgs.base16-schemes}/share/themes/catppuccin-macchiato.yaml"; + polarity = "dark"; + } ]; in