pub-solar-os/modules/audio/default.nix

104 lines
3.1 KiB
Nix
Raw Normal View History

2022-11-20 22:28:23 +00:00
{
lib,
config,
pkgs,
...
}:
with lib; let
2021-05-30 19:10:28 +00:00
psCfg = config.pub-solar;
cfg = config.pub-solar.audio;
xdg = config.home-manager.users."${psCfg.user.name}".xdg;
2022-11-20 22:28:23 +00:00
in {
2021-05-30 19:10:28 +00:00
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";
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-11-20 22:28:23 +00:00
users.users = pkgs.lib.setAttrByPath [psCfg.user.name] {
extraGroups = ["audio"];
};
2022-11-20 22:28:23 +00:00
home-manager = with pkgs;
pkgs.lib.setAttrByPath ["users" psCfg.user.name] {
home.packages =
[
# easyeffects, e.g. for microphone noise filtering
easyeffects
mu
pavucontrol
pa_applet
playerctl
# 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;
2022-11-20 22:28:23 +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;
};
};
};
};
2021-05-30 19:10:28 +00:00
# Enable sound using pipewire-pulse
services.pipewire = {
enable = true;
2021-05-30 19:10:28 +00:00
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
config.pipewire = {
context.default.clock = {
2022-11-20 22:28:23 +00:00
allowed-rates = [44100 48000 88200 96000];
rate = 44100;
};
};
2021-05-30 19:10:28 +00:00
config.pipewire-pulse = builtins.fromJSON (builtins.readFile ./pipewire-pulse.conf.json);
};
2021-05-30 19:10:28 +00:00
# Bluetooth configuration using wireplumber
# https://nixos.wiki/wiki/PipeWire#Bluetooth_Configuration
environment.etc = mkIf cfg.bluetooth.enable {
"wireplumber/bluetooth.lua.d/51-bluez-config.lua".text = ''
bluez_monitor.properties = {
["bluez5.enable-sbc-xq"] = true,
["bluez5.enable-msbc"] = true,
["bluez5.enable-hw-volume"] = true,
["bluez5.headset-roles"] = "[ hsp_hs hsp_ag hfp_hf hfp_ag ]"
2021-05-30 19:10:28 +00:00
}
'';
2021-05-30 19:10:28 +00:00
};
# Enable bluetooth
2021-10-24 20:55:28 +00:00
hardware.bluetooth.enable = mkIf cfg.bluetooth.enable true;
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
};
}