From 056ddf218355181a82807759bc344a6b685974b7 Mon Sep 17 00:00:00 2001 From: punkfairie Date: Sat, 11 Jan 2025 20:46:46 -0800 Subject: [PATCH] refactor(home): inherit (lib) -> lib. --- modules/home/wayland/hyprland/default.nix | 61 ++++++++--------------- 1 file changed, 21 insertions(+), 40 deletions(-) diff --git a/modules/home/wayland/hyprland/default.nix b/modules/home/wayland/hyprland/default.nix index 0820427..9d78534 100644 --- a/modules/home/wayland/hyprland/default.nix +++ b/modules/home/wayland/hyprland/default.nix @@ -6,43 +6,23 @@ pkgs, ... }: let - inherit - (lib) - mkEnableOption - mkOption - mkIf - length - attrNames - range - zipListsWith - subtractLists - sublist - mapAttrs - replicate - last - getExe - concatLists - attrValues - listToAttrs - ; - cfg = config.marleyos.wayland.hyprland; in { options.marleyos.wayland.hyprland = { - enable = mkEnableOption "hyprland"; + enable = lib.mkEnableOption "hyprland"; - monitors = mkOption { + monitors = lib.mkOption { description = "Monitor configuration."; type = with lib.types; attrsOf str; }; - mainMonitor = mkOption { + mainMonitor = lib.mkOption { description = "Which monitor to treat as the main for workspace assignment"; type = with lib.types; str; }; }; - config = mkIf cfg.enable { + config = lib.mkIf cfg.enable { assertions = [ { assertion = @@ -64,24 +44,24 @@ in { xwayland.enable = true; settings = let - numMonitors = length (attrNames (cfg.monitors or {})); - workspaces = range 1 10; + numMonitors = lib.length (lib.attrNames (cfg.monitors or {})); + workspaces = lib.range 1 10; wsPerMonitor = 10 / numMonitors; - mainMonWs = range 1 wsPerMonitor; - secondaryWs = subtractLists mainMonWs workspaces; + mainMonWs = lib.range 1 wsPerMonitor; + secondaryWs = lib.subtractLists mainMonWs workspaces; - monitors = mapAttrs (mon: _: + monitors = lib.mapAttrs (mon: _: if (mon == (cfg.mainMonitor or "")) then "" - else replicate wsPerMonitor "${mon}") + else lib.replicate wsPerMonitor "${mon}") (cfg.monitors or {}); secondaryMons = removeAttrs monitors [(cfg.mainMonitor or "")]; - monList = concatLists (attrValues secondaryMons); + monList = lib.concatLists (lib.attrValues secondaryMons); firstWsToMons = - zipListsWith (mon: ws: { + lib.zipListsWith (mon: ws: { name = toString ws; value = mon; }) @@ -89,13 +69,13 @@ in { secondaryWs; leftover = - sublist (length monList) (10 - (wsPerMonitor * numMonitors)) secondaryWs; + lib.sublist (lib.length monList) (10 - (wsPerMonitor * numMonitors)) secondaryWs; wsToMons = firstWsToMons ++ (map (ws: { name = toString ws; - value = last monList; + value = lib.last monList; }) leftover) ++ (map (ws: { @@ -104,13 +84,14 @@ in { }) mainMonWs); - wsMons = listToAttrs wsToMons; + wsMons = lib.listToAttrs wsToMons; in { - monitor = attrValues cfg.monitors; + monitor = lib.attrValues cfg.monitors; # TODO: Use overlay once it's made. - "$terminal" = getExe inputs.wezterm.packages."${system}".default; - "$launcher" = "${getExe pkgs.wofi} --show drun"; + # TODO: Set this in a default apps module. + "$terminal" = lib.getExe inputs.wezterm.packages."${system}".default; + "$launcher" = "${lib.getExe pkgs.wofi} --show drun"; exec-once = let browserWs = @@ -120,11 +101,11 @@ in { in [ "[workspace 1 silent] $terminal" # TODO: Change once waterfox is set up - "[workspace ${toString browserWs} silent] firefox" + "[workspace ${toString browserWs} silent] $browser" ]; workspace = - mkIf (cfg ? monitors) + lib.mkIf (cfg ? monitors) (map (ws: "${toString ws}, monitor:${wsMons."${toString ws}"}") workspaces);