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

81 lines
2.5 KiB
Nix
Raw Normal View History

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";
bluetooth.enable = mkEnableOption "Life with bluetooth";
2021-05-30 19:10:28 +00:00
};
config = mkIf cfg.enable {
home-manager = with pkgs; pkgs.lib.setAttrByPath [ "users" psCfg.user.name ] {
home.packages = [
# 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
];
xdg.configFile."vimpc/vimpcrc".source = ./.config/vimpc/vimpcrc;
systemd.user.services.easyeffects = import ./easyeffects.service.nix pkgs;
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 = {
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);
# Bluetooth configuration for pipewire
2021-10-24 20:55:28 +00:00
media-session.config.bluez-monitor.rules = mkIf cfg.bluetooth.enable [
2021-05-30 19:10:28 +00:00
{
# Matches all cards
matches = [{ "device.name" = "~bluez_card.*"; }];
actions = {
"update-props" = {
"bluez5.reconnect-profiles" = [ "hfp_hf" "hsp_hs" "a2dp_sink" ];
# mSBC is not expected to work on all headset + adapter combinations.
"bluez5.msbc-support" = true;
# SBC-XQ is not expected to work on all headset + adapter combinations.
"bluez5.sbc-xq-support" = true;
2021-05-30 19:10:28 +00:00
};
};
}
{
matches = [
# Matches all sources
{ "node.name" = "~bluez_input.*"; }
# Matches all outputs
{ "node.name" = "~bluez_output.*"; }
];
}
];
};
# 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
};
}