From b25b9b7d352b72343b7cd93e122aca163f84db64 Mon Sep 17 00:00:00 2001 From: ckgxrg Date: Sat, 25 Jan 2025 11:15:27 +0800 Subject: [PATCH] linux-wallpaperengine: add module linux-wallpaperengine is an implementation of Wallpaper Engine on Linux, this module allows it to be declaractively configured. --- modules/modules.nix | 1 + modules/services/linux-wallpaperengine.nix | 121 ++++++++++++++++++ tests/default.nix | 1 + .../basic-configuration-expected.service | 11 ++ .../basic-configuration.nix | 35 +++++ .../linux-wallpaperengine/default.nix | 1 + 6 files changed, 170 insertions(+) create mode 100644 modules/services/linux-wallpaperengine.nix create mode 100644 tests/modules/services/linux-wallpaperengine/basic-configuration-expected.service create mode 100644 tests/modules/services/linux-wallpaperengine/basic-configuration.nix create mode 100644 tests/modules/services/linux-wallpaperengine/default.nix diff --git a/modules/modules.nix b/modules/modules.nix index d20300d1a..c6a02cf2d 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -330,6 +330,7 @@ let ./services/keybase.nix ./services/keynav.nix ./services/lieer.nix + ./services/linux-wallpaperengine.nix ./services/listenbrainz-mpd.nix ./services/lorri.nix ./services/mako.nix diff --git a/modules/services/linux-wallpaperengine.nix b/modules/services/linux-wallpaperengine.nix new file mode 100644 index 000000000..c618d1ac6 --- /dev/null +++ b/modules/services/linux-wallpaperengine.nix @@ -0,0 +1,121 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.linux-wallpaperengine; + +in { + meta.maintainers = [ hm.maintainers.ckgxrg ]; + + options.services.linux-wallpaperengine = { + enable = mkEnableOption + "linux-wallpaperengine, an implementation of Wallpaper Engine functionality"; + + package = mkPackageOption pkgs "linux-wallpaperengine" { }; + + assetsPath = mkOption { + type = types.path; + description = "Path to the assets directory."; + }; + + clamping = mkOption { + type = types.nullOr (types.enum [ "clamp" "border" "repeat" ]); + default = null; + description = "Clamping mode for all wallpapers."; + }; + + wallpapers = mkOption { + type = types.listOf (types.submodule { + options = { + monitor = mkOption { + type = types.str; + description = "Which monitor to display the wallpaper."; + }; + + wallpaperId = mkOption { + type = types.str; + description = "Wallpaper ID to be used."; + }; + + extraOptions = mkOption { + type = types.listOf types.str; + default = [ ]; + description = + "Extra arguments to pass to the linux-wallpaperengine command for this wallpaper."; + }; + + scaling = mkOption { + type = + types.nullOr (types.enum [ "stretch" "fit" "fill" "default" ]); + default = null; + description = "Scaling mode for this wallpaper."; + }; + + fps = mkOption { + type = types.nullOr types.int; + default = null; + description = "Limits the FPS to a given number."; + }; + + audio = { + silent = mkOption { + type = types.bool; + default = false; + description = "Mutes all sound of the wallpaper."; + }; + + automute = mkOption { + type = types.bool; + default = true; + description = "Automute when another app is playing sound."; + }; + + audio-processing = mkOption { + type = types.bool; + default = true; + description = "Enables audio processing for background."; + }; + }; + }; + }); + default = [ ]; + description = "Define wallpapers."; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + (lib.hm.assertions.assertPlatform "services.linux-wallpaperengine" pkgs + lib.platforms.linux) + ]; + + home.packages = [ cfg.package ]; + + systemd.user.services."linux-wallpaperengine" = let + args = lists.forEach cfg.wallpapers (each: + concatStringsSep " " (cli.toGNUCommandLine { } { + screen-root = each.monitor; + inherit (each) scaling fps; + silent = each.audio.silent; + noautomute = !each.audio.automute; + no-audio-processing = !each.audio.audio-processing; + } ++ each.extraOptions) + # This has to be the last argument in each group + + " --bg ${each.wallpaperId}"); + in { + Unit = { + Description = "Implementation of Wallpaper Engine on Linux"; + After = [ "graphical-session.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + Service = { + ExecStart = getExe cfg.package + " --assets-dir ${cfg.assetsPath} " + + "--clamping ${cfg.clamping} " + (strings.concatStringsSep " " args); + Restart = "on-failure"; + }; + Install = { WantedBy = [ "graphical-session.target" ]; }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index f7778e445..1675cc761 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -266,6 +266,7 @@ in import nmtSrc { ./modules/services/imapnotify ./modules/services/kanshi ./modules/services/lieer + ./modules/services/linux-wallpaperengine ./modules/services/mopidy ./modules/services/mpd ./modules/services/mpd-mpris diff --git a/tests/modules/services/linux-wallpaperengine/basic-configuration-expected.service b/tests/modules/services/linux-wallpaperengine/basic-configuration-expected.service new file mode 100644 index 000000000..8aefc0582 --- /dev/null +++ b/tests/modules/services/linux-wallpaperengine/basic-configuration-expected.service @@ -0,0 +1,11 @@ +[Install] +WantedBy=graphical-session.target + +[Service] +ExecStart=@linux-wallpaperengine@/bin/dummy --assets-dir /some/path/to/assets --clamping border --fps 6 --scaling fit --screen-root HDMI-1 --bg 12345678 --no-audio-processing --noautomute --screen-root DP-1 --silent --scaling fill --fps 12 --bg 87654321 +Restart=on-failure + +[Unit] +After=graphical-session.target +Description=Implementation of Wallpaper Engine on Linux +PartOf=graphical-session.target diff --git a/tests/modules/services/linux-wallpaperengine/basic-configuration.nix b/tests/modules/services/linux-wallpaperengine/basic-configuration.nix new file mode 100644 index 000000000..10aef1b51 --- /dev/null +++ b/tests/modules/services/linux-wallpaperengine/basic-configuration.nix @@ -0,0 +1,35 @@ +{ config, pkgs, ... }: + +{ + services.linux-wallpaperengine = { + enable = true; + assetsPath = "/some/path/to/assets"; + clamping = "border"; + wallpapers = [ + { + monitor = "HDMI-1"; + wallpaperId = "12345678"; + scaling = "fit"; + fps = 6; + } + { + monitor = "DP-1"; + wallpaperId = "87654321"; + extraOptions = [ "--scaling fill" "--fps 12" ]; + audio = { + silent = true; + automute = false; + audio-processing = false; + }; + } + ]; + }; + + test.stubs.linux-wallpaperengine = { }; + + nmt.script = '' + assertFileContent \ + home-files/.config/systemd/user/linux-wallpaperengine.service \ + ${./basic-configuration-expected.service} + ''; +} diff --git a/tests/modules/services/linux-wallpaperengine/default.nix b/tests/modules/services/linux-wallpaperengine/default.nix new file mode 100644 index 000000000..430aa129d --- /dev/null +++ b/tests/modules/services/linux-wallpaperengine/default.nix @@ -0,0 +1 @@ +{ linux-wallpaperengine-basic-configuration = ./basic-configuration.nix; }