mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 11:36:05 +01:00
This commit converts `package = mkOption` declarations throughout the
codebase to use the more modern and consistent `lib.mkPackageOption`
function.
Key changes:
- Simple package options: `mkOption { type = types.package; default = pkgs.foo; }`
becomes `lib.mkPackageOption pkgs "foo" { }`
- Package set options: Uses correct package set as first argument with
`pkgsText` parameter (e.g., `lib.mkPackageOption pkgs.vimPlugins "plugin" { pkgsText = "pkgs.vimPlugins"; }`)
- Removes redundant descriptions that just restate the package name
- Preserves examples and extra context where meaningful
- Handles submodule plugin options properly with `null` defaults
This modernizes the option declarations and makes them more consistent
with current nixpkgs patterns while maintaining full backward compatibility.
Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
112 lines
2.7 KiB
Nix
112 lines
2.7 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
inherit (lib) mkEnableOption mkOption types;
|
|
|
|
cfg = config.services.mpdris2;
|
|
|
|
toIni = lib.generators.toINI {
|
|
mkKeyValue =
|
|
key: value:
|
|
let
|
|
value' = if lib.isBool value then (if value then "True" else "False") else toString value;
|
|
in
|
|
"${key} = ${value'}";
|
|
};
|
|
|
|
mpdris2Conf = {
|
|
Connection =
|
|
{
|
|
host = cfg.mpd.host;
|
|
port = cfg.mpd.port;
|
|
music_dir = cfg.mpd.musicDirectory;
|
|
}
|
|
// lib.optionalAttrs (cfg.mpd.password != null) {
|
|
password = cfg.mpd.password;
|
|
};
|
|
|
|
Bling = {
|
|
notify = cfg.notifications;
|
|
mmkeys = cfg.multimediaKeys;
|
|
};
|
|
};
|
|
|
|
in
|
|
{
|
|
meta.maintainers = [ lib.maintainers.pjones ];
|
|
|
|
options.services.mpdris2 = {
|
|
enable = mkEnableOption "mpDris2 the MPD to MPRIS2 bridge";
|
|
notifications = mkEnableOption "song change notifications";
|
|
multimediaKeys = mkEnableOption "multimedia key support";
|
|
|
|
package = lib.mkPackageOption pkgs "mpdris2" { };
|
|
|
|
mpd = {
|
|
host = mkOption {
|
|
type = types.str;
|
|
default = config.services.mpd.network.listenAddress;
|
|
defaultText = "config.services.mpd.network.listenAddress";
|
|
example = "192.168.1.1";
|
|
description = "The address where MPD is listening for connections.";
|
|
};
|
|
|
|
port = mkOption {
|
|
type = types.port;
|
|
default = config.services.mpd.network.port;
|
|
defaultText = "config.services.mpd.network.port";
|
|
description = ''
|
|
The port number where MPD is listening for connections.
|
|
'';
|
|
};
|
|
|
|
musicDirectory = mkOption {
|
|
type = types.nullOr types.path;
|
|
default = config.services.mpd.musicDirectory;
|
|
defaultText = "config.services.mpd.musicDirectory";
|
|
description = ''
|
|
If set, mpDris2 will use this directory to access music artwork.
|
|
'';
|
|
};
|
|
|
|
password = mkOption {
|
|
type = types.nullOr types.str;
|
|
default = null;
|
|
description = ''
|
|
The password to connect to MPD.
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
assertions = [
|
|
(lib.hm.assertions.assertPlatform "services.mpdris2" pkgs lib.platforms.linux)
|
|
];
|
|
|
|
xdg.configFile."mpDris2/mpDris2.conf".text = toIni mpdris2Conf;
|
|
|
|
systemd.user.services.mpdris2 = {
|
|
Install = {
|
|
WantedBy = [ "default.target" ];
|
|
};
|
|
|
|
Unit = {
|
|
Description = "MPRIS 2 support for MPD";
|
|
After = [ "mpd.service" ];
|
|
};
|
|
|
|
Service = {
|
|
Type = "simple";
|
|
Restart = "on-failure";
|
|
RestartSec = "5s";
|
|
ExecStart = "${cfg.package}/bin/mpDris2";
|
|
BusName = "org.mpris.MediaPlayer2.mpd";
|
|
};
|
|
};
|
|
};
|
|
}
|