at 23.11-pre 2.0 kB view raw
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 (lib.mdDoc "spotifyd, a Spotify playing daemon"); 21 22 config = mkOption { 23 default = ""; 24 type = types.lines; 25 description = lib.mdDoc '' 26 (Deprecated) Configuration for Spotifyd. For syntax and directives, see 27 <https://github.com/Spotifyd/spotifyd#Configuration>. 28 ''; 29 }; 30 31 settings = mkOption { 32 default = {}; 33 type = toml.type; 34 example = { global.bitrate = 320; }; 35 description = lib.mdDoc '' 36 Configuration for Spotifyd. For syntax and directives, see 37 <https://github.com/Spotifyd/spotifyd#Configuration>. 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 after = [ "network-online.target" "sound.target" ]; 54 description = "spotifyd, a Spotify playing daemon"; 55 environment.SHELL = "/bin/sh"; 56 serviceConfig = { 57 ExecStart = "${pkgs.spotifyd}/bin/spotifyd --no-daemon --cache-path /var/cache/spotifyd --config-path ${spotifydConf}"; 58 Restart = "always"; 59 RestartSec = 12; 60 DynamicUser = true; 61 CacheDirectory = "spotifyd"; 62 SupplementaryGroups = ["audio"]; 63 }; 64 }; 65 }; 66 67 meta.maintainers = [ maintainers.anderslundstedt ]; 68}