grimm-nixos-laptop/common/sound/spotifyd.nix

110 lines
3.2 KiB
Nix
Raw Normal View History

2024-05-07 23:31:41 +02:00
{
config,
lib,
pkgs,
...
}:
let
spotifyd_cache_dir = "/tmp/spotifyd";
2024-05-11 22:55:59 +02:00
inherit (config.grimmShared) enable spotify;
spotifyd-dbus = pkgs.writeTextDir "share/dbus-1/system.d/org.mpris.MediaPlayer2.spotifyd.conf" ''
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="spotifyd">
<allow own_prefix="org.mpris.MediaPlayer2.spotifyd"/>
<allow send_destination_prefix="org.mpris.MediaPlayer2.spotifyd"/>
<allow receive_sender="org.mpris.MediaPlayer2"/>
</policy>
<policy context="default">
<allow send_destination_prefix="org.mpris.MediaPlayer2.spotifyd"/>
<allow receive_sender="org.mpris.MediaPlayer2"/>
</policy>
</busconfig>
'';
in
{
2024-05-11 22:55:59 +02:00
config = lib.mkIf (enable && spotify.spotifyd.enable) {
environment.systemPackages = [
pkgs.spotifyd
spotifyd-dbus
];
2024-05-11 22:55:59 +02:00
systemd.services.init-spotifyd-cache-dir = {
description = "Create the spotifyd cache dir";
wantedBy = [ "multi-user.target" ];
2024-05-11 22:55:59 +02:00
serviceConfig.Type = "oneshot";
script = ''
mkdir -p ${spotifyd_cache_dir}
chown spotifyd:spotifyd -R ${spotifyd_cache_dir}
'';
};
2024-05-11 22:55:59 +02:00
grimmShared = {
sound.enable = true;
network = true;
};
2024-04-26 21:36:24 +02:00
2024-05-11 22:55:59 +02:00
services.pipewire.systemWide = true; # required for spotifyd as spotifyd runs as the spotifyd user
2024-04-20 19:50:23 +02:00
2024-05-11 22:55:59 +02:00
# spotifyd config
services.spotifyd = {
enable = true;
settings.global = {
bitrate = 320;
username = spotify.spotifyd.username;
device_name = "grimm_laptop";
password_cmd =
let
pass = spotify.spotifyd.pass;
2024-09-21 09:43:57 +02:00
inherit (lib) isPath isString getExe getExe';
2024-05-11 22:55:59 +02:00
in
2024-09-21 09:43:57 +02:00
if (isPath pass || isString pass) then "${getExe' pkgs.coreutils-full "cat"} ${pass}" else (getExe pass);
2024-05-11 22:55:59 +02:00
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
};
2024-05-11 22:55:59 +02:00
};
2024-05-11 22:55:59 +02:00
services.dbus.packages = [ spotifyd-dbus ];
2024-05-11 22:55:59 +02:00
# spotifyd has access to global pipewire
users.users.spotifyd = {
isSystemUser = true;
group = "spotifyd";
extraGroups = [
"audio"
"pipewire"
];
};
2024-05-11 22:55:59 +02:00
# 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";
};
};
}