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,
...
}: 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);