diff --git a/modules/feh/hm.nix b/modules/feh/hm.nix index 62fccb0a7..85efaf650 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"; + }; 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..09ba7e2b9 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"; + }; 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..03f83cb38 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"; + }; 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..2a566b6e0 100644 --- a/modules/grub/nixos.nix +++ b/modules/grub/nixos.nix @@ -38,11 +38,7 @@ in { 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" // { default = false; }; }; config.boot.loader.grub = lib.mkIf (config.stylix.enable && config.stylix.targets.grub.enable) { @@ -107,7 +103,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/hyprlock/hm.nix b/modules/hyprlock/hm.nix index c54e46166..4f1830315 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"; + }; 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..57fcf5412 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"; + }; 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..048528155 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"; + }; 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..24447ec29 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"; + }; 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..204bef493 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"; }; 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..5967fc86b 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"; + }; - 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..fee8d46f7 100644 --- a/stylix/target.nix +++ b/stylix/target.nix @@ -31,18 +31,28 @@ }; }; - 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: + lib.mkEnableOption + "toggle for wallpaper for ${humanName}" + // { + default = config.stylix.image != null; + example = config.stylix.image == null; + }; + }; } diff --git a/stylix/testbed.nix b/stylix/testbed.nix index 7fc738373..a38ba3ba8 100644 --- a/stylix/testbed.nix +++ b/stylix/testbed.nix @@ -158,6 +158,11 @@ let base16Scheme = "${pkgs.base16-schemes}/share/themes/catppuccin-macchiato.yaml"; polarity = "dark"; } + { + enable = true; + base16Scheme = "${pkgs.base16-schemes}/share/themes/catppuccin-macchiato.yaml"; + polarity = "dark"; + } ]; in