1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.spotifyd;
7 toml = pkgs.formats.toml {};
8 warnConfig =
9 if cfg.config != ""
10 then lib.trace "Using the stringly typed .config attribute is discouraged. Use the TOML typed .settings attribute instead."
11 else id;
12 spotifydConf =
13 if cfg.settings != {}
14 then toml.generate "spotify.conf" cfg.settings
15 else warnConfig (pkgs.writeText "spotifyd.conf" cfg.config);
16in
17{
18 options = {
19 services.spotifyd = {
20 enable = mkEnableOption "spotifyd, a Spotify playing daemon";
21
22 config = mkOption {
23 default = "";
24 type = types.lines;
25 description = ''
26 (Deprecated) Configuration for Spotifyd. For syntax and directives, see
27 <https://docs.spotifyd.rs/config/File.html>.
28 '';
29 };
30
31 settings = mkOption {
32 default = {};
33 type = toml.type;
34 example = { global.bitrate = 320; };
35 description = ''
36 Configuration for Spotifyd. For syntax and directives, see
37 <https://docs.spotifyd.rs/config/File.html>.
38 '';
39 };
40 };
41 };
42
43 config = mkIf cfg.enable {
44 assertions = [
45 {
46 assertion = cfg.config == "" || cfg.settings == {};
47 message = "At most one of the .config attribute and the .settings attribute may be set";
48 }
49 ];
50
51 systemd.services.spotifyd = {
52 wantedBy = [ "multi-user.target" ];
53 wants = [ "network-online.target" ];
54 after = [ "network-online.target" "sound.target" ];
55 description = "spotifyd, a Spotify playing daemon";
56 environment.SHELL = "/bin/sh";
57 serviceConfig = {
58 ExecStart = "${pkgs.spotifyd}/bin/spotifyd --no-daemon --cache-path /var/cache/spotifyd --config-path ${spotifydConf}";
59 Restart = "always";
60 RestartSec = 12;
61 DynamicUser = true;
62 CacheDirectory = "spotifyd";
63 SupplementaryGroups = ["audio"];
64 };
65 };
66 };
67
68 meta.maintainers = [ maintainers.anderslundstedt ];
69}