nix-dotfiles/modules/desktop/monitors.nix
2026-04-27 19:58:15 -07:00

65 lines
2.1 KiB
Nix

{ lib, config, pkgs, ... }:
with lib;
with lib.my;
let
cfg = config.modules.desktop.monitors;
in {
options.modules.desktop.monitors = {
enable = mkEnableOption "manually configure monitor settings, use if manual configuration is needed";
monitors = mkOption {
type = types.listOf (types.submodule {
options = {
name = mkOption {
type = types.str;
description = "the monitor name to configure. easily fetchable from `niri msg outputs`";
example = "eDP-1";
};
scale = mkOpt (types.nullOr types.float) 1.0;
vrr = mkEnableOption "whether or not to enable VRR (variable refresh rate)";
primary = mkEnableOption "whether or not the monitor is the primary monitor";
resolution = mkOpt (types.nullOr (types.submodule {
options = {
width = mkOption { type = types.int; };
height = mkOption { type = types.int; };
};
})) null;
position = mkOpt (types.nullOr (types.submodule {
options = {
x = mkOption { type = types.int; };
y = mkOption { type = types.int; };
};
})) null;
};
});
example = [
{ name = "eDP-1"; scale = 2.0; primary = true; }
{ name = "HDMI-1"; scale = 1.0; vrr = true; }
];
};
};
config = mkIf cfg.enable {
assertions = [
{
assertion = builtins.length (builtins.filter (m: m.primary) cfg.monitors) <= 1;
message = "only one monitor should be marked as primary";
}
];
hm.programs.niri.settings.outputs = builtins.listToAttrs (builtins.map (monitor: {
name = monitor.name;
value = {
scale = monitor.scale;
variable-refresh-rate = monitor.vrr;
focus-at-startup = monitor.primary;
position = monitor.position;
} // optionalAttrs (monitor.resolution != null) {
mode = {
width = monitor.resolution.width;
height = monitor.resolution.height;
};
};
}) cfg.monitors);
};
}