diff --git a/common/spotify.nix b/common/spotify.nix new file mode 100644 index 0000000..cf0b5f4 --- /dev/null +++ b/common/spotify.nix @@ -0,0 +1,24 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.grimmShared; +in +{ + config = with cfg; lib.mkIf (enable && spotify.enable) { + environment.systemPackages = [ + pkgs.ncspot + ] ++ lib.optional graphical pkgs.spotify; + + grimmShared = { + sound = true; + network = true; + }; + }; + + options.grimmShared.spotify = { + enable = lib.mkEnableOption "grimm-spotify"; + }; + + imports = [ + ./spotifyd.nix + ]; +} diff --git a/common/spotifyd.nix b/common/spotifyd.nix new file mode 100644 index 0000000..537f34c --- /dev/null +++ b/common/spotifyd.nix @@ -0,0 +1,93 @@ +{ config, lib, pkgs, ... }: +let + spotifyd_cache_dir = "/tmp/spotifyd"; + cfg = config.grimmShared; + spotifyd-dbus = pkgs.writeTextDir "share/dbus-1/system.d/org.mpris.MediaPlayer2.spotifyd.conf" '' + + + + + + + + + + + + + + + ''; +in +{ + config = with cfg; lib.mkIf (enable && spotify.enable && spotify.spotifyd.enable) { + environment.systemPackages = with pkgs; [ + spotifyd + spotifyd-dbus + ]; + + systemd.services.init-spotifyd-cache-dir = { + description = "Create the spotifyd cache dir"; + wantedBy = [ "multi-user.target" ]; + + serviceConfig.Type = "oneshot"; + script = '' + mkdir -p ${spotifyd_cache_dir} + chown spotifyd:spotifyd -R ${spotifyd_cache_dir} + ''; + }; + + # spotifyd config + services.spotifyd = { + enable = true; + settings.global = { + bitrate = 320; + username = cfg.spotify.spotifyd.username; + device_name = "grimm_laptop"; + password_cmd = let pass = cfg.spotify.spotifyd.pass; in with lib; if (lib.isPath pass || lib.isString pass) then "${pkgs.coreutils-full}/bin/cat ${pass}" else (getExe pass); + device_type = "computer"; + dbus_type = "system"; + device = "default"; + control = "default"; + volume_controller = "softvol"; + # no_audio_cache = true; + spotifyd_cache_dir = spotifyd_cache_dir; + max_cache_size = 10000000000; + initial_volume = "90"; + backend = "alsa"; # fixme + }; + }; + + + services.dbus.packages = with pkgs; [ + spotifyd-dbus + ]; + + # spotifyd has access to global pipewire + users.users.spotifyd = { + isSystemUser = true; + group = "spotifyd"; + extraGroups = [ "audio" "pipewire" ]; + }; + + # spotifyd is also a group + users.groups = { spotifyd = { }; }; + }; + + options.grimmShared.spotify.spotifyd = with lib; { + enable = mkEnableOption "grimm-spotify-tui"; + + username = mkOption { + type = types.nonEmptyStr; + description = "spotify username"; + }; + + + pass = mkOption { + type = types.either types.nonEmptyStr (types.either types.package types.path); + description = "command to execute to obtain login information or readable path to a file containing them"; + }; + }; +} diff --git a/common/sway.nix b/common/sway.nix index c31e9d1..9b8368c 100644 --- a/common/sway.nix +++ b/common/sway.nix @@ -10,7 +10,7 @@ let }; autolaunch = mkOption { - type = types.listOf (types.either types.str types.package); + type = types.listOf (types.either types.nonEmptyStr types.package); default = [ ]; description = "set of commands to be run at sway startup"; }; diff --git a/configuration.nix b/configuration.nix index b25f76c..f196923 100644 --- a/configuration.nix +++ b/configuration.nix @@ -58,13 +58,31 @@ server = "cloud.grimmauld.de"; passwordFile = config.age.secrets.nextcloud_pass.path; }; + + spotify = { + enable = true; + spotifyd = { + enable = true; + pass = config.age.secrets.spotify_pass.path; + username = "3tyhk4i01l54w7co7xm7jvu32"; + }; + }; }; + age.identityPaths = [ "/home/grimmauld/.ssh/id_rsa" ]; age.secrets.nextcloud_pass = { file = ./secrets/nextcloud_pass.age; mode = "777"; }; + age.secrets.spotify_pass = { + file = ./secrets/spotify_pass.age; + owner = "spotifyd"; + group = "spotifyd"; + mode = "700"; + }; + + environment.sessionVariables = { NIXPKGS_ALLOW_UNFREE = "1"; MOZ_ENABLE_WAYLAND = "1"; diff --git a/flake.nix b/flake.nix index 190aa7a..d452838 100644 --- a/flake.nix +++ b/flake.nix @@ -38,10 +38,8 @@ nix-gaming.nixosModules.pipewireLowLatency ./load_common.nix ./specific/grimm-nixos-laptop/configuration.nix - ./configuration.nix ./modules/users.nix - ./modules/spotify-tui.nix ./modules/system-packages.nix ./modules/kvm.nix { environment.systemPackages = [ agenix.packages.${system}.default ]; } diff --git a/load_common.nix b/load_common.nix index 7e74c58..e2c2fdd 100644 --- a/load_common.nix +++ b/load_common.nix @@ -19,5 +19,6 @@ with lib; ./common/cloudsync.nix ./common/security.nix ./common/qt.nix + ./common/spotify.nix ]; } diff --git a/modules/spotify-tui.nix b/modules/spotify-tui.nix deleted file mode 100644 index 5c5658b..0000000 --- a/modules/spotify-tui.nix +++ /dev/null @@ -1,96 +0,0 @@ -{ config, pkgs, ... }: -let - spotifyd_cache_dir = "/tmp/spotifyd"; -in -{ - nixpkgs.overlays = [ - (final: prev: { - spotifyd = prev.spotifyd.overrideAttrs (old: { - postInstall = '' - mkdir -p $out/share/dbus-1/system.d/ - tee $out/share/dbus-1/system.d/org.mpris.MediaPlayer2.spotifyd.conf < - - - - - - - - - - - - - - END - ''; - }); - }) - ]; - - environment.systemPackages = with pkgs; [ - ncspot - spotifyd - ]; - - # decrypt spotify password - age.identityPaths = [ "/home/grimmauld/.ssh/id_rsa" ]; - - # spotify pass - age.secrets.spotify_pass = { - file = ../secrets/spotify_pass.age; - owner = "spotifyd"; - group = "spotifyd"; - mode = "700"; - }; - - systemd.services.init-spotifyd-cache-dir = { - description = "Create the spotifyd cache dir"; - wantedBy = [ "multi-user.target" ]; - - serviceConfig.Type = "oneshot"; - script = '' - mkdir -p ${spotifyd_cache_dir} - chown spotifyd:spotifyd -R ${spotifyd_cache_dir} - ''; - }; - - # spotifyd config - services.spotifyd = { - enable = true; - settings.global = { - bitrate = 320; - username = "3tyhk4i01l54w7co7xm7jvu32"; - device_name = "grimm_laptop"; - password_cmd = "${pkgs.coreutils-full}/bin/cat ${config.age.secrets.spotify_pass.path}"; # read password secret - device_type = "computer"; - dbus_type = "system"; - device = "default"; - control = "default"; - volume_controller = "softvol"; - # no_audio_cache = true; - spotifyd_cache_dir = spotifyd_cache_dir; - max_cache_size = 10000000000; - initial_volume = "90"; - backend = "alsa"; # fixme - }; - }; - - - services.dbus.packages = with pkgs; [ - spotifyd # add above dbus code to the config - ]; - - # spotifyd has access to global pipewire - users.users.spotifyd = { - isSystemUser = true; - group = "spotifyd"; - extraGroups = [ "audio" "pipewire" ]; - }; - - # spotifyd is also a group - users.groups = { spotifyd = { }; }; -}