niksos/modules/other/hardware.nix

73 lines
2.6 KiB
Nix

{
config,
lib,
...
}: let
cfg = config.myOptions.other.hardware;
inherit (lib.attrsets) mapAttrsToList;
inherit (lib.modules) mkIf;
inherit (lib.options) mkOption;
inherit (lib.types) attrsOf float int submodule;
inherit (lib.types.ints) positive;
in {
options.myOptions.other.hardware = {
monitors = mkOption {
description = "hostname for this system";
type = attrsOf (submodule {
options = {
resolution = mkOption {
description = "monitor resolution";
type = submodule {
options = {
w = mkOption {
description = "monitor width";
type = positive;
};
h = mkOption {
description = "monitor height";
type = positive;
};
};
};
};
refreshRate = mkOption {
description = "monitor refresh rate";
type = positive;
};
position = mkOption {
description = "monitor position";
type = submodule {
options = {
x = mkOption {
description = "monitor x position";
type = int;
};
y = mkOption {
description = "monitor y position";
type = int;
};
};
};
};
scale = mkOption {
description = "monitor scale";
type = float;
};
};
});
default = {};
};
};
config = mkIf (cfg.monitors != {}) {
boot.kernelParams = mapAttrsToList (name: m: let
xres = toString m.resolution.w;
yres = toString m.resolution.h;
refresh = toString m.refreshRate;
in
# https://www.kernel.org/doc/html/latest/fb/modedb.html
"video=${name}:${xres}x${yres}@${refresh}"
) cfg.monitors;
};
}