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