Commit 69d12c91d183

Vincent Demeester <vincent@sbr.pm>
2022-08-19 17:53:37
systems/modules: hardware.audio to support pipewire
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent 26d4b0f
Changed files (3)
systems
systems/modules/desktop/sway.nix
@@ -13,6 +13,12 @@ in
     # Enable wayland desktop modules if not already
     modules.desktop.wayland.enable = true;
 
+    # Enable pipewire
+    modules.hardware.audio = {
+      enable = true;
+      pipewire.enable = true;
+    };
+
     xdg = {
       portal = {
         enable = true;
@@ -23,12 +29,6 @@ in
       };
     };
 
-    services.pipewire = {
-      enable = true;
-      alsa.enable = true;
-      pulse.enable = true;
-    };
-
     # Allow swaylock to unlock the computer for us
     security.pam.services.swaylock = {
       text = "auth include login";
systems/modules/hardware/audio.nix
@@ -6,27 +6,22 @@ in
 {
   options.modules.hardware.audio = {
     enable = mkEnableOption "enable audio";
-    tcp = mkOption {
-      default = false;
-      description = "enable pulseaudio tcp";
-      type = types.bool;
+    pulseaudio = {
+      enable = mkEnableOption "enable pulseaudio";
+      tcp = mkOption {
+        default = false;
+        description = "enable pulseaudio tcp";
+        type = types.bool;
+      };
+    };
+    pipewire = {
+      enable = mkEnableOption "enable pipewire";
     };
   };
   config = mkIf cfg.enable (mkMerge [
     {
-      # Add extra packages
-      environment.systemPackages = with pkgs; [
-        apulse # allow alsa application to use pulse
-        pavucontrol # pulseaudio volume control
-        pasystray # systray application
-      ];
       # Enable sound (alsa)
       sound.enable = true;
-      # Enable and configure pulseaudio
-      hardware.pulseaudio = {
-        enable = true;
-        support32Bit = true;
-      };
       # FIXME is it needed
       security.pam.loginLimits = [
         { domain = "@audio"; item = "memlock"; type = "-"; value = "unlimited"; }
@@ -34,7 +29,31 @@ in
         { domain = "@audio"; item = "nofile"; type = "-"; value = "99999"; }
       ];
     }
-    (mkIf cfg.tcp {
+    (mkIf cfg.pipewire.enable {
+      security.rtkit.enable = true;
+      services.pipewire = {
+        enable = true;
+        alsa.enable = true;
+        alsa.support32Bit = true;
+        pulse.enable = true;
+      };
+    })
+    (mkIf cfg.pulseaudio.enable {
+      # Enable and configure pulseaudio
+      hardware.pulseaudio = {
+        enable = true;
+        support32Bit = true;
+      };
+    })
+    (mkIf (cfg.pulseaudio.enable || cfg.pipewire.enable) {
+      # Add extra packages
+      environment.systemPackages = with pkgs; [
+        apulse # allow alsa application to use pulse
+        pavucontrol # pulseaudio volume control
+        pasystray # systray application
+      ];
+    })
+    (mkIf (cfg.pulseaudio.enable && cfg.pulseaudio.tcp) {
       hardware.pulseaudio = {
         zeroconf = {
           discovery.enable = cfg.tcp;
systems/modules/hardware/bluetooth.nix
@@ -14,7 +14,7 @@ in
       hardware.bluetooth.enable = true;
       # warnings = if stable then [ ] else [ "NixOS release: ${config.system.nixos.release}" ];
     }
-    (mkIf config.modules.hardware.audio.enable {
+    (mkIf config.modules.hardware.audio.pulseaudio.enable {
       hardware.pulseaudio = {
         # NixOS allows either a lightweight build (default) or full build of
         # PulseAudio to be installed.  Only the full build has Bluetooth