From 1a62545c3cc62bd42bc4445470d14e456bfebc97 Mon Sep 17 00:00:00 2001 From: LavaDesu Date: Sun, 23 Mar 2025 12:36:07 +1100 Subject: [PATCH] user/{eww,hypridle,hyprlock}: configure based on options.me --- modules/options.nix | 39 ++++++++++++++++++++++++++++++++------- modules/user/eww.nix | 13 ++++++++++--- modules/user/hypridle.nix | 6 ++++-- modules/user/hyprlock.nix | 33 ++++++++++++++++++--------------- res/eww/eww.yuck | 24 ++++++++++++++---------- 5 files changed, 78 insertions(+), 37 deletions(-) diff --git a/modules/options.nix b/modules/options.nix index 9b8f45a..c47f438 100644 --- a/modules/options.nix +++ b/modules/options.nix @@ -1,18 +1,43 @@ -{ config, lib, ... }: { +{ config, lib, ... }: +let + inherit (lib) + mkOption + types; +in { options.me = { - environment = lib.mkOption { - type = lib.types.enum [ "desktop" "laptop" "headless" ]; + environment = mkOption { + type = types.enum [ "desktop" "laptop" "headless" ]; default = "desktop"; }; - fprint = lib.mkOption { - type = lib.types.bool; + fprint = mkOption { + type = types.bool; default = false; }; - gui = lib.mkOption { - type = lib.types.bool; + gui = mkOption { + type = types.bool; default = config.me.environment != "headless"; }; + + batteryDevice = mkOption { + type = types.nullOr types.string; + default = null; + }; + + kbBacklightDevice = mkOption { + type = types.nullOr types.string; + default = null; + }; + + hasBluetooth = mkOption { + type = types.bool; + default = config.me.environment == "laptop"; + }; + + hasWifi = mkOption { + type = types.bool; + default = config.me.environment == "laptop"; + }; }; } diff --git a/modules/user/eww.nix b/modules/user/eww.nix index 193b546..7cd123f 100644 --- a/modules/user/eww.nix +++ b/modules/user/eww.nix @@ -6,10 +6,17 @@ let dontUnpack = true; installPhase = '' cp -r ${../../res/eww} $out + + substituteInPlace $out/eww.yuck \ + --replace-fail "_BAT_ENABLED_" "${config.me.batteryPath != null}" \ + --replace-fail "_BAT_PATH_" "${config.me.batteryPATH}" \ + --replace-fail "_BT_ENABLED_" "${config.me.hasBluetooth}" \ + --replace-fail "_WIFI_ENABLED_" "${config.me.hasWifi}" + substituteInPlace $out/eww.scss \ - --replace-warn "EWW_BACKGROUND" "${config.catppuccin.hexcolors.crust}" \ - --replace-warn "EWW_TEXT" "${config.catppuccin.hexcolors.text}" \ - --replace-warn "EWW_ACCENT" "${config.catppuccin.hexcolors.${config.catppuccin.accent}}" + --replace-fail "EWW_BACKGROUND" "${config.catppuccin.hexcolors.crust}" \ + --replace-fail "EWW_TEXT" "${config.catppuccin.hexcolors.text}" \ + --replace-fail "EWW_ACCENT" "${config.catppuccin.hexcolors.${config.catppuccin.accent}}" ''; }; in { diff --git a/modules/user/hypridle.nix b/modules/user/hypridle.nix index 9ee5f26..68203b1 100644 --- a/modules/user/hypridle.nix +++ b/modules/user/hypridle.nix @@ -1,6 +1,6 @@ { config, lib, pkgs, ... }: let - kblight = "light -s sysfs/leds/asus::kbd_backlight"; + kblight = "light -s sysfs/leds/${config.me.kbBacklightDevice}"; in { home.packages = [ config.services.hypridle.package ]; @@ -13,12 +13,13 @@ in after_sleep_cmd = "hyprctl dispatch dpms on"; }; - listener = [ + listener = lib.optionals (config.me.kbBacklightDevice != null) [ { timeout = 120; on-timeout = "${kblight} -O && ${kblight} -S 0"; on-resume = "${kblight} -I"; } + ] ++ [ { timeout = 150; on-timeout = "light -O && light -T 0.5"; @@ -33,6 +34,7 @@ in on-timeout = "hyprctl dispatch dpms off"; on-resume = "hyprctl dispatch dpms on"; } + ] ++ lib.optionals (config.me.environment == "laptop") [ { timeout = 600; on-timeout = "systemctl suspend"; diff --git a/modules/user/hyprlock.nix b/modules/user/hyprlock.nix index c99fd84..dfab271 100644 --- a/modules/user/hyprlock.nix +++ b/modules/user/hyprlock.nix @@ -1,4 +1,4 @@ -{ ... }: { +{ config, lib, ... }: { programs.hyprlock = { enable = true; settings = { @@ -8,7 +8,7 @@ }; auth = { fingerprint = { - enabled = true; + enabled = config.me.fprint; ready_message = "Scan fingerprint to unlock"; }; }; @@ -38,7 +38,7 @@ position = "-40,-10"; } ]; - label = [ + label = lib.optionals config.me.fprint [ # Fingerprint icon { monitor = ""; @@ -61,17 +61,7 @@ halign = "center"; valign = "top"; } - # Fail text under input - { - monitor = ""; - color = "$red"; - font_family = "Open Sans"; - font_size = 25; - text = "$FAIL $ATTEMPTS[]"; - position = "0, -200"; - halign = "center"; - valign = "center"; - } + ] ++ lib.optionals (config.me.batteryDevice != null) [ # Battery icon { monitor = ""; @@ -86,7 +76,7 @@ # Battery percentage { monitor = ""; - text = ''cmd[update:60000] echo "$(cat /sys/class/power_supply/BATT/capacity)%"''; + text = ''cmd[update:60000] echo "$(cat /sys/class/power_supply/${config.me.batteryDevice}/capacity)%"''; color = "$text"; font_size = 23; font_family = "Open Sans"; @@ -94,6 +84,7 @@ halign = "right"; valign = "top"; } + ] ++ [ # Time and Date { monitor = ""; @@ -105,6 +96,18 @@ position = "-70, -20"; text = ''cmd[update:1000] echo "$(date '+%A, %d %B %Y') $(date +%H:%M)$(date +:%S)"''; } + + # Fail text under input + { + monitor = ""; + color = "$red"; + font_family = "Open Sans"; + font_size = 25; + text = "$FAIL $ATTEMPTS[]"; + position = "0, -200"; + halign = "center"; + valign = "center"; + } ]; input-field = { monitor = ""; diff --git a/res/eww/eww.yuck b/res/eww/eww.yuck index 08b41ce..c153154 100644 --- a/res/eww/eww.yuck +++ b/res/eww/eww.yuck @@ -20,27 +20,31 @@ :focusable false (bar)) +(defvar bat-enabled _BAT_ENABLED_) +(defvar bt-enabled _BT_ENABLED_) +(defvar wifi-enabled _WIFI_ENABLED_) (defvar bat-extended true) (defvar bluetooth-extended false) (defvar network-extended false) (defvar time-extended false) + (defpoll ptime :interval "1s" `date +%H:%M`) (defpoll petimea :interval "1s" :run-while time-extended `date "+%A, %d %B %Y "`) (defpoll petimeb :interval "1s" :run-while time-extended `date "+:%S"`) -(defpoll pbat_cap :interval "5s" - `cat /sys/class/power_supply/BATT/capacity`) -(defpoll pbat_status :interval "1s" - `cat /sys/class/power_supply/BATT/status`) -(defpoll network_strength :interval "1s" +(defpoll pbat_cap :interval "5s" :run-while bat-enabled + `cat /sys/class/power_supply/_BAT_PATH_/capacity`) +(defpoll pbat_status :interval "1s" :run-while bat-enabled + `cat /sys/class/power_supply/_BAT_PATH_/status`) +(defpoll network_strength :interval "1s" :run-while wifi-enabled `nmcli -f IN-USE,SIGNAL device wifi | grep '*' | tr -d -c 0-9`) -(defpoll bluetooth_device :interval "1s" +(defpoll bluetooth_device :interval "1s" :run-while bt-enabled `bluetoothctl devices Connected | grep Device | cut -d" " -f3-`) -(deflisten lnetwork :initial "" "./scripts/network.sh") +(deflisten lnetwork :initial "" :run-while wifi-enabled "./scripts/network.sh") (deflisten ltitle :initial "" "./scripts/title.sh") (deflisten lworkspaces :initial "[]" "./scripts/workspaces.sh") (deflisten lcurrent_workspace :initial "1" "./scripts/active-workspace.sh") @@ -79,9 +83,9 @@ (box :orientation "horizontal" :space-evenly false :halign "end" - (bluetooth) - (network) - (battery) + (box :visible {bt-enabled} (bluetooth)) + (box :visible {wifi-enabled} (network)) + (box :visible {bat-enabled} (battery)) (time))) (defwidget bluetooth []