Skip to content

Commit

Permalink
treewide: optionalize image (except KDE)
Browse files Browse the repository at this point in the history
  • Loading branch information
Flameopathic committed Jan 3, 2025
1 parent f48cab3 commit ce128e9
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 59 deletions.
11 changes: 7 additions & 4 deletions modules/feh/hm.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 7 additions & 4 deletions modules/feh/nixos.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 6 additions & 4 deletions modules/gnome/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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" = {
Expand Down
8 changes: 2 additions & 6 deletions modules/grub/nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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"
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,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})";
Expand Down
8 changes: 5 additions & 3 deletions modules/hyprpaper/hm.nix
Original file line number Diff line number Diff line change
@@ -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}" ];
Expand Down
8 changes: 5 additions & 3 deletions modules/lightdm/nixos.nix
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 5 additions & 2 deletions modules/regreet/nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions modules/sway/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}'';
};
})
Expand Down
11 changes: 2 additions & 9 deletions modules/swaylock/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}";
};
};
Expand Down
7 changes: 5 additions & 2 deletions modules/wpaperd/hm.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 13 additions & 4 deletions stylix/palette.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand All @@ -17,7 +17,7 @@ let
template = ./palette.json.mustache;
extension = ".json";
};
in json;
in json);
generatedScheme = lib.importJSON paletteJSON;

in {
Expand All @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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;

Expand Down
36 changes: 23 additions & 13 deletions stylix/target.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
}
5 changes: 5 additions & 0 deletions stylix/testbed.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ce128e9

Please sign in to comment.