1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-24 20:19:45 +01:00
home-manager/modules/services/mpd-mpris.nix

111 lines
3 KiB
Nix
Raw Normal View History

2022-12-27 18:15:51 +01:00
{ 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";
2022-12-27 18:15:51 +01:00
package = lib.mkPackageOption pkgs "mpd-mpris" { };
2022-12-27 18:15:51 +01:00
mpd = {
useLocal = lib.mkOption {
type = lib.types.bool;
default = config.services.mpd.enable;
defaultText = lib.literalExpression "config.services.mpd.enable";
description = ''
2022-12-27 18:15:51 +01:00
Whether to configure for the local MPD daemon. If
`true` the `network`,
`host`, and `port`
2022-12-27 18:15:51 +01:00
settings are ignored.
'';
};
network = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = ''
2022-12-27 18:15:51 +01:00
The network used to dial to the MPD server. Check
<https://golang.org/pkg/net/#Dial>
2022-12-27 18:15:51 +01:00
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.";
2022-12-27 18:15:51 +01:00
};
port = lib.mkOption {
type = with lib.types; nullOr port;
default = null;
description = ''
2022-12-27 18:15:51 +01:00
The port number where MPD is listening for connections.
'';
};
password = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = ''
2022-12-27 18:15:51 +01:00
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;
};
};
};
};
}