From f3aa13d1411bd5503a4826603596bd1d92a8477a Mon Sep 17 00:00:00 2001 From: Mario Rodas Date: Thu, 11 Mar 2021 04:20:00 +0000 Subject: [PATCH] spotifyd: add spotifyd service --- modules/module-list.nix | 1 + modules/services/spotifyd.nix | 63 +++++++++++++++++++++++++++++++++++ release.nix | 1 + tests/services-spotifyd.nix | 18 ++++++++++ 4 files changed, 83 insertions(+) create mode 100644 modules/services/spotifyd.nix create mode 100644 tests/services-spotifyd.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 447d075..85dcaf2 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -54,6 +54,7 @@ ./services/redis ./services/skhd ./services/spacebar + ./services/spotifyd.nix ./services/synapse-bt.nix ./services/synergy ./services/yabai diff --git a/modules/services/spotifyd.nix b/modules/services/spotifyd.nix new file mode 100644 index 0000000..461d4df --- /dev/null +++ b/modules/services/spotifyd.nix @@ -0,0 +1,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 = '' + Whether to enable the spotifyd service. + ''; + }; + + package = mkOption { + type = types.path; + default = pkgs.spotifyd; + defaultText = "pkgs.spotifyd"; + description = '' + The spotifyd package to use. + ''; + }; + + settings = mkOption { + type = types.nullOr format.type; + default = null; + example = { + bitrate = 160; + volume_normalisation = true; + }; + description = '' + Configuration for spotifyd, see + 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; + }; + }; + }; +} diff --git a/release.nix b/release.nix index 6dc3a52..a72ad98 100644 --- a/release.nix +++ b/release.nix @@ -125,6 +125,7 @@ let tests.services-redis = makeTest ./tests/services-redis.nix; tests.services-skhd = makeTest ./tests/services-skhd.nix; tests.services-spacebar = makeTest ./tests/services-spacebar.nix; + tests.services-spotifyd = makeTest ./tests/services-spotifyd.nix; tests.services-synapse-bt = makeTest ./tests/services-synapse-bt.nix; tests.services-synergy = makeTest ./tests/services-synergy.nix; tests.services-yabai = makeTest ./tests/services-yabai.nix; diff --git a/tests/services-spotifyd.nix b/tests/services-spotifyd.nix new file mode 100644 index 0000000..956e6a9 --- /dev/null +++ b/tests/services-spotifyd.nix @@ -0,0 +1,18 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + spotifyd = pkgs.runCommand "spotifyd-0.0.0" {} "mkdir $out"; +in + +{ + services.spotifyd.enable = true; + services.spotifyd.package = spotifyd; + + test = '' + echo >&2 "checking spotifyd service in ~/Library/LaunchAgents" + grep "org.nixos.spotifyd" ${config.out}/user/Library/LaunchAgents/org.nixos.spotifyd.plist + grep "${spotifyd}/bin/spotifyd" ${config.out}/user/Library/LaunchAgents/org.nixos.spotifyd.plist + ''; +}