From b6b76a0e7d8285ffd6c2d6268142f9af87ee9080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Sat, 22 Jul 2023 11:18:58 +0200 Subject: [PATCH] feat(spotify_player): add service/program module --- modules/profiles/desktop.nix | 33 +++++++++++++++- modules/programs/spotify_player.nix | 33 ++++++++++++++++ modules/services/spotify_player.nix | 58 +++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 modules/programs/spotify_player.nix create mode 100644 modules/services/spotify_player.nix diff --git a/modules/profiles/desktop.nix b/modules/profiles/desktop.nix index bae0d2f..4af668d 100644 --- a/modules/profiles/desktop.nix +++ b/modules/profiles/desktop.nix @@ -36,7 +36,25 @@ in nix-edit.enable = mkDefault true; nvim.enable = mkDefault true; python.versions."311".enable = mkDefault true; - spotify.enable = mkDefault true; + spotify-player = { + enable = mkDefault true; + package = pkgs.spotify-player.overrideAttrs (old: { + buildFeatures = lib.lists.remove "notify" (old.buildFeatures or [ ]); + }); + config = { + client_id = "3172dbeaf64949728920c58b823bc24b"; + copy_command = { + command = "wl-copy"; + args = [ ]; + }; + enable_cover_image_cache = true; + default_device = "spotify-player-daemon"; + enable_streaming = false; + playback_window_position = "Bottom"; + cover_img_length = 20; + cover_img_width = 10; + }; + }; ssh.enable = mkDefault true; thunar.enable = mkDefault true; wallpaper.enable = mkDefault true; @@ -47,6 +65,19 @@ in gammastep.enable = true; kdeconnect.enable = mkDefault true; printing.enable = true; + spotify-player = { + enable = mkDefault true; + config = { + client_id = "3172dbeaf64949728920c58b823bc24b"; + device = { + name = "spotify-player-daemon"; + device_type = "computer"; + volume = 70; + bitrate = 320; + audio_cache = true; + }; + }; + }; wireguard.enable = true; }; }; diff --git a/modules/programs/spotify_player.nix b/modules/programs/spotify_player.nix new file mode 100644 index 0000000..435b9c8 --- /dev/null +++ b/modules/programs/spotify_player.nix @@ -0,0 +1,33 @@ +{ config +, lib +, pkgs +, ... +}: + +with lib; +let + cfg = config.my.programs.spotify-player; + toml = pkgs.formats.toml { }; +in +{ + options.my.programs.spotify-player = { + enable = mkEnableOption "spotify-player"; + package = mkOption { + type = types.package; + default = pkgs.spotify-player; + }; + config = mkOption { + inherit (toml) type; + default = { }; + }; + }; + + config = mkIf cfg.enable { + home-manager.users.moritz = { + xdg.configFile."spotify-player/app.toml" = { + source = toml.generate "app.toml" cfg.config; + }; + home.packages = [ cfg.package ]; + }; + }; +} diff --git a/modules/services/spotify_player.nix b/modules/services/spotify_player.nix new file mode 100644 index 0000000..b494c3a --- /dev/null +++ b/modules/services/spotify_player.nix @@ -0,0 +1,58 @@ +{ lib, config, pkgs, ... }: + +with lib; +let + toml = pkgs.formats.toml { }; + cfg = config.my.services.spotify-player; + + tomlConfig = + if cfg.configFile != null + then cfg.configFile + else toml.generate "app.toml" cfg.config; + + configFolder = pkgs.runCommand "spotify-player-config" { } '' + mkdir $out + ln -s "${tomlConfig}" $out/app.toml + ''; +in +{ + options.my.services.spotify-player = { + enable = mkEnableOption "spotify_player"; + config = mkOption { + inherit (toml) type; + default = { }; + }; + configFile = mkOption { + type = with types; nullOr path; + default = null; + }; + package = mkOption { + type = types.package; + default = pkgs.spotify-player; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + { + assertion = cfg.config == { } || cfg.configFile == null; + message = "At least one of the options 'config' or 'configFile' must be set."; + } + { + assertion = cfg.config != { } || cfg.configFile != null; + message = "Only one of the options 'config' or 'configFile' may be set."; + } + ]; + systemd.user.services.spotify-player = { + after = [ "graphical-session.target" "network.target" ]; + partOf = [ "graphical-session.target" ]; + wantedBy = [ "graphical-session.target" ]; + serviceConfig = { + Type = "forking"; + Restart = "always"; + RestartSec = "1s"; + ExecStart = "${getExe cfg.package} --daemon --config-folder ${configFolder}"; + }; + }; + }; +}