From de6fb52e254a7a91c1330066feb919afd4c823a0 Mon Sep 17 00:00:00 2001 From: Yorick Barbanneau Date: Mon, 19 Feb 2024 00:16:54 +0100 Subject: [PATCH] Add variables for thermal monitoring on waybar --- modules/home-manager/desktop/sway/default.nix | 37 +++++++++++++++++ .../desktop/sway/includes/waybar.nix | 41 +++++++++++++++---- 2 files changed, 71 insertions(+), 7 deletions(-) diff --git a/modules/home-manager/desktop/sway/default.nix b/modules/home-manager/desktop/sway/default.nix index ec4e4b3..70c4aff 100644 --- a/modules/home-manager/desktop/sway/default.nix +++ b/modules/home-manager/desktop/sway/default.nix @@ -12,6 +12,43 @@ in default = false; description = "configure laptop mode"; }; + + waybar = { + laptop = mkOption { + type = types.bool; + default = false; + description = "Enable laptop element on Waybar"; + }; + + cpuThermal = { + + hwmonPathAbs = mkOption { + type = types.str; + default = ""; + description = "CPU thermal hwmon absolute path"; + }; + + inputFilename = mkOption { + type = types.str; + default = ""; + description = "CPU thermal hwmon file"; + }; + }; + + gpuThermal = { + enable = mkOption { + type = types.bool; + default = false; + description = "enable waybar GPU temperature"; + }; + + hmonPath = mkOption { + type = types.str; + default = ""; + description = "Thermal zone for CPU"; + }; + }; + }; }; imports = [ ./includes/fuzzel.nix diff --git a/modules/home-manager/desktop/sway/includes/waybar.nix b/modules/home-manager/desktop/sway/includes/waybar.nix index 6c91c37..7ff9f80 100644 --- a/modules/home-manager/desktop/sway/includes/waybar.nix +++ b/modules/home-manager/desktop/sway/includes/waybar.nix @@ -1,7 +1,10 @@ -{config, lib, ...}: +{lib, config, ...}: with lib; +let + cfg = config.modules.desktop.sway; +in { - config = mkIf config.modules.desktop.sway.enable { + config = mkIf cfg.enable { programs.waybar = { enable = true; systemd = { @@ -21,12 +24,30 @@ with lib; modules-right = [ "network" "custom/sep" - "backlight" - "battery" - "custom/sep" + ] ++ ( + if cfg.waybar.laptop then [ + "backlight" + "battery" + "custom/sep" + ] + else [ + ] + ) ++ + [ + "memory" "cpu" - "custom/sep" + "temperature" + "custom/sep" + ] ++ ( + if cfg.waybar.gpuThermal.enable then [ + "temperature#gpu" + "custom/sep" + ] + else [ + ] + ) ++ + [ "pulseaudio" "custom/sep" "clock" @@ -100,7 +121,13 @@ with lib; "temperature" = { "critical-threshold" = 80; "format" = "{temperatureC}°C  "; - "thermal-zone" = "6"; + "hwmon-path-abs" = "${cfg.waybar.cpuThermal.hwmonPathAbs}"; + "input-filename" = "${cfg.waybar.cpuThermal.inputFilename}"; + }; + "temperature#gpu" = { + "critical-threshold" = 80; + "format" = "GPU: {temperatureC}°C  "; + "hwmon-path" = "${cfg.waybar.gpuThermal.hmonPath}"; }; "backlight" = { "format" = "{percent}% {icon}";