begin to modularise

This commit is contained in:
Tristan 2023-05-06 18:38:35 +01:00
parent bbd26675f8
commit a1175ba492
10 changed files with 311 additions and 93 deletions

82
lib/modules/display.nix Normal file
View file

@ -0,0 +1,82 @@
{ user }: { lib, pkgs, config, ... }:
with lib;
let
cfg = config.displays;
renderDisplaysForHyprland = displays:
"# === DISPLAY MODULE ===\n"
+ concatStringsSep "\n" (map displayHyprlandSetting displays);
displayHyprlandSetting = display:
"monitor = " + display.name +
", " + resToString display.resolution +
", " + display.position +
", " + toString display.scaling;
resolutionType = types.submodule ({ x, y, freq, ... }:
{
options = {
x = mkOption {
description = "x";
type = types.int;
default = 0;
};
y = mkOption {
description = "y";
type = types.int;
default = 0;
};
freq = mkOption {
description = "frequency";
type = types.int;
default = 0;
};
};
});
displayType = types.submodule
({ ... }: {
options = {
name = mkOption {
description = "name of the display";
};
scaling = mkOption {
type = types.float;
default = 1.0;
};
resolution = mkOption {
description = "res";
type = resolutionType;
default = { };
};
position = mkOption {
description = "XxY";
default = "auto";
};
};
});
resToString = res:
if res.x == 0 || res.y == 0 || res.freq == 0
then "preferred"
else "${toString res.x}x${toString res.y}@${toString res.freq}";
in
{
options.displays =
{
enable = mkEnableOption "manage displays";
displays = mkOption {
type = types.listOf displayType;
default = [ ];
};
};
config = mkIf cfg.enable {
home-manager.users.${user}.imports = [
{
wayland.windowManager.hyprland.extraConfig = mkIf (cfg.displays != [ ])
(renderDisplaysForHyprland cfg.displays);
}
];
};
}