Skip to content

Commit

Permalink
treewide: optionalize stylix.image
Browse files Browse the repository at this point in the history
  • Loading branch information
Flameopathic committed Jan 26, 2025
1 parent d6951d0 commit 833cbbd
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 68 deletions.
6 changes: 4 additions & 2 deletions modules/feh/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
}:

{
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
Expand Down
6 changes: 4 additions & 2 deletions modules/feh/nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
}:

{
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
Expand Down
10 changes: 6 additions & 4 deletions modules/gnome/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ let

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 = {
Expand All @@ -34,8 +36,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 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" = {
Expand Down
26 changes: 19 additions & 7 deletions modules/grub/nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,26 @@ let
"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 =
Expand Down Expand Up @@ -123,7 +135,7 @@ in
${
if
config.stylix.targets.grub.useImage
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"
Expand Down
10 changes: 8 additions & 2 deletions modules/hyprlock/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

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})";
Expand Down
13 changes: 10 additions & 3 deletions modules/hyprpaper/hm.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{ 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)
lib.mkIf
(
config.stylix.enable
&& config.stylix.targets.hyprpaper.enable
&& config.stylix.targets.hyprpaper.wallpaper
)
{
services.hyprpaper.settings = {
preload = [ "${config.stylix.image}" ];
Expand Down
38 changes: 26 additions & 12 deletions modules/kde/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,20 @@ let
mkdir --parents "$wallpaper/contents/images"
magick \
"$wallpaperImage" \
-thumbnail 400x250 \
"$wallpaper/contents/screenshot.png"
dimensions="$(identify -ping -format '%wx%h' "$wallpaperImage")"
magick "$wallpaperImage" "$wallpaper/contents/images/$dimensions.png"
${
if (config.stylix.image != null) then
''
magick \
"$wallpaperImage" \
-thumbnail 400x250 \
"$wallpaper/contents/screenshot.png"
dimensions="$(identify -ping -format '%wx%h' "$wallpaperImage")"
magick "$wallpaperImage" "$wallpaper/contents/images/$dimensions.png"
''
else
""
}
write_text \
"$colorscheme" \
Expand Down Expand Up @@ -264,11 +271,18 @@ let
return 1
}
if wallpaper_image="$(global_path plasma-apply-wallpaperimage)"; then
"$wallpaper_image" "${themePackage}/share/wallpapers/stylix"
else
echo "Skipping plasma-apply-wallpaperimage: command not found"
fi
${
if (config.stylix.image != null) then
''
if wallpaper_image="$(global_path plasma-apply-wallpaperimage)"; then
"$wallpaper_image" "${themePackage}/share/wallpapers/stylix"
else
echo "Skipping plasma-apply-wallpaperimage: command not found"
fi
''
else
""
}
if look_and_feel="$(global_path plasma-apply-lookandfeel)"; then
"$look_and_feel" --apply stylix
Expand Down
10 changes: 7 additions & 3 deletions modules/lightdm/nixos.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
{ 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.enable
&& config.stylix.targets.lightdm.enable
&& config.stylix.targets.lightdm.wallpaper
) config.stylix.image;
}
8 changes: 5 additions & 3 deletions modules/regreet/nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
}:

{
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
Expand All @@ -32,7 +34,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 config.stylix.targets.regreet.wallpaper {
path = config.stylix.image;
fit =
let
Expand Down
9 changes: 6 additions & 3 deletions modules/sway/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,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) {
Expand Down Expand Up @@ -57,7 +59,8 @@ 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}'';
};
Expand Down
29 changes: 19 additions & 10 deletions modules/swaylock/hm.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
pkgs,
options,
config,
lib,
...
Expand All @@ -18,16 +17,26 @@ let

in
{
imports = [
(lib.mkRenamedOptionModuleWith {
from = [
"stylix"
"targets"
"swaylock"
"useImage"
];
sinceRelease = 2505;
to = [
"stylix"
"targets"
"swaylock"
"wallpaper"
];
})
];
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 =
Expand Down Expand Up @@ -64,7 +73,7 @@ in
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}";
};
};
Expand Down
13 changes: 10 additions & 3 deletions modules/wpaperd/hm.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{ 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)
lib.mkIf
(
config.stylix.enable
&& config.stylix.targets.wpaperd.enable
&& config.stylix.targets.wpaperd.wallpaper
)
(
let
inherit (config.stylix) imageScalingMode;
Expand Down
17 changes: 13 additions & 4 deletions stylix/palette.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
let
cfg = config.stylix;

paletteJSON =
paletteJSON = lib.mkIf (cfg.image != null) (
let
generatedJSON = pkgs.runCommand "palette.json" { } ''
${palette-generator}/bin/palette-generator \
Expand All @@ -24,7 +24,8 @@ let
extension = ".json";
};
in
json;
json
);
generatedScheme = lib.importJSON paletteJSON;

in
Expand All @@ -47,13 +48,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 {
Expand Down Expand Up @@ -123,7 +125,7 @@ in
lines
attrs
];
default = generatedScheme;
default = lib.mkIf (cfg.image != null) generatedScheme;
defaultText = lib.literalMD ''
The colors used in the theming.
Expand Down Expand Up @@ -151,6 +153,13 @@ in
lib.stylix.colors = (base16.mkSchemeAttrs cfg.base16Scheme).override cfg.override;
lib.stylix.scheme = base16.mkSchemeAttrs cfg.base16Scheme;

assertions = [
{
assertion = cfg.image != null || cfg.base16Scheme != null;
message = "One of `stylix.image` or `stylix.base16Scheme` must be set";
}
];

stylix.generated.fileTree = {
# Making palette.json part of the system closure will protect it from
# garbage collection, so future configurations can be evaluated without
Expand Down
Loading

0 comments on commit 833cbbd

Please sign in to comment.