From bcd049b8c528b656de41093ea1be0e4aa969b164 Mon Sep 17 00:00:00 2001 From: Fabian Montero Date: Thu, 28 Nov 2024 18:11:35 -0600 Subject: [PATCH] modularize gui --- home/modules/default.nix | 1 + home/modules/gui/autorandr.nix | 32 +++++ home/modules/gui/default.nix | 116 ++++++++++++++++++ .../gui/fonts.nix | 0 .../gui/gtk.nix | 1 - .../gui/i3.nix | 23 ++-- .../gui/picom.nix | 1 - .../gui/polybar.nix | 7 +- home/modules/gui/startx.nix | 16 +++ .../fabian@posixlycorrect/default.nix | 23 +++- .../fabian@posixlycorrect/gui/autorandr.nix | 35 ------ .../fabian@posixlycorrect/gui/default.nix | 20 --- .../fabian@posixlycorrect/gui/startx.nix | 16 --- 13 files changed, 202 insertions(+), 89 deletions(-) create mode 100644 home/modules/gui/autorandr.nix create mode 100644 home/modules/gui/default.nix rename home/{platforms/fabian@posixlycorrect => modules}/gui/fonts.nix (100%) rename home/{platforms/fabian@posixlycorrect => modules}/gui/gtk.nix (72%) rename home/{platforms/fabian@posixlycorrect => modules}/gui/i3.nix (88%) rename home/{platforms/fabian@posixlycorrect => modules}/gui/picom.nix (97%) rename home/{platforms/fabian@posixlycorrect => modules}/gui/polybar.nix (97%) create mode 100644 home/modules/gui/startx.nix delete mode 100644 home/platforms/fabian@posixlycorrect/gui/autorandr.nix delete mode 100644 home/platforms/fabian@posixlycorrect/gui/default.nix delete mode 100644 home/platforms/fabian@posixlycorrect/gui/startx.nix diff --git a/home/modules/default.nix b/home/modules/default.nix index f5bf6d5..0ac2c86 100644 --- a/home/modules/default.nix +++ b/home/modules/default.nix @@ -11,5 +11,6 @@ ./steam ./yubikey.nix ./browsers.nix + ./gui ]; } diff --git a/home/modules/gui/autorandr.nix b/home/modules/gui/autorandr.nix new file mode 100644 index 0000000..ed35e99 --- /dev/null +++ b/home/modules/gui/autorandr.nix @@ -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; + }; + }; +} diff --git a/home/modules/gui/default.nix b/home/modules/gui/default.nix new file mode 100644 index 0000000..9dcf14c --- /dev/null +++ b/home/modules/gui/default.nix @@ -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; + }; + }; +} diff --git a/home/platforms/fabian@posixlycorrect/gui/fonts.nix b/home/modules/gui/fonts.nix similarity index 100% rename from home/platforms/fabian@posixlycorrect/gui/fonts.nix rename to home/modules/gui/fonts.nix diff --git a/home/platforms/fabian@posixlycorrect/gui/gtk.nix b/home/modules/gui/gtk.nix similarity index 72% rename from home/platforms/fabian@posixlycorrect/gui/gtk.nix rename to home/modules/gui/gtk.nix index eae736f..fdd2712 100644 --- a/home/platforms/fabian@posixlycorrect/gui/gtk.nix +++ b/home/modules/gui/gtk.nix @@ -1,4 +1,3 @@ -#TODO: do i really need to take all these args? { config, lib, diff --git a/home/platforms/fabian@posixlycorrect/gui/i3.nix b/home/modules/gui/i3.nix similarity index 88% rename from home/platforms/fabian@posixlycorrect/gui/i3.nix rename to home/modules/gui/i3.nix index d38e9f2..1ed3030 100644 --- a/home/platforms/fabian@posixlycorrect/gui/i3.nix +++ b/home/modules/gui/i3.nix @@ -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 = []; }; }; diff --git a/home/platforms/fabian@posixlycorrect/gui/picom.nix b/home/modules/gui/picom.nix similarity index 97% rename from home/platforms/fabian@posixlycorrect/gui/picom.nix rename to home/modules/gui/picom.nix index 22a18ab..8807f67 100644 --- a/home/platforms/fabian@posixlycorrect/gui/picom.nix +++ b/home/modules/gui/picom.nix @@ -5,7 +5,6 @@ ... }: { services.picom = { - enable = true; fade = true; fadeSteps = [0.1 0.1]; fadeDelta = 10; diff --git a/home/platforms/fabian@posixlycorrect/gui/polybar.nix b/home/modules/gui/polybar.nix similarity index 97% rename from home/platforms/fabian@posixlycorrect/gui/polybar.nix rename to home/modules/gui/polybar.nix index c6bf6d2..8012b3b 100644 --- a/home/platforms/fabian@posixlycorrect/gui/polybar.nix +++ b/home/modules/gui/polybar.nix @@ -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"; diff --git a/home/modules/gui/startx.nix b/home/modules/gui/startx.nix new file mode 100644 index 0000000..6aaaf9f --- /dev/null +++ b/home/modules/gui/startx.nix @@ -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; + }; +} diff --git a/home/platforms/fabian@posixlycorrect/default.nix b/home/platforms/fabian@posixlycorrect/default.nix index b24596e..03f82b4 100644 --- a/home/platforms/fabian@posixlycorrect/default.nix +++ b/home/platforms/fabian@posixlycorrect/default.nix @@ -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"; diff --git a/home/platforms/fabian@posixlycorrect/gui/autorandr.nix b/home/platforms/fabian@posixlycorrect/gui/autorandr.nix deleted file mode 100644 index d645250..0000000 --- a/home/platforms/fabian@posixlycorrect/gui/autorandr.nix +++ /dev/null @@ -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"; - }; - }; - }; - }; -} diff --git a/home/platforms/fabian@posixlycorrect/gui/default.nix b/home/platforms/fabian@posixlycorrect/gui/default.nix deleted file mode 100644 index dd66640..0000000 --- a/home/platforms/fabian@posixlycorrect/gui/default.nix +++ /dev/null @@ -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; - }; -} diff --git a/home/platforms/fabian@posixlycorrect/gui/startx.nix b/home/platforms/fabian@posixlycorrect/gui/startx.nix deleted file mode 100644 index d19e317..0000000 --- a/home/platforms/fabian@posixlycorrect/gui/startx.nix +++ /dev/null @@ -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; -}