mirror of
https://github.com/nix-community/home-manager
synced 2024-12-24 18:59:47 +01:00
mpd-mpris: add module
This commit is contained in:
parent
72ce74d3ea
commit
5e889b385c
12 changed files with 212 additions and 0 deletions
3
.github/CODEOWNERS
vendored
3
.github/CODEOWNERS
vendored
|
@ -447,6 +447,9 @@ Makefile @thiagokokada
|
||||||
|
|
||||||
/modules/services/mpdris2.nix @pjones
|
/modules/services/mpdris2.nix @pjones
|
||||||
|
|
||||||
|
/modules/services/mpd-mpris.nix @olmokramer
|
||||||
|
/tests/modules/services/mpd-mpris @olmokramer
|
||||||
|
|
||||||
/modules/services/mpd-discord-rpc.nix @Kranzes
|
/modules/services/mpd-discord-rpc.nix @Kranzes
|
||||||
|
|
||||||
/modules/services/mpris-proxy.nix @ThibautMarty
|
/modules/services/mpris-proxy.nix @ThibautMarty
|
||||||
|
|
|
@ -915,6 +915,14 @@ in
|
||||||
A new module is available: 'services.autorandr'.
|
A new module is available: 'services.autorandr'.
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
time = "2023-02-20T22:31:23+00:00";
|
||||||
|
condition = hostPlatform.isLinux;
|
||||||
|
message = ''
|
||||||
|
A new module is available: 'services.mpd-mpris'.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,6 +250,7 @@ let
|
||||||
./services/mpd.nix
|
./services/mpd.nix
|
||||||
./services/mpdris2.nix
|
./services/mpdris2.nix
|
||||||
./services/mpd-discord-rpc.nix
|
./services/mpd-discord-rpc.nix
|
||||||
|
./services/mpd-mpris.nix
|
||||||
./services/mpris-proxy.nix
|
./services/mpris-proxy.nix
|
||||||
./services/muchsync.nix
|
./services/muchsync.nix
|
||||||
./services/network-manager-applet.nix
|
./services/network-manager-applet.nix
|
||||||
|
|
110
modules/services/mpd-mpris.nix
Normal file
110
modules/services/mpd-mpris.nix
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
{ config, lib, pkgs, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.services.mpd-mpris;
|
||||||
|
|
||||||
|
ignoreIfLocalMpd = value: if cfg.mpd.useLocal then null else value;
|
||||||
|
|
||||||
|
renderArg = name: value:
|
||||||
|
if lib.isBool value && value then
|
||||||
|
"-${name}"
|
||||||
|
else if lib.isInt value then
|
||||||
|
"-${name} ${toString value}"
|
||||||
|
else if lib.isString value then
|
||||||
|
"-${name} ${lib.escapeShellArg value}"
|
||||||
|
else
|
||||||
|
"";
|
||||||
|
|
||||||
|
concatArgs = strings:
|
||||||
|
lib.concatStringsSep " " (lib.filter (s: s != "") strings);
|
||||||
|
|
||||||
|
renderArgs = args: concatArgs (lib.mapAttrsToList renderArg args);
|
||||||
|
|
||||||
|
renderCmd = pkg: args: "${pkg}/bin/mpd-mpris ${renderArgs args}";
|
||||||
|
in {
|
||||||
|
meta.maintainers = [ lib.hm.maintainers.olmokramer ];
|
||||||
|
|
||||||
|
options.services.mpd-mpris = {
|
||||||
|
enable = lib.mkEnableOption
|
||||||
|
"mpd-mpris: An implementation of the MPRIS protocol for MPD";
|
||||||
|
|
||||||
|
package = lib.mkPackageOption pkgs "mpd-mpris" { };
|
||||||
|
|
||||||
|
mpd = {
|
||||||
|
useLocal = lib.mkOption {
|
||||||
|
type = lib.types.bool;
|
||||||
|
default = config.services.mpd.enable;
|
||||||
|
defaultText = lib.literalExpression "config.services.mpd.enable";
|
||||||
|
description = ''
|
||||||
|
Whether to configure for the local MPD daemon. If
|
||||||
|
<literal>true</literal> the <literal>network</literal>,
|
||||||
|
<literal>host</literal>, and <literal>port</literal>
|
||||||
|
settings are ignored.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
network = lib.mkOption {
|
||||||
|
type = with lib.types; nullOr str;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
The network used to dial to the MPD server. Check
|
||||||
|
<link xlink:href="https://golang.org/pkg/net/#Dial" />
|
||||||
|
for available values (most common are "tcp" and "unix")
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
host = lib.mkOption {
|
||||||
|
type = with lib.types; nullOr str;
|
||||||
|
default = null;
|
||||||
|
example = "192.168.1.1";
|
||||||
|
description = "The address where MPD is listening for connections.";
|
||||||
|
};
|
||||||
|
|
||||||
|
port = lib.mkOption {
|
||||||
|
type = with lib.types; nullOr port;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
The port number where MPD is listening for connections.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
password = lib.mkOption {
|
||||||
|
type = with lib.types; nullOr str;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
The password to connect to MPD.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
assertions = [
|
||||||
|
(lib.hm.assertions.assertPlatform "services.mpd-mpris" pkgs
|
||||||
|
lib.platforms.linux)
|
||||||
|
];
|
||||||
|
|
||||||
|
systemd.user.services.mpd-mpris = {
|
||||||
|
Install = { WantedBy = [ "default.target" ]; };
|
||||||
|
|
||||||
|
Unit = {
|
||||||
|
Description =
|
||||||
|
"mpd-mpris: An implementation of the MPRIS protocol for MPD";
|
||||||
|
After = [ "mpd.service" ];
|
||||||
|
Requires = lib.mkIf cfg.mpd.useLocal [ "mpd.service" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
Service = {
|
||||||
|
Type = "simple";
|
||||||
|
Restart = "on-failure";
|
||||||
|
RestartSec = "5s";
|
||||||
|
ExecStart = renderCmd cfg.package {
|
||||||
|
no-instance = true;
|
||||||
|
network = ignoreIfLocalMpd cfg.mpd.network;
|
||||||
|
host = ignoreIfLocalMpd cfg.mpd.host;
|
||||||
|
port = ignoreIfLocalMpd cfg.mpd.port;
|
||||||
|
pwd = cfg.mpd.password;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -188,6 +188,7 @@ import nmt {
|
||||||
./modules/services/mopidy
|
./modules/services/mopidy
|
||||||
./modules/services/mpd
|
./modules/services/mpd
|
||||||
./modules/services/mpdris2
|
./modules/services/mpdris2
|
||||||
|
./modules/services/mpd-mpris
|
||||||
./modules/services/pantalaimon
|
./modules/services/pantalaimon
|
||||||
./modules/services/parcellite
|
./modules/services/parcellite
|
||||||
./modules/services/pass-secret-service
|
./modules/services/pass-secret-service
|
||||||
|
|
12
tests/modules/services/mpd-mpris/configuration-basic.nix
Normal file
12
tests/modules/services/mpd-mpris/configuration-basic.nix
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
{ ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
services.mpd-mpris = { enable = true; };
|
||||||
|
|
||||||
|
test.stubs.mpd-mpris = { };
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
serviceFile=home-files/.config/systemd/user/mpd-mpris.service
|
||||||
|
assertFileContent "$serviceFile" ${./configuration-basic.service}
|
||||||
|
'';
|
||||||
|
}
|
12
tests/modules/services/mpd-mpris/configuration-basic.service
Normal file
12
tests/modules/services/mpd-mpris/configuration-basic.service
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=@mpd-mpris@/bin/mpd-mpris -no-instance
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5s
|
||||||
|
Type=simple
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
After=mpd.service
|
||||||
|
Description=mpd-mpris: An implementation of the MPRIS protocol for MPD
|
|
@ -0,0 +1,15 @@
|
||||||
|
{ ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
services.mpd-mpris = {
|
||||||
|
enable = true;
|
||||||
|
mpd.useLocal = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
test.stubs.mpd-mpris = { };
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
serviceFile=home-files/.config/systemd/user/mpd-mpris.service
|
||||||
|
assertFileContent "$serviceFile" ${./configuration-with-local-mpd.service}
|
||||||
|
'';
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=@mpd-mpris@/bin/mpd-mpris -no-instance
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5s
|
||||||
|
Type=simple
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
After=mpd.service
|
||||||
|
Description=mpd-mpris: An implementation of the MPRIS protocol for MPD
|
||||||
|
Requires=mpd.service
|
|
@ -0,0 +1,20 @@
|
||||||
|
{ ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
services.mpd-mpris = {
|
||||||
|
enable = true;
|
||||||
|
mpd = {
|
||||||
|
network = "tcp";
|
||||||
|
host = "example.com";
|
||||||
|
port = 1234;
|
||||||
|
password = "my_password";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
test.stubs.mpd-mpris = { };
|
||||||
|
|
||||||
|
nmt.script = ''
|
||||||
|
serviceFile=home-files/.config/systemd/user/mpd-mpris.service
|
||||||
|
assertFileContent "$serviceFile" ${./configuration-with-password.service}
|
||||||
|
'';
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
[Install]
|
||||||
|
WantedBy=default.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=@mpd-mpris@/bin/mpd-mpris -host 'example.com' -network 'tcp' -no-instance -port 1234 -pwd 'my_password'
|
||||||
|
Restart=on-failure
|
||||||
|
RestartSec=5s
|
||||||
|
Type=simple
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
After=mpd.service
|
||||||
|
Description=mpd-mpris: An implementation of the MPRIS protocol for MPD
|
5
tests/modules/services/mpd-mpris/default.nix
Normal file
5
tests/modules/services/mpd-mpris/default.nix
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
mpd-mpris-configuration-basic = ./configuration-basic.nix;
|
||||||
|
mpd-mpris-configuration-with-local-mpd = ./configuration-with-local-mpd.nix;
|
||||||
|
mpd-mpris-configuration-with-password = ./configuration-with-password.nix;
|
||||||
|
}
|
Loading…
Reference in a new issue