From 210d8f3b1f2886f17d99d7e67db0745f4967decd Mon Sep 17 00:00:00 2001 From: Hektor Misplon Date: Wed, 11 Mar 2026 23:53:50 +0100 Subject: [PATCH] refactor: merge 'audio-automation' module into 'audio' module --- hosts/astyanax/default.nix | 2 +- modules/audio-automation/default.nix | 17 --------------- modules/audio/audio-automation.nix | 29 +++++++++++++++++++++++++ modules/audio/default.nix | 32 +++++++++++++++++----------- 4 files changed, 50 insertions(+), 30 deletions(-) delete mode 100644 modules/audio-automation/default.nix create mode 100644 modules/audio/audio-automation.nix diff --git a/hosts/astyanax/default.nix b/hosts/astyanax/default.nix index dc21ea6..2433d9d 100644 --- a/hosts/astyanax/default.nix +++ b/hosts/astyanax/default.nix @@ -25,7 +25,6 @@ in }) ../../modules/desktops/niri ../../modules/audio - ../../modules/audio-automation ../../modules/backups ../../modules/bluetooth ../../modules/keyboard @@ -57,6 +56,7 @@ in docker.user = config.host.username; nfc.user = config.host.username; desktop.ly.enable = true; + audio.automation.enable = true; nix.settings.secret-key-files = [ config.sops.secrets.nix_signing_key_astyanax.path ]; diff --git a/modules/audio-automation/default.nix b/modules/audio-automation/default.nix deleted file mode 100644 index 70dcda1..0000000 --- a/modules/audio-automation/default.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ pkgs, ... }: - -{ - environment.systemPackages = [ pkgs.libnotify ]; - - services.udev.extraRules = '' - SUBSYSTEM=="power_supply", ATTR{online}=="0", ACTION=="change", TAG+="systemd", ENV{SYSTEMD_USER_WANTS}+="mute-audio.service" - ''; - - systemd.user.services.mute-audio = { - description = "mute audio when switching to battery power"; - serviceConfig = { - Type = "oneshot"; - ExecStart = "${pkgs.bash}/bin/bash -c '${pkgs.pulseaudio}/bin/pactl set-sink-mute $(${pkgs.pulseaudio}/bin/pactl get-default-sink) true && ${pkgs.libnotify}/bin/notify-send \"audio Muted\" \"switched to battery power\"'"; - }; - }; -} diff --git a/modules/audio/audio-automation.nix b/modules/audio/audio-automation.nix new file mode 100644 index 0000000..29cab34 --- /dev/null +++ b/modules/audio/audio-automation.nix @@ -0,0 +1,29 @@ +{ + lib, + config, + pkgs, + ... +}: + +let + cfg = config.audio.automation; +in +{ + options.audio.automation.enable = lib.mkEnableOption "audio automation (mute on battery)"; + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ pkgs.libnotify ]; + + services.udev.extraRules = '' + SUBSYSTEM=="power_supply", ATTR{online}=="0", ACTION=="change", TAG+="systemd", ENV{SYSTEMD_USER_WANTS}+="mute-audio.service" + ''; + + systemd.user.services.mute-audio = { + description = "mute audio when switching to battery power"; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.bash}/bin/bash -c '${pkgs.pulseaudio}/bin/pactl set-sink-mute $(${pkgs.pulseaudio}/bin/pactl get-default-sink) true && ${pkgs.libnotify}/bin/notify-send \"audio Muted\" \"switched to battery power\"'"; + }; + }; + }; +} diff --git a/modules/audio/default.nix b/modules/audio/default.nix index dc6435a..9779f71 100644 --- a/modules/audio/default.nix +++ b/modules/audio/default.nix @@ -1,18 +1,26 @@ +{ ... }: + { - nixpkgs.allowedUnfree = [ - "spotify" - "spotify-unwrapped" + imports = [ + ./audio-automation.nix ]; - security.rtkit.enable = true; - services = { - pulseaudio.enable = false; - pipewire = { - enable = true; - alsa.enable = true; - alsa.support32Bit = true; - pulse.enable = true; + config = { + nixpkgs.allowedUnfree = [ + "spotify" + "spotify-unwrapped" + ]; + + security.rtkit.enable = true; + services = { + pulseaudio.enable = false; + pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + }; + pulseaudio.extraConfig = "load-module module-switch-on-connect"; }; - pulseaudio.extraConfig = "load-module module-switch-on-connect"; }; }