2021-05-30 19:10:28 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
psCfg = config.pub-solar;
|
|
|
|
cfg = config.pub-solar.audio;
|
|
|
|
xdg = config.home-manager.users."${psCfg.user.name}".xdg;
|
|
|
|
in {
|
|
|
|
options.pub-solar.audio = {
|
|
|
|
enable = mkEnableOption "Life in highs and lows";
|
2021-10-24 20:55:28 +00:00
|
|
|
mopidy.enable = mkEnableOption "Life with mopidy";
|
2022-08-10 20:42:14 +00:00
|
|
|
spotify.enable = mkEnableOption "Life in DRM";
|
|
|
|
spotify.username = mkOption {
|
|
|
|
description = "Spotify login username or email";
|
|
|
|
type = types.str;
|
|
|
|
example = "yourname@example.com";
|
|
|
|
default = "";
|
|
|
|
};
|
2021-10-24 20:55:28 +00:00
|
|
|
bluetooth.enable = mkEnableOption "Life with bluetooth";
|
2021-05-30 19:10:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2022-08-10 20:42:14 +00:00
|
|
|
users.users = pkgs.lib.setAttrByPath [psCfg.user.name] {
|
|
|
|
extraGroups = ["audio"];
|
|
|
|
};
|
|
|
|
|
2021-05-30 19:10:28 +00:00
|
|
|
home-manager = with pkgs;
|
|
|
|
pkgs.lib.setAttrByPath ["users" psCfg.user.name] {
|
|
|
|
home.packages =
|
|
|
|
[
|
2022-01-05 22:02:05 +00:00
|
|
|
# easyeffects, e.g. for microphone noise filtering
|
|
|
|
easyeffects
|
2021-05-30 19:10:28 +00:00
|
|
|
mu
|
|
|
|
pavucontrol
|
|
|
|
pa_applet
|
|
|
|
playerctl
|
|
|
|
# Needed for pactl cmd, until pw-cli is more mature (vol up/down hotkeys?)
|
|
|
|
pulseaudio
|
|
|
|
vimpc
|
2022-08-10 20:42:14 +00:00
|
|
|
]
|
|
|
|
++ (
|
|
|
|
if cfg.spotify.enable
|
|
|
|
then [pkgs.spotify-tui]
|
|
|
|
else []
|
|
|
|
);
|
2021-05-30 19:10:28 +00:00
|
|
|
xdg.configFile."vimpc/vimpcrc".source = ./.config/vimpc/vimpcrc;
|
2022-01-05 22:02:05 +00:00
|
|
|
systemd.user.services.easyeffects = import ./easyeffects.service.nix pkgs;
|
2022-08-10 20:42:14 +00:00
|
|
|
|
|
|
|
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;
|
2022-11-20 22:28:23 +00:00
|
|
|
};
|
2022-08-10 20:42:14 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2021-05-30 19:10:28 +00:00
|
|
|
|
2022-11-20 22:40:24 +00:00
|
|
|
# rtkit is optional but recommended
|
|
|
|
security.rtkit.enable = true;
|
2023-05-17 22:04:39 +00:00
|
|
|
# Enable sound using pipewire-pulse, default config:
|
|
|
|
# https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/master/src/daemon/pipewire.conf.in
|
2021-05-30 19:10:28 +00:00
|
|
|
services.pipewire = {
|
2022-01-05 22:02:05 +00:00
|
|
|
enable = true;
|
2021-05-30 19:10:28 +00:00
|
|
|
alsa.enable = true;
|
|
|
|
alsa.support32Bit = true;
|
|
|
|
pulse.enable = true;
|
2022-04-14 11:47:29 +00:00
|
|
|
|
|
|
|
config.pipewire = {
|
|
|
|
context.default.clock = {
|
|
|
|
allowed-rates = [44100 48000 88200 96000];
|
|
|
|
rate = 44100;
|
|
|
|
quantum = 2048;
|
|
|
|
min-quantum = 1024;
|
|
|
|
max-quantum = 4096;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config.pipewire-pulse = builtins.fromJSON (builtins.readFile ./pipewire-pulse.conf.json);
|
2022-07-08 12:18:10 +00:00
|
|
|
};
|
2021-05-30 19:10:28 +00:00
|
|
|
|
2023-05-17 22:04:39 +00:00
|
|
|
# Make pulseaudio listen on port 4713 for mopidy, extending the default
|
|
|
|
# config: https://gitlab.freedesktop.org/pipewire/pipewire/-/blob/master/src/daemon/pipewire-pulse.conf.in
|
|
|
|
environment.etc = mkIf cfg.mopidy.enable {
|
|
|
|
"pipewire/pipewire-pulse.conf.d/99-custom.conf".text = ''
|
|
|
|
{
|
|
|
|
"context.modules": [
|
|
|
|
{
|
|
|
|
"name": "libpipewire-module-protocol-pulse",
|
|
|
|
"args": {
|
|
|
|
"server.address": ["unix:native", "tcp:4713"],
|
|
|
|
"vm.overrides": {
|
|
|
|
"pulse.min.quantum": "1024/48000"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
2021-05-30 19:10:28 +00:00
|
|
|
}
|
2022-07-08 12:18:10 +00:00
|
|
|
'';
|
2021-05-30 19:10:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# Enable bluetooth
|
2023-03-27 08:38:24 +00:00
|
|
|
hardware.bluetooth = mkIf cfg.bluetooth.enable {
|
|
|
|
enable = true;
|
2023-05-17 22:04:39 +00:00
|
|
|
# Disable bluetooth on startup to save battery
|
|
|
|
powerOnBoot = false;
|
|
|
|
# Disable useless SIM Access Profile plugin
|
2023-03-27 08:38:24 +00:00
|
|
|
disabledPlugins = [
|
|
|
|
"sap"
|
|
|
|
];
|
2023-05-17 22:04:39 +00:00
|
|
|
settings = {
|
|
|
|
General = {
|
|
|
|
# Enables experimental features and interfaces.
|
|
|
|
# Makes BlueZ Battery Provider available
|
|
|
|
Experimental = true;
|
|
|
|
};
|
|
|
|
};
|
2023-03-27 08:38:24 +00:00
|
|
|
};
|
2021-10-24 20:55:28 +00:00
|
|
|
services.blueman.enable = mkIf cfg.bluetooth.enable true;
|
2021-05-30 19:10:28 +00:00
|
|
|
|
|
|
|
# Enable audio server & client
|
2021-10-24 20:55:28 +00:00
|
|
|
services.mopidy = mkIf cfg.mopidy.enable ((import ./mopidy.nix) pkgs);
|
2021-05-30 19:10:28 +00:00
|
|
|
};
|
|
|
|
}
|