From eee6ae33e874912c8ec218c8ac1eeef89afd85d2 Mon Sep 17 00:00:00 2001 From: Kloenk Date: Fri, 18 Oct 2019 21:04:08 +0200 Subject: [PATCH] spotifyd: add module --- modules/misc/news.nix | 8 ++++++ modules/modules.nix | 1 + modules/services/spotifyd.nix | 53 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 modules/services/spotifyd.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index bbc05e230..ea22fbdd8 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1236,6 +1236,14 @@ in A new module is available: 'services.lorri'. ''; } + + { + time = "2019-11-24T17:46:57+00:00"; + condition = hostPlatform.isLinux; + message = '' + A new module is available: 'services.spotifyd'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index a3bf286c7..09c1a4a49 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -132,6 +132,7 @@ let (loadModule ./services/screen-locker.nix { }) (loadModule ./services/stalonetray.nix { }) (loadModule ./services/status-notifier-watcher.nix { }) + (loadModule ./services/spotifyd.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/sxhkd.nix { condition = hostPlatform.isLinux; }) (loadModule ./services/syncthing.nix { }) (loadModule ./services/taffybar.nix { }) diff --git a/modules/services/spotifyd.nix b/modules/services/spotifyd.nix new file mode 100644 index 000000000..831b3bdb7 --- /dev/null +++ b/modules/services/spotifyd.nix @@ -0,0 +1,53 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.spotifyd; + + configFile = pkgs.writeText "spotifyd.conf" '' + ${generators.toINI {} cfg.settings} + ''; + +in + +{ + options.services.spotifyd = { + enable = mkEnableOption "SpotifyD connect"; + + settings = mkOption { + type = types.attrsOf (types.attrsOf types.str); + default = {}; + description = "Configuration for spotifyd"; + example = literalExample '' + { + global = { + user = "Alex"; + password = "foo"; + device_name = "nix"; + }; + } + ''; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ pkgs.spotifyd ]; + + systemd.user.services.spotifyd = { + Unit = { + Description = "spotify daemon"; + Documentation = "https://github.com/Spotifyd/spotifyd"; + }; + + Install.WantedBy = [ "default.target" ]; + + Service = { + ExecStart = "${pkgs.spotifyd}/bin/spotifyd --no-daemon --config ${configFile}"; + Restart = "always"; + RestartSec = 12; + }; + }; + }; +}