fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Erwin Boskmampdris2: remove assertion on mpd module9042c756

master
2.8 KiB111 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.services.mpdris2;
8
9  toIni = generators.toINI {
10    mkKeyValue = key: value:
11      let
12        value' = if isBool value then
13          (if value then "True" else "False")
14        else
15          toString value;
16      in "${key} = ${value'}";
17  };
18
19  mpdris2Conf = {
20    Connection = {
21      host = cfg.mpd.host;
22      port = cfg.mpd.port;
23      music_dir = cfg.mpd.musicDirectory;
24    } // optionalAttrs (cfg.mpd.password != null) {
25      password = cfg.mpd.password;
26    };
27
28    Bling = {
29      notify = cfg.notifications;
30      mmkeys = cfg.multimediaKeys;
31    };
32  };
33
34in {
35  meta.maintainers = [ maintainers.pjones ];
36
37  options.services.mpdris2 = {
38    enable = mkEnableOption "mpDris2 the MPD to MPRIS2 bridge";
39    notifications = mkEnableOption "song change notifications";
40    multimediaKeys = mkEnableOption "multimedia key support";
41
42    package = mkOption {
43      type = types.package;
44      default = pkgs.mpdris2;
45      defaultText = literalExpression "pkgs.mpdris2";
46      description = "The mpDris2 package to use.";
47    };
48
49    mpd = {
50      host = mkOption {
51        type = types.str;
52        default = config.services.mpd.network.listenAddress;
53        defaultText = "config.services.mpd.network.listenAddress";
54        example = "192.168.1.1";
55        description = "The address where MPD is listening for connections.";
56      };
57
58      port = mkOption {
59        type = types.port;
60        default = config.services.mpd.network.port;
61        defaultText = "config.services.mpd.network.port";
62        description = ''
63          The port number where MPD is listening for connections.
64        '';
65      };
66
67      musicDirectory = mkOption {
68        type = types.nullOr types.path;
69        default = config.services.mpd.musicDirectory;
70        defaultText = "config.services.mpd.musicDirectory";
71        description = ''
72          If set, mpDris2 will use this directory to access music artwork.
73        '';
74      };
75
76      password = mkOption {
77        type = types.nullOr types.str;
78        default = null;
79        description = ''
80          The password to connect to MPD.
81        '';
82      };
83    };
84  };
85
86  config = mkIf cfg.enable {
87    assertions = [
88      (lib.hm.assertions.assertPlatform "services.mpdris2" pkgs
89        lib.platforms.linux)
90    ];
91
92    xdg.configFile."mpDris2/mpDris2.conf".text = toIni mpdris2Conf;
93
94    systemd.user.services.mpdris2 = {
95      Install = { WantedBy = [ "default.target" ]; };
96
97      Unit = {
98        Description = "MPRIS 2 support for MPD";
99        After = [ "mpd.service" ];
100      };
101
102      Service = {
103        Type = "simple";
104        Restart = "on-failure";
105        RestartSec = "5s";
106        ExecStart = "${cfg.package}/bin/mpDris2";
107        BusName = "org.mpris.MediaPlayer2.mpd";
108      };
109    };
110  };
111}