From 4fed3712b00ba05d04320fd1b597ba12324a1014 Mon Sep 17 00:00:00 2001 From: Jan-Bulthuis Date: Thu, 27 Feb 2025 11:13:47 +0100 Subject: [PATCH] Added background module for themed backgrounds --- user-modules/desktop/theming/background.nix | 119 ++++++++++++++++++++ user-modules/desktop/theming/default.nix | 2 + 2 files changed, 121 insertions(+) create mode 100644 user-modules/desktop/theming/background.nix diff --git a/user-modules/desktop/theming/background.nix b/user-modules/desktop/theming/background.nix new file mode 100644 index 0000000..ff8df97 --- /dev/null +++ b/user-modules/desktop/theming/background.nix @@ -0,0 +1,119 @@ +{ + config, + pkgs, + lib, + ... +}: + +with lib; +let + cfg = config.desktop.theming.background; +in +{ + options.desktop.theming.background = { + path = mkOption { + type = types.str; + # default = "minimal/a_cat_in_a_cup.png"; + default = "minimal/a_flower_on_a_dark_background.png"; + description = "Path to the background image."; + }; + themed = mkEnableOption "themed background"; + invert = mkEnableOption "invert background"; + src = mkOption { + default = pkgs.fetchFromGitHub { + owner = "dharmx"; + repo = "walls"; + rev = "6bf4d733ebf2b484a37c17d742eb47e5139e6a14"; + sha256 = "sha256-M96jJy3L0a+VkJ+DcbtrRAquwDWaIG9hAUxenr/TcQU="; + }; + }; + }; + + config = + with pkgs; + let + theme = writeTextFile { + name = "gowall-theme"; + text = builtins.toJSON { + name = "NixOS"; + colors = + let + colors = config.desktop.theming.schemeColors; + in + [ + "#${colors.base00}" + "#${colors.base01}" + "#${colors.base02}" + "#${colors.base03}" + "#${colors.base04}" + "#${colors.base05}" + "#${colors.base06}" + "#${colors.base07}" + "#${colors.base08}" + "#${colors.base09}" + "#${colors.base0A}" + "#${colors.base0B}" + "#${colors.base0C}" + "#${colors.base0D}" + "#${colors.base0E}" + "#${colors.base0F}" + ]; + }; + executable = true; + }; + + background-themed = stdenv.mkDerivation { + name = "background-themed-1.0.0"; + src = cfg.src; + + buildInputs = [ + gowall + imagemagick + (writeShellScriptBin "xdg-open" "") + ]; + + buildPhase = + if cfg.themed then + if cfg.invert then + '' + cp ${theme} ./theme.json + + export HOME=$PWD + convert ./${cfg.path} -channel RGB -negate ./${cfg.path} + + gowall convert ./${cfg.path} -o themed -t ./theme.json + mv Pictures/gowall/themed.* ./ + mogrify -format png themed.* + '' + else + '' + cp ${theme} ./theme.json + + export HOME=$PWD + + gowall convert ./${cfg.path} -o themed -t ./theme.json + mv Pictures/gowall/themed.* ./ + mogrify -format png themed.* + '' + else + '' + cp ${cfg.path} ./themed + + mogrify -format png themed + ''; + + installPhase = '' + install -Dm644 -t $out themed.png + ''; + }; + in + { + programs.wpaperd = { + enable = true; + settings.default = { + path = "${background-themed}/"; + mode = "center"; + }; + }; + }; +} diff --git a/user-modules/desktop/theming/default.nix b/user-modules/desktop/theming/default.nix index 56950ea..640933c 100644 --- a/user-modules/desktop/theming/default.nix +++ b/user-modules/desktop/theming/default.nix @@ -90,6 +90,8 @@ let in { imports = [ + ./background.nix + # Import all themes ./themes/catppuccin.nix ./themes/gruvbox.nix