modularize gui

This commit is contained in:
Fabian Montero 2024-11-28 18:11:35 -06:00
parent 61eb9ed8c5
commit bcd049b8c5
13 changed files with 202 additions and 89 deletions

View file

@ -11,5 +11,6 @@
./steam
./yubikey.nix
./browsers.nix
./gui
];
}

View file

@ -0,0 +1,32 @@
{
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.local.gui;
in {
programs.autorandr = {
profiles."default" = {
fingerprint =
mapAttrs
(monitorId: monitor: monitor.fingerprint)
cfg.monitors;
config =
mapAttrs (
monitorId:
filterAttrs
(k: v:
!elem k [
#list of options to exclude from this list
"fingerprint"
"initialI3Workspace"
"monitorId"
])
)
cfg.monitors;
};
};
}

View file

@ -0,0 +1,116 @@
{
config,
pkgs,
lib,
...
}:
with lib; let
cfg = config.local.gui;
monitorType = {setName}: (
types.submodule ({name ? null, ...}: {
options = {
monitorId = mkOption {
type = types.str;
example = "DP-1";
readOnly = true;
internal = true;
};
primary = mkOption {
type = types.bool;
default = false;
description = "is primary monitor";
example = "true";
};
position = mkOption {
type = types.str;
example = "0x0";
};
mode = mkOption {
type = types.str;
description = "resolution";
default = "1920x1080";
example = "1920x1080";
};
rate = mkOption {
type = types.str;
description = "refresh rate";
example = "143.85";
};
rotate = mkOption {
type = types.str;
default = "normal";
example = "left";
};
fingerprint = mkOption {
type = types.str;
example = "00ffffffffffff003669a03bd4040000231e0104a5341d783bd005ac5048a627125054bfcf00814081809500714f81c0b30001010101023a801871382d40582c450009252100001e0882805070384d400820f80c09252100001a000000fd003090b4b422010a202020202020000000fc004d53492047323443340a20202001a2020320f14d010304131f120211900e0f1d1e230907078301000065030c001000866f80a0703840403020350009252100001a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e9";
};
initialI3Workspace = mkOption {
type = types.nullOr types.int;
default = null;
example = 1;
};
};
config = optionalAttrs setName {
# make this better later
monitorId = name;
};
})
);
in {
options.local.gui = {
enable = mkEnableOption "GUI settings";
primaryMonitor = mkOption {
type = monitorType {setName = false;};
readOnly = true;
internal = true;
};
monitors = mkOption {
type = types.attrsOf (monitorType {setName = true;});
};
displayBatteryLevel = mkOption {
type = types.bool;
default = false;
description = "show battery level on polybar";
example = "true";
};
};
imports = [
./autorandr.nix
./fonts.nix
./i3.nix
./polybar.nix
./startx.nix # move to ly once 24.11 comes out :(
./picom.nix
];
config = let
primaryMonitors =
filter (monitor: monitor.primary)
(attrValues cfg.monitors);
in
mkIf cfg.enable {
assertions = [
{
assertion = length primaryMonitors == 1;
message = "Exactly one (1) primary monitor is requiered.";
}
];
local.gui.primaryMonitor = head primaryMonitors;
xsession = {
enable = true;
windowManager.i3.enable = true;
};
programs.autorandr.enable = true;
services = {
dunst.enable = true;
betterlockscreen.enable = true;
polybar.enable = true;
picom.enable = true;
};
};
}

View file

@ -1,4 +1,3 @@
#TODO: do i really need to take all these args?
{
config,
lib,

View file

@ -6,7 +6,6 @@
}:
with lib; {
xsession.windowManager.i3 = {
enable = true;
package = pkgs.i3-gaps;
config = let
@ -87,17 +86,17 @@ with lib; {
}
];
workspaceOutputAssign = [
{
output = "DP-1";
workspace = "1";
}
{
output = "DP-2";
workspace = "10";
}
];
workspaceOutputAssign =
mapAttrsToList (
monitorId: v:
{
output = monitorId;
}
// optionalAttrs (v.initialI3Workspace != null) {
workspace = toString v.initialI3Workspace;
}
)
config.local.gui.monitors;
bars = [];
};
};

View file

