From c8e4a0d2186d388e3c6f3240b8b3ae422a7780d7 Mon Sep 17 00:00:00 2001 From: Flameopathic <64027365+Flameopathic@users.noreply.github.com> Date: Mon, 24 Feb 2025 09:13:57 -0500 Subject: [PATCH] treewide: optionalize stylix.image option (#717) Optionalize the stylix.image option when stylix.base16Scheme is set, making the following Stylix configurations valid: [ // Now it possible to set 'stylix.image = null', if // stylix.base16Scheme is set. { base16Scheme = /* ... */; } // This configuration was already possible. { image = /* ... */; } // This configuration was already possible. { base16Scheme = /* ... */; image = /* ... */; } ] Closes: https://github.com/danth/stylix/issues/200 Closes: https://github.com/danth/stylix/issues/442 Link: https://github.com/danth/stylix/pull/717 Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com> Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com> Tested-by: NAHO <90870942+trueNAHO@users.noreply.github.com> Reviewed-by: Daniel Thwaites --- .github/workflows/check.yml | 7 +- docs/src/configuration.md | 85 +++++++++--------- modules/feh/hm.nix | 13 ++- modules/feh/nixos.nix | 13 ++- modules/gnome/hm.nix | 13 +-- modules/grub/nixos.nix | 167 +++++++++++++++++++----------------- modules/hyprland/hm.nix | 4 +- modules/hyprlock/hm.nix | 38 ++++---- modules/hyprpaper/hm.nix | 24 +++--- modules/kde/hm.nix | 6 +- modules/lightdm/nixos.nix | 12 ++- modules/regreet/nixos.nix | 18 ++-- modules/sway/hm.nix | 13 ++- modules/swaylock/hm.nix | 31 ++++--- modules/wayfire/hm.nix | 105 ++++++++++++----------- modules/wpaperd/hm.nix | 61 ++++++------- stylix/palette.nix | 10 ++- stylix/target.nix | 32 +++++-- stylix/testbed.nix | 39 ++++++--- 19 files changed, 401 insertions(+), 290 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index a82c9614..0859f460 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -77,7 +77,12 @@ jobs: - uses: DeterminateSystems/nix-installer-action@v16 with: extra-conf: |- - allow-import-from-derivation = false + allow-import-from-derivation = ${{ + startsWith(matrix.check.key, 'testbed:') && + contains(matrix.check.key, ':schemeless') && + 'true' || + 'false' + }} - run: | nix build --no-update-lock-file --print-build-logs \ diff --git a/docs/src/configuration.md b/docs/src/configuration.md index 8ab7554d..7ce96f9e 100644 --- a/docs/src/configuration.md +++ b/docs/src/configuration.md @@ -16,53 +16,12 @@ To enable the Stylix module, declare: > examples which don't include it. No other settings will take effect unless > `stylix.enable` is set to `true`. -## Wallpaper - -To start theming, you need to set a wallpaper image. - -```nix -{ - stylix.image = ./wallpaper.png; -} -``` - -The option accepts derivations as well as paths, so you can fetch an image -directly from the internet: - -```nix -{ - stylix.image = pkgs.fetchurl { - url = "https://www.pixelstalk.net/wp-content/uploads/2016/05/Epic-Anime-Awesome-Wallpapers.jpg"; - sha256 = "enQo3wqhgf0FEPHj2coOCvo7DuZv+x5rL/WIo4qPI50="; - }; -} -``` - ## Color scheme -### Generated schemes - -If you only set a wallpaper, Stylix will use a -[genetic algorithm](https://en.wikipedia.org/wiki/Genetic_algorithm) -to create a color scheme. The quality of these schemes can vary, but more -colorful images tend to have better results. - -You can force a light or dark scheme using the polarity option: - -```nix -{ - stylix.polarity = "dark"; -} -``` - -The current scheme can be previewed in a web browser at either -[`/etc/stylix/palette.html`](file:///etc/stylix/palette.html) for NixOS, or -`~/.config/stylix/palette.html` for Home Manager. - ### Handmade schemes -If you prefer a handmade color scheme, you can choose anything from -[the Tinted Theming repository](https://github.com/tinted-theming/schemes): +To set a [Tinted Theming](https://github.com/tinted-theming/schemes) color +scheme, declare: ```nix { @@ -116,6 +75,46 @@ For more complex configurations you may find it simpler to use See [base16.nix](https://github.com/SenchoPens/base16.nix) documentation for usage examples. +## Wallpaper + +To set a wallpaper, provide a path or an arbitrary derivation: + +- ```nix + { + stylix.image = ./wallpaper.png; + } + ``` + +- ```nix + { + stylix.image = pkgs.fetchurl { + url = "https://www.pixelstalk.net/wp-content/uploads/2016/05/Epic-Anime-Awesome-Wallpapers.jpg"; + sha256 = "enQo3wqhgf0FEPHj2coOCvo7DuZv+x5rL/WIo4qPI50="; + }; + } + ``` + +If `stylix.base16Scheme` is undeclared, Stylix generates a color scheme based on +the wallpaper using a [genetic +algorithm](https://en.wikipedia.org/wiki/Genetic_algorithm). Note that more +colorful images tend to yield better results. The algorithm's polarity can be +schewed towards a dark or light theme with: + +- ```nix + { + stylix.polarity = "dark"; + } + ``` + +- ```nix + { + stylix.polarity = "light"; + } + ``` + +The generated color scheme can be viewed at `/etc/stylix/palette.html` on NixOS, +or at `~/.config/stylix/palette.html` on Home Manager. + ## Fonts The default combination of fonts is: diff --git a/modules/feh/hm.nix b/modules/feh/hm.nix index a1012994..989c0779 100644 --- a/modules/feh/hm.nix +++ b/modules/feh/hm.nix @@ -4,16 +4,21 @@ lib, ... }: - +let + cfg = config.stylix.targets.feh; +in { - 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" ( + config.stylix.image != null + ); + }; config.xsession.initExtra = lib.mkIf ( config.stylix.enable - && config.stylix.targets.feh.enable + && cfg.enable && ( with config.xsession.windowManager; bspwm.enable diff --git a/modules/feh/nixos.nix b/modules/feh/nixos.nix index 64469e0a..ca527511 100644 --- a/modules/feh/nixos.nix +++ b/modules/feh/nixos.nix @@ -4,16 +4,21 @@ lib, ... }: - +let + cfg = config.stylix.targets.feh; +in { - 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" ( + config.stylix.image != null + ); + }; config.services.xserver.displayManager.sessionCommands = lib.mkIf ( config.stylix.enable - && config.stylix.targets.feh.enable + && cfg.enable && (with config.services.xserver.windowManager; xmonad.enable || i3.enable) ) ( diff --git a/modules/gnome/hm.nix b/modules/gnome/hm.nix index d57458ae..660008ef 100644 --- a/modules/gnome/hm.nix +++ b/modules/gnome/hm.nix @@ -9,6 +9,7 @@ let inherit (config.stylix.fonts) sansSerif serif monospace; fontSize = toString config.stylix.fonts.sizes.applications; documentFontSize = toString (config.stylix.fonts.sizes.applications - 1); + cfg = config.stylix.targets.gnome; activator = pkgs.writeShellApplication { name = "stylix-activate-gnome"; @@ -42,10 +43,12 @@ let in { - options.stylix.targets.gnome.enable = - config.lib.stylix.mkEnableTarget "GNOME" true; + options.stylix.targets.gnome = { + enable = config.lib.stylix.mkEnableTarget "GNOME" true; + useWallpaper = config.lib.stylix.mkEnableWallpaper "GNOME" true; + }; - config = lib.mkIf (config.stylix.enable && config.stylix.targets.gnome.enable) { + config = lib.mkIf (config.stylix.enable && cfg.enable) { dconf.settings = { "org/gnome/desktop/background" = { color-shading-type = "solid"; @@ -64,8 +67,8 @@ in # Seemingly no tile support... :( else "zoom"; - picture-uri = "file://${config.stylix.image}"; - picture-uri-dark = "file://${config.stylix.image}"; + picture-uri = lib.mkIf cfg.useWallpaper "file://${config.stylix.image}"; + picture-uri-dark = lib.mkIf cfg.useWallpaper "file://${config.stylix.image}"; }; "org/gnome/desktop/interface" = { diff --git a/modules/grub/nixos.nix b/modules/grub/nixos.nix index d49cc1c4..e767516f 100644 --- a/modules/grub/nixos.nix +++ b/modules/grub/nixos.nix @@ -10,6 +10,7 @@ with config.stylix.fonts; with config.lib.stylix.colors.withHashtag; let + cfg = config.stylix.targets.grub; # Grub requires fonts to be converted to "PFF2 format" # This function takes a font { name, package } and produces a .pf2 file mkGrubFont = @@ -44,97 +45,107 @@ let "crop"; in { + imports = [ + (lib.mkRenamedOptionModuleWith { + from = [ + "stylix" + "targets" + "grub" + "useImage" + ]; + sinceRelease = 2505; + to = [ + "stylix" + "targets" + "grub" + "useWallpaper" + ]; + }) + ]; 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; - }; + useWallpaper = config.lib.stylix.mkEnableWallpaper "GRUB" false; }; - config.boot.loader.grub = - lib.mkIf (config.stylix.enable && config.stylix.targets.grub.enable) - { - backgroundColor = base00; - # Need to override the NixOS splash, this will match the background - splashImage = pixel "base00"; + config.boot.loader.grub = lib.mkIf (config.stylix.enable && cfg.enable) { + backgroundColor = base00; + # Need to override the NixOS splash, this will match the background + splashImage = pixel "base00"; - # This font will be used for the GRUB terminal - font = toString (mkGrubFont monospace); + # This font will be used for the GRUB terminal + font = toString (mkGrubFont monospace); - # TODO: Include OS icons - theme = - pkgs.runCommand "stylix-grub" - { - themeTxt = '' - desktop-image: "background.png" - desktop-image-scale-method: "${image-scale}" - desktop-color: "${base00}" + # TODO: Include OS icons + theme = + pkgs.runCommand "stylix-grub" + { + themeTxt = '' + desktop-image: "background.png" + desktop-image-scale-method: "${image-scale}" + desktop-color: "${base00}" - title-text: "" + title-text: "" - terminal-left: "10%" - terminal-top: "20%" - terminal-width: "80%" - terminal-height: "60%" + terminal-left: "10%" + terminal-top: "20%" + terminal-width: "80%" + terminal-height: "60%" - + progress_bar { - left = 25% - top = 80%+20 # 20 pixels below boot menu - width = 50% - height = 30 + + progress_bar { + left = 25% + top = 80%+20 # 20 pixels below boot menu + width = 50% + height = 30 - id = "__timeout__" - show_text = true - font = "${sansSerif.name}" - text = "@TIMEOUT_NOTIFICATION_MIDDLE@" + id = "__timeout__" + show_text = true + font = "${sansSerif.name}" + text = "@TIMEOUT_NOTIFICATION_MIDDLE@" - border_color = "${base00}" - bg_color = "${base00}" - fg_color = "${base0B}" - text_color = "${base05}" - } - - + boot_menu { - left = 25% - top = 20% - width = 50% - height = 60% - menu_pixmap_style = "background_*.png" - - item_height = 40 - item_icon_space = 8 - item_spacing = 0 - item_padding = 0 - item_font = "${sansSerif.name}" - item_color = "${base05}" - - selected_item_color = "${base01}" - selected_item_pixmap_style = "selection_*.png" - } - ''; - passAsFile = [ "themeTxt" ]; + border_color = "${base00}" + bg_color = "${base00}" + fg_color = "${base0B}" + text_color = "${base05}" } - '' - mkdir $out - cp $themeTxtPath $out/theme.txt - ${ - if - config.stylix.targets.grub.useImage - # Make sure the background image is .png by asking to convert it - then - "${pkgs.imagemagick}/bin/convert ${config.stylix.image} png32:$out/background.png" - else - "cp ${pixel "base00"} $out/background.png" - } + + boot_menu { + left = 25% + top = 20% + width = 50% + height = 60% + menu_pixmap_style = "background_*.png" - cp ${pixel "base01"} $out/background_c.png - cp ${pixel "base0B"} $out/selection_c.png + item_height = 40 + item_icon_space = 8 + item_spacing = 0 + item_padding = 0 + item_font = "${sansSerif.name}" + item_color = "${base05}" - cp ${mkGrubFont sansSerif} $out/sans_serif.pf2 - ''; - }; + selected_item_color = "${base01}" + selected_item_pixmap_style = "selection_*.png" + } + ''; + passAsFile = [ "themeTxt" ]; + } + '' + mkdir $out + cp $themeTxtPath $out/theme.txt + + ${ + if + cfg.useWallpaper + # Make sure the background image is .png by asking to convert it + then + "${pkgs.imagemagick}/bin/convert ${config.stylix.image} png32:$out/background.png" + else + "cp ${pixel "base00"} $out/background.png" + } + + cp ${pixel "base01"} $out/background_c.png + cp ${pixel "base0B"} $out/selection_c.png + + cp ${mkGrubFont sansSerif} $out/sans_serif.pf2 + ''; + }; } diff --git a/modules/hyprland/hm.nix b/modules/hyprland/hm.nix index ad3e5c60..8ee1edef 100644 --- a/modules/hyprland/hm.nix +++ b/modules/hyprland/hm.nix @@ -3,7 +3,9 @@ { options.stylix.targets.hyprland = { enable = config.lib.stylix.mkEnableTarget "Hyprland" true; - hyprpaper.enable = config.lib.stylix.mkEnableTarget "Hyprpaper" true; + hyprpaper.enable = config.lib.stylix.mkEnableTarget "Hyprpaper" ( + config.stylix.image != null + ); }; config = diff --git a/modules/hyprlock/hm.nix b/modules/hyprlock/hm.nix index e3acef98..b0592f4e 100644 --- a/modules/hyprlock/hm.nix +++ b/modules/hyprlock/hm.nix @@ -1,21 +1,29 @@ { config, lib, ... }: with config.lib.stylix; -{ - options.stylix.targets.hyprlock.enable = mkEnableTarget "Hyprlock" true; - config = - lib.mkIf (config.stylix.enable && config.stylix.targets.hyprlock.enable) - { - programs.hyprlock.settings = { - background.path = "${config.stylix.image}"; - input-field = with colors; { - outer_color = "rgb(${base03})"; - inner_color = "rgb(${base00})"; - font_color = "rgb(${base05})"; - fail_color = "rgb(${base08})"; - check_color = "rgb(${base0A})"; - }; - }; +let + cfg = config.stylix.targets.hyprlock; +in +{ + options.stylix.targets.hyprlock = { + enable = mkEnableTarget "Hyprlock" true; + useWallpaper = mkEnableWallpaper "Hyprlock" true; + }; + + config = lib.mkIf (config.stylix.enable && cfg.enable) { + programs.hyprlock.settings = { + background = { + path = lib.mkIf cfg.useWallpaper config.stylix.image; + color = "rgb(${base00})"; }; + input-field = with colors; { + outer_color = "rgb(${base03})"; + inner_color = "rgb(${base00})"; + font_color = "rgb(${base05})"; + fail_color = "rgb(${base08})"; + check_color = "rgb(${base0A})"; + }; + }; + }; } diff --git a/modules/hyprpaper/hm.nix b/modules/hyprpaper/hm.nix index 325f0501..1bf17a97 100644 --- a/modules/hyprpaper/hm.nix +++ b/modules/hyprpaper/hm.nix @@ -1,14 +1,18 @@ { config, lib, ... }: +let + cfg = config.stylix.targets.hyprpaper; +in { - options.stylix.targets.hyprpaper.enable = - config.lib.stylix.mkEnableTarget "Hyprpaper" true; + options.stylix.targets.hyprpaper = { + enable = config.lib.stylix.mkEnableTarget "Hyprpaper" ( + config.stylix.image != null + ); + }; - config = - lib.mkIf (config.stylix.enable && config.stylix.targets.hyprpaper.enable) - { - services.hyprpaper.settings = { - preload = [ "${config.stylix.image}" ]; - wallpaper = [ ",${config.stylix.image}" ]; - }; - }; + config = lib.mkIf (config.stylix.enable && cfg.enable) { + services.hyprpaper.settings = { + preload = [ "${config.stylix.image}" ]; + wallpaper = [ ",${config.stylix.image}" ]; + }; + }; } diff --git a/modules/kde/hm.nix b/modules/kde/hm.nix index ebeeb3ec..01c305d5 100644 --- a/modules/kde/hm.nix +++ b/modules/kde/hm.nix @@ -10,6 +10,7 @@ let inherit (config.lib.stylix) colors mkEnableTarget + mkEnableWallpaper ; inherit (config.stylix) image @@ -20,8 +21,7 @@ let let satisfies = check: (check default) && (check withImage); in - # TODO: when adding `wallpaper` option to this module, replace this with `image == null || !cfg.wallpaper` - if image == null then + if image == null || !cfg.useWallpaper then default else if satisfies lib.isString then default + withImage @@ -336,7 +336,7 @@ in { options.stylix.targets.kde = { enable = mkEnableTarget "KDE" true; - + useWallpaper = mkEnableWallpaper "KDE" true; decorations = lib.mkOption { type = lib.types.str; default = "org.kde.breeze"; diff --git a/modules/lightdm/nixos.nix b/modules/lightdm/nixos.nix index 36873584..c52e6023 100644 --- a/modules/lightdm/nixos.nix +++ b/modules/lightdm/nixos.nix @@ -1,10 +1,14 @@ { config, lib, ... }: - +let + cfg = config.stylix.targets.lightdm; +in { - options.stylix.targets.lightdm.enable = - config.lib.stylix.mkEnableTarget "LightDM" true; + options.stylix.targets.lightdm = { + enable = config.lib.stylix.mkEnableTarget "LightDM" true; + useWallpaper = config.lib.stylix.mkEnableWallpaper "LightDM" true; + }; config.services.xserver.displayManager.lightdm.background = lib.mkIf ( - config.stylix.enable && config.stylix.targets.lightdm.enable + config.stylix.enable && cfg.enable && cfg.useWallpaper ) config.stylix.image; } diff --git a/modules/regreet/nixos.nix b/modules/regreet/nixos.nix index 2cc9d570..e8476e89 100644 --- a/modules/regreet/nixos.nix +++ b/modules/regreet/nixos.nix @@ -4,18 +4,18 @@ lib, ... }: - +let + cfg = config.stylix.targets.regreet; +in { - options.stylix.targets.regreet.enable = - config.lib.stylix.mkEnableTarget "ReGreet" true; + options.stylix.targets.regreet = { + enable = config.lib.stylix.mkEnableTarget "ReGreet" true; + useWallpaper = config.lib.stylix.mkEnableWallpaper "ReGreet" true; + }; config = lib.mkIf - ( - config.stylix.enable - && config.stylix.targets.regreet.enable - && pkgs.stdenv.hostPlatform.isLinux - ) + (config.stylix.enable && cfg.enable && pkgs.stdenv.hostPlatform.isLinux) { warnings = let @@ -32,7 +32,7 @@ "stylix: regreet: custom services.greetd.settings.default_session.command value may not work: ${config.services.greetd.settings.default_session.command}"; programs.regreet = { settings.GTK.application_prefer_dark_theme = config.stylix.polarity == "dark"; - settings.background = { + settings.background = lib.mkIf cfg.useWallpaper { path = config.stylix.image; fit = let diff --git a/modules/sway/hm.nix b/modules/sway/hm.nix index 8bbaba3b..c5c4d042 100644 --- a/modules/sway/hm.nix +++ b/modules/sway/hm.nix @@ -3,6 +3,8 @@ with config.lib.stylix.colors.withHashtag; let + cfg = config.stylix.targets.sway; + text = base05; urgent = base08; focused = base0D; @@ -15,11 +17,13 @@ let in { - options.stylix.targets.sway.enable = - config.lib.stylix.mkEnableTarget "Sway" true; + options.stylix.targets.sway = { + enable = config.lib.stylix.mkEnableTarget "Sway" true; + useWallpaper = config.lib.stylix.mkEnableWallpaper "Sway" true; + }; config = lib.mkMerge [ - (lib.mkIf (config.stylix.enable && config.stylix.targets.sway.enable) { + (lib.mkIf (config.stylix.enable && cfg.enable) { wayland.windowManager.sway.config = { inherit fonts; @@ -57,7 +61,8 @@ in }; }; - output."*".bg = "${config.stylix.image} ${config.stylix.imageScalingMode}"; + output."*".bg = + lib.mkIf cfg.useWallpaper "${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 359447cd..d03c0e9c 100644 --- a/modules/swaylock/hm.nix +++ b/modules/swaylock/hm.nix @@ -1,6 +1,5 @@ { pkgs, - options, config, lib, ... @@ -9,6 +8,8 @@ with config.lib.stylix.colors; let + cfg = config.stylix.targets.swaylock; + inside = base01-hex; outside = base01-hex; ring = base05-hex; @@ -18,16 +19,26 @@ let in { + imports = [ + (lib.mkRenamedOptionModuleWith { + from = [ + "stylix" + "targets" + "swaylock" + "useImage" + ]; + sinceRelease = 2505; + to = [ + "stylix" + "targets" + "swaylock" + "useWallpaper" + ]; + }) + ]; 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; - }; + useWallpaper = config.lib.stylix.mkEnableWallpaper "Swaylock" true; }; config = @@ -71,7 +82,7 @@ in text-ver-color = text; text-wrong-color = text; } - // lib.optionalAttrs config.stylix.targets.swaylock.useImage { + // lib.optionalAttrs cfg.useWallpaper { image = "${config.stylix.image}"; }; }; diff --git a/modules/wayfire/hm.nix b/modules/wayfire/hm.nix index 45fb00ed..19559172 100644 --- a/modules/wayfire/hm.nix +++ b/modules/wayfire/hm.nix @@ -4,60 +4,65 @@ pkgs, ... }: +let + cfg = config.stylix.targets.wayfire; +in { - options.stylix.targets.wayfire.enable = - config.lib.stylix.mkEnableTarget "wayfire" true; + options.stylix.targets.wayfire = { + enable = config.lib.stylix.mkEnableTarget "wayfire" true; + useWallpaper = config.lib.stylix.mkEnableWallpaper "wayfire" true; + }; - config = - lib.mkIf (config.stylix.enable && config.stylix.targets.wayfire.enable) - ( - let - inherit (config.lib.stylix) colors; - rgba = rgb: a: "\\#${rgb}${a}"; - rgb = (lib.flip rgba) "ff"; + config = lib.mkIf (config.stylix.enable && cfg.enable) ( + let + inherit (config.lib.stylix) colors; + rgba = rgb: a: "\\#${rgb}${a}"; + rgb = (lib.flip rgba) "ff"; - wayfireConfig = config.wayland.windowManager.wayfire; + wayfireConfig = config.wayland.windowManager.wayfire; - wayfireBackground = pkgs.runCommand "wayfire-background.png" { } '' - ${lib.getExe' pkgs.imagemagick "convert"} ${config.stylix.image} $out - ''; - in - { - wayland.windowManager.wayfire.settings = lib.mkIf wayfireConfig.enable { - cube = { - background = rgb colors.base00; - cubemap_image = "${wayfireBackground}"; - skydome_texture = "${wayfireBackground}"; - }; - - expo.background = rgb colors.base00; - vswitch.background = rgb colors.base00; - vswipe.background = rgb colors.base00; - core.background_color = rgb colors.base00; - - decoration = { - font = "${config.stylix.fonts.monospace.name} ${builtins.toString config.stylix.fonts.sizes.desktop}"; - active_color = rgb colors.base0D; - inactive_color = rgb colors.base03; - }; - }; - - wayland.windowManager.wayfire.wf-shell.settings = - lib.mkIf wayfireConfig.wf-shell.enable - { - background.image = "${wayfireBackground}"; - background.fill_mode = - if config.stylix.imageScalingMode == "stretch" then - "stretch" - else if config.stylix.imageScalingMode == "fit" then - "preserve_aspect" - else - "fill_and_crop"; - - panel.background_color = rgb colors.base01; - panel.menu_icon = "${pkgs.nixos-icons}/share/icons/hicolor/256x256/apps/nix-snowflake.png"; - }; - } + wayfireBackground = lib.mkIf cfg.useWallpaper ( + pkgs.runCommand "wayfire-background.png" { } '' + ${lib.getExe' pkgs.imagemagick "convert"} ${config.stylix.image} $out + '' ); + in + { + wayland.windowManager.wayfire.settings = lib.mkIf wayfireConfig.enable { + cube = { + background = rgb colors.base00; + cubemap_image = lib.mkIf cfg.useWallpaper "${wayfireBackground}"; + skydome_texture = lib.mkIf cfg.useWallpaper "${wayfireBackground}"; + }; + + expo.background = rgb colors.base00; + vswitch.background = rgb colors.base00; + vswipe.background = rgb colors.base00; + core.background_color = rgb colors.base00; + + decoration = { + font = "${config.stylix.fonts.monospace.name} ${builtins.toString config.stylix.fonts.sizes.desktop}"; + active_color = rgb colors.base0D; + inactive_color = rgb colors.base03; + }; + }; + + wayland.windowManager.wayfire.wf-shell.settings = + lib.mkIf wayfireConfig.wf-shell.enable + { + background.image = lib.mkIf cfg.useWallpaper "${wayfireBackground}"; + background.fill_mode = + if config.stylix.imageScalingMode == "stretch" then + "stretch" + else if config.stylix.imageScalingMode == "fit" then + "preserve_aspect" + else + "fill_and_crop"; + + panel.background_color = rgb colors.base01; + panel.menu_icon = "${pkgs.nixos-icons}/share/icons/hicolor/256x256/apps/nix-snowflake.png"; + }; + } + ); } diff --git a/modules/wpaperd/hm.nix b/modules/wpaperd/hm.nix index 16a58d89..e2bc31b9 100644 --- a/modules/wpaperd/hm.nix +++ b/modules/wpaperd/hm.nix @@ -1,35 +1,38 @@ { config, lib, ... }: - +let + cfg = config.stylix.targets.wpaperd; +in { - options.stylix.targets.wpaperd.enable = - config.lib.stylix.mkEnableTarget "wpaperd" true; + options.stylix.targets.wpaperd = { + enable = config.lib.stylix.mkEnableTarget "wpaperd" ( + config.stylix.image != null + ); + }; - config = - lib.mkIf (config.stylix.enable && config.stylix.targets.wpaperd.enable) - ( - let - inherit (config.stylix) imageScalingMode; + config = lib.mkIf (config.stylix.enable && cfg.enable) ( + let + inherit (config.stylix) imageScalingMode; - # wpaperd doesn't have any mode close to the described behavior of center - modeMap = { - "stretch" = "stretch"; - # wpaperd's center mode is closest to the described behavior of fill - "fill" = "center"; - "fit" = "fit"; - "tile" = "tile"; - }; + # wpaperd doesn't have any mode close to the described behavior of center + modeMap = { + "stretch" = "stretch"; + # wpaperd's center mode is closest to the described behavior of fill + "fill" = "center"; + "fit" = "fit"; + "tile" = "tile"; + }; - modeAttrs = - if builtins.hasAttr imageScalingMode modeMap then - { mode = modeMap.${imageScalingMode}; } - else - lib.info "stylix: wpaperd: unsupported image scaling mode: ${imageScalingMode}" - { }; - in - { - programs.wpaperd.settings.any = { - path = "${config.stylix.image}"; - } // modeAttrs; - } - ); + modeAttrs = + if builtins.hasAttr imageScalingMode modeMap then + { mode = modeMap.${imageScalingMode}; } + else + lib.info "stylix: wpaperd: unsupported image scaling mode: ${imageScalingMode}" + { }; + in + { + programs.wpaperd.settings.any = { + path = "${config.stylix.image}"; + } // modeAttrs; + } + ); } diff --git a/stylix/palette.nix b/stylix/palette.nix index b59a6687..f57b94b8 100644 --- a/stylix/palette.nix +++ b/stylix/palette.nix @@ -29,13 +29,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 { @@ -158,6 +159,13 @@ in # https://github.com/SenchoPens/base16.nix/blob/b390e87cd404e65ab4d786666351f1292e89162a/README.md#theme-step-22 lib.stylix.colors = (cfg.base16.mkSchemeAttrs cfg.base16Scheme).override cfg.override; + assertions = [ + { + assertion = !(cfg.image == null && cfg.base16Scheme == null); + message = "One of `stylix.image` or `stylix.base16Scheme` must be set"; + } + ]; + stylix.generated.fileTree = { # The raw output of the palette generator. "stylix/generated.json" = { diff --git a/stylix/target.nix b/stylix/target.nix index ca3af6eb..12b8494b 100644 --- a/stylix/target.nix +++ b/stylix/target.nix @@ -31,17 +31,31 @@ }; }; - config.lib.stylix.mkEnableTarget = + 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`"; + { + 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`"; + }; + mkEnableWallpaper = + humanName: autoEnable: + lib.mkOption { + default = config.stylix.image != null && autoEnable; + example = config.stylix.image == null; + description = "Whether to set the wallpaper for ${humanName}."; + type = lib.types.bool; + } + // lib.optionalAttrs autoEnable { + defaultText = lib.literalMD "`stylix.image != null`"; + }; }; } diff --git a/stylix/testbed.nix b/stylix/testbed.nix index 0d20bd49..bbaeab29 100644 --- a/stylix/testbed.nix +++ b/stylix/testbed.nix @@ -137,6 +137,8 @@ let testbed.module testbed.name stylix.polarity + "image${lib.optionalString (stylix.image or null == null) "less"}" + "scheme${lib.optionalString (stylix.base16Scheme or null == null) "less"}" ]; system = lib.nixosSystem { @@ -181,28 +183,45 @@ let # This generates a copy of each testbed for each of the following themes. makeTestbeds = - testbed: - map (makeTestbed testbed) [ - { - enable = true; - image = pkgs.fetchurl { + let + images = { + dark = pkgs.fetchurl { + name = "mountains.jpg"; + url = "https://unsplash.com/photos/ZqLeQDjY6fY/download?ixid=M3wxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNzE2MzY1NDY4fA&force=true"; + hash = "sha256-Dm/0nKiTFOzNtSiARnVg7zM0J1o+EuIdUQ3OAuasM58="; + }; + + light = pkgs.fetchurl { name = "three-bicycles.jpg"; url = "https://unsplash.com/photos/hwLAI5lRhdM/download?ixid=M3wxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNzE2MzYxNDcwfA&force=true"; hash = "sha256-S0MumuBGJulUekoGI2oZfUa/50Jw0ZzkqDDu1nRkFUA="; }; + }; + in + testbed: + map (makeTestbed testbed) [ + { + enable = true; + image = images.light; base16Scheme = "${inputs.tinted-schemes}/base16/catppuccin-latte.yaml"; polarity = "light"; } { enable = true; - image = pkgs.fetchurl { - name = "mountains.jpg"; - url = "https://unsplash.com/photos/ZqLeQDjY6fY/download?ixid=M3wxMjA3fDB8MXxhbGx8fHx8fHx8fHwxNzE2MzY1NDY4fA&force=true"; - hash = "sha256-Dm/0nKiTFOzNtSiARnVg7zM0J1o+EuIdUQ3OAuasM58="; - }; + image = images.dark; base16Scheme = "${inputs.tinted-schemes}/base16/catppuccin-macchiato.yaml"; polarity = "dark"; } + { + enable = true; + base16Scheme = "${inputs.tinted-schemes}/base16/catppuccin-macchiato.yaml"; + polarity = "dark"; + } + { + enable = true; + image = images.dark; + polarity = "dark"; + } ]; in