Add spotify as an audio option

Adds a `config.pub-solar.audio.spotify` option that when enabled
installs and configures `spotifyd` as a systemd daemon and `spotify-tui`
as the terminal-based UI.

After enabling, run `spt` in the terminal to open the UI.
This commit is contained in:
Benjamin Bädorf 2022-08-10 22:42:14 +02:00
parent fd50ecf445
commit c2bc749beb
No known key found for this signature in database
GPG key ID: 4406E80E13CD656C
2 changed files with 33 additions and 2 deletions

View file

@ -9,10 +9,21 @@ in
options.pub-solar.audio = {
enable = mkEnableOption "Life in highs and lows";
mopidy.enable = mkEnableOption "Life with mopidy";
spotify.enable = mkEnableOption "Life in DRM";
spotify.username = mkOption {
description = "Spotify login username or email";
type = types.str;
example = "yourname@example.com";
default = "";
};
bluetooth.enable = mkEnableOption "Life with bluetooth";
};
config = mkIf cfg.enable {
users.users = pkgs.lib.setAttrByPath [ psCfg.user.name ] {
extraGroups = [ "audio" ];
};
home-manager = with pkgs; pkgs.lib.setAttrByPath [ "users" psCfg.user.name ] {
home.packages = [
# easyeffects, e.g. for microphone noise filtering
@ -24,9 +35,23 @@ in
# Needed for pactl cmd, until pw-cli is more mature (vol up/down hotkeys?)
pulseaudio
vimpc
];
] ++ (if cfg.spotify.enable then [ pkgs.spotify-tui ] else [ ]);
xdg.configFile."vimpc/vimpcrc".source = ./.config/vimpc/vimpcrc;
systemd.user.services.easyeffects = import ./easyeffects.service.nix pkgs;
services.spotifyd = mkIf cfg.spotify.enable {
enable = true;
settings = {
global = {
username = cfg.spotify.username;
password_cmd = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1001/bus ${pkgs.libsecret}/bin/secret-tool lookup spotify password";
bitrate = 320;
volume_normalisation = true;
no_audio_cache = false;
max_cache_size = 1000000000;
};
};
};
};
# Enable sound using pipewire-pulse

View file

@ -16,7 +16,13 @@ in
# home to /home/username, useDefaultShell to true, and isSystemUser to false.
isNormalUser = true;
description = psCfg.user.description;
extraGroups = [ "wheel" "docker" "input" "audio" "networkmanager" "lp" "scanner" ];
extraGroups = [
"wheel"
"input"
"networkmanager"
"lp"
"scanner"
];
initialHashedPassword = if psCfg.user.password != null then psCfg.user.password else "";
shell = pkgs.zsh;
openssh.authorizedKeys.keyFiles = if psCfg.user.publicKeys != null then psCfg.user.publicKeys else [ ];