From a8b86890db0f58a9282015af94648422e6d2c21f Mon Sep 17 00:00:00 2001
From: Myned <dev@bjork.tech>
Date: Thu, 2 Jan 2025 12:01:56 -0600
Subject: [PATCH] niri: add disabled outputs option

Signed-off-by: Myned <dev@bjork.tech>
---
 machines/mynix/default.nix               |  5 +++++
 options/custom/desktops/niri/default.nix |  4 ++++
 options/custom/desktops/niri/output.nix  | 27 ++++++++++++++----------
 3 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/machines/mynix/default.nix b/machines/mynix/default.nix
index 484cdfb..2a00b26 100644
--- a/machines/mynix/default.nix
+++ b/machines/mynix/default.nix
@@ -15,6 +15,11 @@
     refresh = 100;
     #// vrr = true;
 
+    desktops.niri.output = {
+      connectors = ["DP-1" "DP-2" "DP-3"];
+      disabled = ["HDMI-A-1" "HDMI-A-2" "HDMI-A-3"];
+    };
+
     programs.looking-glass = {
       enable = true;
       igpu = true;
diff --git a/options/custom/desktops/niri/default.nix b/options/custom/desktops/niri/default.nix
index c5c73cb..d0281ce 100644
--- a/options/custom/desktops/niri/default.nix
+++ b/options/custom/desktops/niri/default.nix
@@ -102,6 +102,10 @@ in {
           # https://github.com/sodiboo/niri-flake/blob/main/docs.md#programsnirisettingsdebug
           settings.debug = {
             #// disable-direct-scanout = [];
+
+            # BUG: Crash when multiple outputs from the same monitor are enabled
+            # https://github.com/YaLTeR/niri/issues/734
+            disable-monitor-names = [];
           };
         };
       }
diff --git a/options/custom/desktops/niri/output.nix b/options/custom/desktops/niri/output.nix
index 772cc96..70ddfc9 100644
--- a/options/custom/desktops/niri/output.nix
+++ b/options/custom/desktops/niri/output.nix
@@ -9,6 +9,7 @@ in {
   options.custom.desktops.niri.output = {
     enable = mkOption {default = false;};
     connectors = mkOption {default = [];};
+    disabled = mkOption {default = [];};
   };
 
   config = mkIf cfg.enable {
@@ -18,20 +19,24 @@ in {
         # https://github.com/sodiboo/niri-flake/blob/main/docs.md#programsnirisettingsoutputs
         #?? niri msg outputs
         programs.niri.settings.outputs = listToAttrs (forEach cfg.connectors (connector: {
-          name = connector;
+            name = connector;
 
-          value = {
-            background-color = "#073642";
+            value = {
+              background-color = "#073642";
 
-            mode = with config.custom; {
-              inherit width height;
-              refresh = refresh + 0.0; # Convert to float
+              mode = with config.custom; {
+                inherit width height;
+                refresh = refresh + 0.0; # Convert to float
+              };
+
+              scale = config.custom.scale;
+              variable-refresh-rate = mkIf config.custom.vrr "on-demand"; #!! Requires window-rule
             };
-
-            scale = config.custom.scale;
-            variable-refresh-rate = mkIf config.custom.vrr "on-demand"; #!! Requires window-rule
-          };
-        }));
+          })
+          ++ (forEach cfg.disabled (connector: {
+            name = connector;
+            value = {enable = false;};
+          })));
       }
     ];
   };