From df7d81b0b322c793f1b0e99f7a1e14d91b5312fb Mon Sep 17 00:00:00 2001 From: Sara Johnsson <46252070+Fendse@users.noreply.github.com> Date: Sat, 30 Jan 2021 18:20:36 +0100 Subject: [PATCH] playerctld: add module --- .github/CODEOWNERS | 3 ++ modules/lib/maintainers.nix | 6 ++++ modules/misc/news.nix | 8 +++++ modules/modules.nix | 1 + modules/services/playerctld.nix | 36 +++++++++++++++++++ tests/default.nix | 1 + tests/modules/services/playerctld/basic.nix | 31 ++++++++++++++++ tests/modules/services/playerctld/default.nix | 1 + 8 files changed, 87 insertions(+) create mode 100644 modules/services/playerctld.nix create mode 100644 tests/modules/services/playerctld/basic.nix create mode 100644 tests/modules/services/playerctld/default.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a1b6c8718..f4eba15f3 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -209,6 +209,9 @@ /modules/services/plan9port.nix @ehmry +/modules/services/playerctld.nix @fendse +/tests/modules/playerctld @fendse + /modules/services/pulseeffects.nix @jonringer /modules/services/random-background.nix @rycee diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 680549cf2..3282df9f9 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -53,4 +53,10 @@ github = "thiagokokada"; githubId = 844343; }; + fendse = { + email = "46252070+Fendse@users.noreply.github.com"; + github = "Fendse"; + githubId = 46252070; + name = "Sara Johnsson"; + }; } diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 338282cec..f24e64d9f 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1814,6 +1814,14 @@ in A new module is available: 'services.plan9port'. ''; } + + { + time = "2021-01-31T11:23:30+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.playerctld'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 0abec5be2..a96f90a95 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -175,6 +175,7 @@ let (loadModule ./services/pbgopy.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/picom.nix { }) (loadModule ./services/plan9port.nix { condition = hostPlatform.isLinux; }) + (loadModule ./services/playerctld.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/polybar.nix { }) (loadModule ./services/pulseeffects.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/random-background.nix { }) diff --git a/modules/services/playerctld.nix b/modules/services/playerctld.nix new file mode 100644 index 000000000..63e7b8feb --- /dev/null +++ b/modules/services/playerctld.nix @@ -0,0 +1,36 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.playerctld; + +in { + meta.maintainers = [ maintainers.fendse ]; + + options.services.playerctld = { + enable = mkEnableOption "playerctld daemon"; + + package = mkOption { + type = types.package; + default = pkgs.playerctl; + defaultText = literalExample "pkgs.playerctl"; + description = "The playerctl package to use."; + }; + }; + + config = mkIf cfg.enable { + systemd.user.services.playerctld = { + Unit.Description = "MPRIS media player daemon"; + + Install.WantedBy = [ "default.target" ]; + + Service = { + ExecStart = "${cfg.package}/bin/playerctld"; + Type = "dbus"; + BusName = "org.mpris.MediaPlayer2.playerctld"; + }; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index a2691c256..9437f0820 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -102,6 +102,7 @@ import nmt { ./modules/services/lieer ./modules/services/redshift-gammastep ./modules/services/pbgopy + ./modules/services/playerctld ./modules/services/polybar ./modules/services/sxhkd ./modules/services/window-managers/i3 diff --git a/tests/modules/services/playerctld/basic.nix b/tests/modules/services/playerctld/basic.nix new file mode 100644 index 000000000..3c10a99f1 --- /dev/null +++ b/tests/modules/services/playerctld/basic.nix @@ -0,0 +1,31 @@ +{ config, pkgs, ... }: + +{ + config = { + services.playerctld.enable = true; + services.playerctld.package = pkgs.writeScriptBin "playerctld" "" // { + outPath = "@playerctld@"; + }; + + nmt.script = '' + serviceFile=home-files/.config/systemd/user/playerctld.service + + assertFileExists "$serviceFile" + + assertFileContent "$serviceFile" "${ + pkgs.writeText "playerctld-test" '' + [Install] + WantedBy=default.target + + [Service] + BusName=org.mpris.MediaPlayer2.playerctld + ExecStart=@playerctld@/bin/playerctld + Type=dbus + + [Unit] + Description=MPRIS media player daemon + '' + }" + ''; + }; +} diff --git a/tests/modules/services/playerctld/default.nix b/tests/modules/services/playerctld/default.nix new file mode 100644 index 000000000..93ed10aaf --- /dev/null +++ b/tests/modules/services/playerctld/default.nix @@ -0,0 +1 @@ +{ playerctld-basic = ./basic.nix; }