diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 92d3e9f54..eb964972f 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1584,6 +1584,18 @@ in { https://conky.cc/ for more. ''; } + + { + time = "2024-04-29T19:23:09+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.hyprpaper'. + + Hyprpaper is a blazing fast wallpaper utility for Hyprland with the ability to + dynamically change wallpapers through sockets. It will work on all wlroots-based + compositors, though. See https://github.com/hyprwm/hyprpaper for more. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 7c81102a9..4c0746402 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -302,6 +302,7 @@ let ./services/gromit-mpx.nix ./services/home-manager-auto-upgrade.nix ./services/hound.nix + ./services/hyprpaper.nix ./services/imapnotify.nix ./services/kanshi.nix ./services/kbfs.nix diff --git a/modules/services/hyprpaper.nix b/modules/services/hyprpaper.nix new file mode 100644 index 000000000..5b3b8b9fa --- /dev/null +++ b/modules/services/hyprpaper.nix @@ -0,0 +1,95 @@ +{ config, lib, pkgs, ... }: +with lib; +let + + cfg = config.services.hyprpaper; +in { + meta.maintainers = [ maintainers.khaneliman maintainers.fufexan ]; + + options.services.hyprpaper = { + enable = mkEnableOption "Hyprpaper, Hyprland's wallpaper daemon"; + + package = mkPackageOption pkgs "hyprpaper" { }; + + settings = lib.mkOption { + type = with lib.types; + let + valueType = nullOr (oneOf [ + bool + int + float + str + path + (attrsOf valueType) + (listOf valueType) + ]) // { + description = "Hyprpaper configuration value"; + }; + in valueType; + default = { }; + description = '' + hyprpaper configuration written in Nix. Entries with the same key + should be written as lists. Variables' and colors' names should be + quoted. See for more examples. + ''; + example = lib.literalExpression '' + { + general = { + after_sleep_cmd = "hyprctl dispatch dpms on"; + ignore_dbus_inhibit = false; + lock_cmd = "hyprlock"; + }; + + listener = [ + { + timeout = 900; + on-timeout = "hyprlock"; + } + { + timeout = 1200; + on-timeout = "hyprctl dispatch dpms off"; + on-resume = "hyprctl dispatch dpms on"; + } + ]; + } + ''; + }; + + importantPrefixes = lib.mkOption { + type = with lib.types; listOf str; + default = [ "$" ]; + example = [ "$" ]; + description = '' + List of prefix of attributes to source at the top of the config. + ''; + }; + }; + + config = mkIf cfg.enable { + xdg.configFile."hypr/hyprpaper.conf" = mkIf (cfg.settings != { }) { + text = lib.hm.generators.toHyprconf { + attrs = cfg.settings; + inherit (cfg) importantPrefixes; + }; + }; + + systemd.user.services.hyprpaper = { + Install = { WantedBy = [ "graphical-session.target" ]; }; + + Unit = { + ConditionEnvironment = "WAYLAND_DISPLAY"; + Description = "hyprpaper"; + After = [ "graphical-session-pre.target" ]; + PartOf = [ "graphical-session.target" ]; + X-Restart-Triggers = + [ "${config.xdg.configFile."hypr/hyprpaper.conf".source}" ]; + }; + + Service = { + ExecStart = "${getExe cfg.package}"; + Restart = "always"; + RestartSec = "10"; + }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 7b714581d..360ec3b3f 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -239,6 +239,7 @@ in import nmtSrc { ./modules/services/gpg-agent ./modules/services/gromit-mpx ./modules/services/home-manager-auto-upgrade + ./modules/services/hyprpaper ./modules/services/imapnotify ./modules/services/kanshi ./modules/services/lieer diff --git a/tests/modules/services/hyprpaper/basic-configuration.nix b/tests/modules/services/hyprpaper/basic-configuration.nix new file mode 100644 index 000000000..846921fa9 --- /dev/null +++ b/tests/modules/services/hyprpaper/basic-configuration.nix @@ -0,0 +1,30 @@ +{ pkgs, ... }: { + services.hyprpaper = { + enable = true; + package = pkgs.hyprpaper; + + settings = { + ipc = "on"; + splash = false; + splash_offset = 2.0; + + preload = + [ "/share/wallpapers/buttons.png" "/share/wallpapers/cat_pacman.png" ]; + + wallpaper = [ + "DP-3,/share/wallpapers/buttons.png" + "DP-1,/share/wallpapers/cat_pacman.png" + ]; + }; + }; + + test.stubs.hyprpaper = { }; + + nmt.script = '' + config=home-files/.config/hypr/hyprpaper.conf + clientServiceFile=home-files/.config/systemd/user/hyprpaper.service + assertFileExists $config + assertFileExists $clientServiceFile + assertFileContent $config ${./hyprpaper.conf} + ''; +} diff --git a/tests/modules/services/hyprpaper/default.nix b/tests/modules/services/hyprpaper/default.nix new file mode 100644 index 000000000..2a5abbfed --- /dev/null +++ b/tests/modules/services/hyprpaper/default.nix @@ -0,0 +1 @@ +{ hyprpaper-basic-configuration = ./basic-configuration.nix; } diff --git a/tests/modules/services/hyprpaper/hyprpaper.conf b/tests/modules/services/hyprpaper/hyprpaper.conf new file mode 100644 index 000000000..d7b4ccb4f --- /dev/null +++ b/tests/modules/services/hyprpaper/hyprpaper.conf @@ -0,0 +1,7 @@ +ipc=on +preload=/share/wallpapers/buttons.png +preload=/share/wallpapers/cat_pacman.png +splash=false +splash_offset=2.000000 +wallpaper=DP-3,/share/wallpapers/buttons.png +wallpaper=DP-1,/share/wallpapers/cat_pacman.png