1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-05 02:39:45 +01:00
home-manager/modules/services/mpd-mpris.nix
Emily 36a53d9f26 treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]. All
conversions were automatically checked to produce the same DocBook
result when converted back, modulo minor typographical/formatting
differences on the acceptable-to-desirable spectrum.

To reproduce this commit, run:

  $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \
    nix shell nixpkgs#coreutils \
    -c find . -name '*.nix' \
    -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \
    {} +
  $ ./format

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
2023-07-17 18:40:56 +01:00

111 lines
3.1 KiB
Nix

{ 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
(lib.mdDoc "mpd-mpris: An implementation of the MPRIS protocol for MPD");
package = lib.mkPackageOptionMD pkgs "mpd-mpris" { };
mpd = {
useLocal = lib.mkOption {
type = lib.types.bool;
default = config.services.mpd.enable;
defaultText = lib.literalExpression "config.services.mpd.enable";
description = lib.mdDoc ''
Whether to configure for the local MPD daemon. If
`true` the `network`,
`host`, and `port`
settings are ignored.
'';
};
network = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = lib.mdDoc ''
The network used to dial to the MPD server. Check
<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 =
lib.mdDoc "The address where MPD is listening for connections.";
};
port = lib.mkOption {
type = with lib.types; nullOr port;
default = null;
description = lib.mdDoc ''
The port number where MPD is listening for connections.
'';
};
password = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
description = lib.mdDoc ''
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;
};
};
};
};
}