diff --git a/configs/spotifyd.nix b/configs/spotifyd.nix index 0666627..ae4bb28 100644 --- a/configs/spotifyd.nix +++ b/configs/spotifyd.nix @@ -1,8 +1,11 @@ { config, pkgs, lib, ... }: { + imports = [ ]; + disabledModules = [ "services/audio/spotifyd.nix" ]; + services.spotifyd = { enable = true; - config = builtins.readFile ((pkgs.formats.toml {}).generate "spotifyd.toml" { + settings = { global = { username = lib.strings.fileContents ; password = lib.strings.fileContents ; @@ -11,7 +14,7 @@ device_type = "s_t_b"; # set-top box device_name = config.networking.hostName; }; - }); + }; }; # ref https://github.com/NixOS/nixpkgs/issues/71362#issuecomment-753461502 diff --git a/modules/spotifyd.nix b/modules/spotifyd.nix new file mode 100644 index 0000000..cfffc8c --- /dev/null +++ b/modules/spotifyd.nix @@ -0,0 +1,60 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.spotifyd; + toml = pkgs.formats.toml {}; + spotifydConf = if cfg.settings != {} then toml.generate "spotify.conf" cfg.settings else pkgs.writeText "spotifyd.conf" cfg.config; +in +{ + options = { + services.spotifyd = { + enable = mkEnableOption "spotifyd, a Spotify playing daemon"; + + config = mkOption { + default = ""; + type = types.lines; + description = '' + (Deprecated) Configuration for Spotifyd. For syntax and directives, see + . + ''; + }; + + settings = mkOption { + default = {}; + type = toml.type; + description = '' + Configuration for Spotifyd. For syntax and directives, see + . + ''; + }; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + { + assertion = (cfg.config == "" && cfg.settings != {}) || (cfg.config != "" && cfg.settings == {}); + message = "Using the stringly typed .config attribute is discouraged. Use the TOML typed .settings attribute instead."; + } + ]; + + systemd.services.spotifyd = { + wantedBy = [ "multi-user.target" ]; + after = [ "network-online.target" "sound.target" ]; + description = "spotifyd, a Spotify playing daemon"; + environment.SHELL = "/bin/sh"; + serviceConfig = { + ExecStart = "${pkgs.spotifyd}/bin/spotifyd --no-daemon --cache-path /var/cache/spotifyd --config-path ${spotifydConf}"; + Restart = "always"; + RestartSec = 12; + DynamicUser = true; + CacheDirectory = "spotifyd"; + SupplementaryGroups = ["audio"]; + }; + }; + }; + + meta.maintainers = [ maintainers.anderslundstedt ]; +}