From 1a06b0c70ea02073ecd6bc86b7f10992c13082c4 Mon Sep 17 00:00:00 2001
From: NullBite <me@nullbite.com>
Date: Sun, 11 Feb 2024 13:11:31 +0100
Subject: [PATCH] sound: add option to use unstable alsa-ucm-conf

---
 system/hardware/sound.nix | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/system/hardware/sound.nix b/system/hardware/sound.nix
index 1e8b92f..d3aa0b2 100644
--- a/system/hardware/sound.nix
+++ b/system/hardware/sound.nix
@@ -1,4 +1,4 @@
-{ config, lib, pkgs, ...}:
+{ config, lib, pkgs, inputs, ...}:
 let
   cfg = config.nixfiles.hardware.sound;
   inherit (lib) optionals mkEnableOption mkIf mkDefault;
@@ -10,9 +10,15 @@ in
 
   options.nixfiles.hardware.sound = {
     enable = mkEnableOption "sound configuration";
+    useUnstableUcmConf = lib.mkOption {
+      description = "Whether to enable unstable alsa-ucm-conf. This seems to cause a mass rebuild and requires a lot of packages to be built from source, so it should only be used if necessary.";
+      default = false;
+      example = true;
+      type = lib.types.bool;
+    };
   };
 
-  config = mkIf cfg.enable {
+  config = lib.mkMerge [(mkIf cfg.enable {
     security.rtkit.enable = mkDefault true;
     services.pipewire = {
       enable = true;
@@ -30,5 +36,12 @@ in
       ncpamixer
       pulsemixer
     ];
-  };
+  })
+  ({
+    # use alsa-ucm-conf from unstable (fixes Scarlett Solo channels)
+    nixpkgs.overlays = lib.optional cfg.useUnstableUcmConf (final: prev: {
+      inherit (inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}) alsa-ucm-conf;
+    });
+  })
+  ];
 }