@ -5,7 +5,6 @@
...
}: {
services.picom = {
enable = true;
fade = true;
fadeSteps = [0.1 0.1];
fadeDelta = 10;

View file

@ -6,7 +6,6 @@
}:
with lib; {
services.polybar = {
enable = true;
package = pkgs.polybarFull;
script = ''
# Terminate already running bar instances
@ -33,7 +32,7 @@ with lib; {
};
"bar/main" = {
monitor = "DP-1";
monitor = config.local.gui.primaryMonitor.monitorId;
width = "100%";
height = 30;
offset-x = "0%";
@ -82,7 +81,9 @@ with lib; {
};
"bar/secondary" = {
monitor = "DP-2";
monitor = head (attrNames (filterAttrs (monitorId: v:
!v.primary)
config.local.gui.monitors)); # this is bad. will fail if more than 2 monitors. this sets all monitors other than the primary one for this bar.
"inherit" = "bar/main";
modules-left = "i3";

View file

@ -0,0 +1,16 @@
{
config,
lib,
pkgs,
...
}:
with lib; {
config = mkIf config.local.gui.enable {
home.file.".xinitrc".source = let
content = ''
exec ~/.xsession
'';
in
pkgs.writeShellScript "xinitrc" content;
};
}

View file

@ -8,7 +8,6 @@
imports = [
./apps.nix
./systemd
./gui
./isolation.nix
];
@ -22,6 +21,28 @@
"unstable".flake = flakes.unstable;
};
local.gui = {
enable = true;
#? wallpaperPath = ""; place wallpaper in config?
monitors = {
DP-1 = {
primary = true;
position = "0x0";
mode = "1920x1080";
rate = "143.85";
fingerprint = "00ffffffffffff003669a03bd4040000231e0104a5341d783bd005ac5048a627125054bfcf00814081809500714f81c0b30001010101023a801871382d40582c450009252100001e0882805070384d400820f80c09252100001a000000fd003090b4b422010a202020202020000000fc004d53492047323443340a20202001a2020320f14d010304131f120211900e0f1d1e230907078301000065030c001000866f80a0703840403020350009252100001a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e9";
initialI3Workspace = 1;
};
DP-2 = {
position = "1920x0";
mode = "1920x1080";
rate = "59.94";
fingerprint = "00ffffffffffff0009d1e77845540000061f0104a5351e783a0565a756529c270f5054a56b80d1c0b300a9c08180810081c001010101023a801871382d40582c45000f282100001e000000ff0039324d30303033323031510a20000000fd00324c1e5311010a202020202020000000fc0042656e51204757323438300a20019b02031cf14f901f041303120211011406071516052309070783010000023a801871382d40582c45000f282100001f011d8018711c1620582c25000f282100009f011d007251d01e206e2855000f282100001e8c0ad08a20e02d10103e96000f28210000180000000000000000000000000000000000000000000000000000008d";
initialI3Workspace = 10;
};
};
};
home = {
stateVersion = "21.11"; # No tocar esto
username = "fabian";

View file

@ -1,35 +0,0 @@
{
config,
lib,
pkgs,
...
}: {
programs.autorandr = {
enable = true;
profiles."posixlycorrect" = {
fingerprint = {
DP-1 = "00ffffffffffff003669a03bd4040000231e0104a5341d783bd005ac5048a627125054bfcf00814081809500714f81c0b30001010101023a801871382d40582c450009252100001e0882805070384d400820f80c09252100001a000000fd003090b4b422010a202020202020000000fc004d53492047323443340a20202001a2020320f14d010304131f120211900e0f1d1e230907078301000065030c001000866f80a0703840403020350009252100001a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e9";
DP-2 = "00ffffffffffff0009d1e77845540000061f0104a5351e783a0565a756529c270f5054a56b80d1c0b300a9c08180810081c001010101023a801871382d40582c45000f282100001e000000ff0039324d30303033323031510a20000000fd00324c1e5311010a202020202020000000fc0042656e51204757323438300a20019b02031cf14f901f041303120211011406071516052309070783010000023a801871382d40582c45000f282100001f011d8018711c1620582c25000f282100009f011d007251d01e206e2855000f282100001e8c0ad08a20e02d10103e96000f28210000180000000000000000000000000000000000000000000000000000008d";
};
config = {
DP-1 = {
enable = true;
primary = true;
position = "0x0";
mode = "1920x1080";
rate = "143.85";
rotate = "normal";
};
DP-2 = {
enable = true;
primary = false;
position = "1920x0";
mode = "1920x1080";
rate = "59.94";
rotate = "normal";
};
};
};
};
}

View file

@ -1,20 +0,0 @@
{
config,
pkgs,
lib,
...
}: {
imports = [
./autorandr.nix
./fonts.nix
./i3.nix
./polybar.nix
./startx.nix
./picom.nix
];
services = {
dunst.enable = true;
betterlockscreen.enable = true;
};
}

View file

@ -1,16 +0,0 @@
{
config,
lib,
pkgs,
...
}:
with lib; {
xsession.enable = true;
home.file.".xinitrc".source = let
content = ''
exec ~/.xsession
'';
in
pkgs.writeShellScript "xinitrc" content;
}