summaryrefslogtreecommitdiff
path: root/modules/services/spotifyd.nix
blob: 2469a2458d2d6f7343370dcf8c718126b78dd155 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.spotifyd;

  format = pkgs.formats.toml { };
  configFile = format.generate "spotifyd.conf" {
    global = {
      backend = "portaudio";
    };
    spotifyd = cfg.settings;
  };
in
{
  options = {
    services.spotifyd = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = lib.mdDoc ''
          Whether to enable the spotifyd service.
        '';
      };

      package = mkOption {
        type = types.path;
        default = pkgs.spotifyd;
        defaultText = "pkgs.spotifyd";
        description = lib.mdDoc ''
          The spotifyd package to use.
        '';
      };

      settings = mkOption {
        type = types.nullOr format.type;
        default = null;
        example = {
          bitrate = 160;
          volume_normalisation = true;
        };
        description = lib.mdDoc ''
          Configuration for spotifyd, see <https://spotifyd.github.io/spotifyd/config/File.html>
          for supported values.
        '';
      };
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = [ cfg.package ];
    launchd.user.agents.spotifyd = {
      serviceConfig.ProgramArguments = [ "${cfg.package}/bin/spotifyd" "--no-daemon" ]
        ++ optionals (cfg.settings != null) [ "--config-path=${configFile}" ];
      serviceConfig = {
        KeepAlive = true;
        RunAtLoad = true;
        ThrottleInterval = 30;
      };
    };
  };
}