refactor(home): inherit (lib) -> lib.

This commit is contained in:
punkfairie 2025-01-11 20:46:46 -08:00
parent 69ab87b164
commit 056ddf2183
No known key found for this signature in database
GPG key ID: B3C5488E9A1A7CA6

View file

@ -6,43 +6,23 @@
pkgs, pkgs,
... ...
}: let }: let
inherit
(lib)
mkEnableOption
mkOption
mkIf
length
attrNames
range
zipListsWith
subtractLists
sublist
mapAttrs
replicate
last
getExe
concatLists
attrValues
listToAttrs
;
cfg = config.marleyos.wayland.hyprland; cfg = config.marleyos.wayland.hyprland;
in { in {
options.marleyos.wayland.hyprland = { options.marleyos.wayland.hyprland = {
enable = mkEnableOption "hyprland"; enable = lib.mkEnableOption "hyprland";
monitors = mkOption { monitors = lib.mkOption {
description = "Monitor configuration."; description = "Monitor configuration.";
type = with lib.types; attrsOf str; type = with lib.types; attrsOf str;
}; };
mainMonitor = mkOption { mainMonitor = lib.mkOption {
description = "Which monitor to treat as the main for workspace assignment"; description = "Which monitor to treat as the main for workspace assignment";
type = with lib.types; str; type = with lib.types; str;
}; };
}; };
config = mkIf cfg.enable { config = lib.mkIf cfg.enable {
assertions = [ assertions = [
{ {
assertion = assertion =
@ -64,24 +44,24 @@ in {
xwayland.enable = true; xwayland.enable = true;
settings = let settings = let
numMonitors = length (attrNames (cfg.monitors or {})); numMonitors = lib.length (lib.attrNames (cfg.monitors or {}));
workspaces = range 1 10; workspaces = lib.range 1 10;
wsPerMonitor = 10 / numMonitors; wsPerMonitor = 10 / numMonitors;
mainMonWs = range 1 wsPerMonitor; mainMonWs = lib.range 1 wsPerMonitor;
secondaryWs = subtractLists mainMonWs workspaces; secondaryWs = lib.subtractLists mainMonWs workspaces;
monitors = mapAttrs (mon: _: monitors = lib.mapAttrs (mon: _:
if (mon == (cfg.mainMonitor or "")) if (mon == (cfg.mainMonitor or ""))
then "" then ""
else replicate wsPerMonitor "${mon}") else lib.replicate wsPerMonitor "${mon}")
(cfg.monitors or {}); (cfg.monitors or {});
secondaryMons = removeAttrs monitors [(cfg.mainMonitor or "")]; secondaryMons = removeAttrs monitors [(cfg.mainMonitor or "")];
monList = concatLists (attrValues secondaryMons); monList = lib.concatLists (lib.attrValues secondaryMons);
firstWsToMons = firstWsToMons =
zipListsWith (mon: ws: { lib.zipListsWith (mon: ws: {
name = toString ws; name = toString ws;
value = mon; value = mon;
}) })
@ -89,13 +69,13 @@ in {
secondaryWs; secondaryWs;
leftover = leftover =
sublist (length monList) (10 - (wsPerMonitor * numMonitors)) secondaryWs; lib.sublist (lib.length monList) (10 - (wsPerMonitor * numMonitors)) secondaryWs;
wsToMons = wsToMons =
firstWsToMons firstWsToMons
++ (map (ws: { ++ (map (ws: {
name = toString ws; name = toString ws;
value = last monList; value = lib.last monList;
}) })
leftover) leftover)
++ (map (ws: { ++ (map (ws: {
@ -104,13 +84,14 @@ in {
}) })
mainMonWs); mainMonWs);
wsMons = listToAttrs wsToMons; wsMons = lib.listToAttrs wsToMons;
in { in {
monitor = attrValues cfg.monitors; monitor = lib.attrValues cfg.monitors;
# TODO: Use overlay once it's made. # TODO: Use overlay once it's made.
"$terminal" = getExe inputs.wezterm.packages."${system}".default; # TODO: Set this in a default apps module.
"$launcher" = "${getExe pkgs.wofi} --show drun"; "$terminal" = lib.getExe inputs.wezterm.packages."${system}".default;
"$launcher" = "${lib.getExe pkgs.wofi} --show drun";
exec-once = let exec-once = let
browserWs = browserWs =
@ -120,11 +101,11 @@ in {
in [ in [
"[workspace 1 silent] $terminal" "[workspace 1 silent] $terminal"
# TODO: Change once waterfox is set up # TODO: Change once waterfox is set up
"[workspace ${toString browserWs} silent] firefox" "[workspace ${toString browserWs} silent] $browser"
]; ];
workspace = workspace =
mkIf (cfg ? monitors) lib.mkIf (cfg ? monitors)
(map (map
(ws: "${toString ws}, monitor:${wsMons."${toString ws}"}") (ws: "${toString ws}, monitor:${wsMons."${toString ws}"}")
workspaces); workspaces);