dotfiles/modules/nixos/hardware/audio.nix

83 lines
2.4 KiB
Nix
Raw Normal View History

2024-04-20 13:42:06 +00:00
{
config,
pkgs,
lib,
...
}:
2022-05-28 20:48:02 +00:00
let
# These micro-scripts change the volume while also triggering the volume
# notification widget
increaseVolume = pkgs.writeShellScriptBin "increaseVolume" ''
${pkgs.pamixer}/bin/pamixer -i 2
volume=$(${pkgs.pamixer}/bin/pamixer --get-volume)
${pkgs.volnoti}/bin/volnoti-show $volume
'';
decreaseVolume = pkgs.writeShellScriptBin "decreaseVolume" ''
${pkgs.pamixer}/bin/pamixer -d 2
volume=$(${pkgs.pamixer}/bin/pamixer --get-volume)
${pkgs.volnoti}/bin/volnoti-show $volume
'';
toggleMute = pkgs.writeShellScriptBin "toggleMute" ''
${pkgs.pamixer}/bin/pamixer --toggle-mute
mute=$(${pkgs.pamixer}/bin/pamixer --get-mute)
if [ "$mute" == "true" ]; then
${pkgs.volnoti}/bin/volnoti-show --mute
else
volume=$(${pkgs.pamixer}/bin/pamixer --get-volume)
${pkgs.volnoti}/bin/volnoti-show $volume
fi
'';
2024-04-20 13:42:06 +00:00
in
{
2022-04-29 02:12:16 +00:00
2022-12-21 21:18:03 +00:00
config = lib.mkIf (pkgs.stdenv.isLinux && config.gui.enable) {
# Enable PipeWire
services.pipewire = {
enable = true;
pulse.enable = true;
};
2022-04-29 02:12:16 +00:00
2022-11-14 15:35:36 +00:00
# Provides audio source with background noise filtered
programs.noisetorch.enable = true;
2022-05-29 17:44:45 +00:00
# These aren't necessary, but helpful for the user
2022-05-28 20:48:02 +00:00
environment.systemPackages = with pkgs; [
pamixer # Audio control
volnoti # Volume notifications
];
home-manager.users.${config.user} = {
# Graphical volume notifications
services.volnoti.enable = true;
2022-05-29 17:44:45 +00:00
xsession.windowManager.i3.config = {
# Make sure that Volnoti actually starts (home-manager doesn't start
# user daemon's automatically)
2024-04-20 13:42:06 +00:00
startup = [
{
command = "systemctl --user restart volnoti --alpha 0.15 --radius 40 --timeout 0.2";
always = true;
notification = false;
}
];
2022-05-29 17:44:45 +00:00
# i3 keybinds for changing the volume
keybindings = {
2024-04-20 13:42:06 +00:00
"XF86AudioRaiseVolume" = "exec --no-startup-id ${increaseVolume}/bin/increaseVolume";
"XF86AudioLowerVolume" = "exec --no-startup-id ${decreaseVolume}/bin/decreaseVolume";
2022-05-29 17:44:45 +00:00
"XF86AudioMute" = "exec --no-startup-id ${toggleMute}/bin/toggleMute";
# We can mute the mic by adding "--default-source"
2024-04-20 13:42:06 +00:00
"XF86AudioMicMute" = "exec --no-startup-id ${pkgs.pamixer}/bin/pamixer --default-source --toggle-mute";
2022-05-29 17:44:45 +00:00
};
2022-05-28 20:48:02 +00:00
};
};
2022-04-30 16:32:00 +00:00
};
2022-04-29 02:12:16 +00:00
}