diff --git a/configs/nixos/modules/desktop/default.nix b/configs/nixos/modules/desktop/default.nix index cfe5592..800cc22 100644 --- a/configs/nixos/modules/desktop/default.nix +++ b/configs/nixos/modules/desktop/default.nix @@ -19,7 +19,6 @@ modules.desktop.utilities.audio.enable = lib.mkDefault true; modules.desktop.utilities.clipboard.enable = lib.mkDefault true; modules.desktop.utilities.osd.enable = lib.mkDefault true; - modules.desktop.utilities.network.enable = lib.mkDefault true; modules.desktop.utilities.recording.enable = lib.mkDefault true; modules.desktop.utilities.screenshot.enable = lib.mkDefault true; modules.desktop.utilities.theming.enable = lib.mkDefault true; diff --git a/configs/nixos/modules/desktop/session/waybar.nix b/configs/nixos/modules/desktop/session/waybar.nix index b8c29de..4a56b9b 100644 --- a/configs/nixos/modules/desktop/session/waybar.nix +++ b/configs/nixos/modules/desktop/session/waybar.nix @@ -34,6 +34,38 @@ let # through JSON so the glyph survives as bytes rather than an editor paste. g = code: builtins.fromJSON ''"\u${code}"''; + networkStatus = pkgs.writeShellScript "waybar-network-status" '' + active=$( + ${lib.getExe' pkgs.networkmanager "nmcli"} -t -f DEVICE,TYPE,STATE,CONNECTION device status \ + | ${lib.getExe' pkgs.gawk "awk"} -F: '$3 == "connected" && $2 != "loopback" { print; exit }' + ) + + if [ -z "$active" ]; then + ${lib.getExe pkgs.jq} -cn \ + --arg text "${g "f127"} off" \ + --arg tooltip "Network disconnected" \ + --arg class "disconnected" \ + '{ text: $text, tooltip: $tooltip, class: $class }' + exit 0 + fi + + IFS=: read -r device type _state connection <<< "$active" + + case "$type" in + wifi) icon="${g "f1eb"}" ;; + ethernet) icon="LAN" ;; + *) icon="NET" ;; + esac + + ipaddr=$(${lib.getExe' pkgs.iproute2 "ip"} -4 -o addr show dev "$device" | ${lib.getExe' pkgs.gawk "awk"} '{ print $4; exit }') + + ${lib.getExe pkgs.jq} -cn \ + --arg text "$icon $connection" \ + --arg tooltip "$device: ''${ipaddr:-no IPv4}" \ + --arg class "$type" \ + '{ text: $text, tooltip: $tooltip, class: $class }' + ''; + in { options.modules.desktop.session.waybar.enable = lib.mkEnableOption "the Waybar status bar"; @@ -88,6 +120,15 @@ in }; }; + "custom/network" = { + order = 60; + settings = { + return-type = "json"; + exec = "${networkStatus}"; + interval = 5; + }; + }; + battery = { order = 70; settings = { diff --git a/configs/nixos/modules/desktop/utilities/network.nix b/configs/nixos/modules/desktop/utilities/network.nix deleted file mode 100644 index 02b40d7..0000000 --- a/configs/nixos/modules/desktop/utilities/network.nix +++ /dev/null @@ -1,57 +0,0 @@ -{ - config, - lib, - pkgs, - ... -}: -# Desktop network status integrations. -let - glyph = code: builtins.fromJSON ''"\u${code}"''; - - networkStatus = pkgs.writeShellScript "waybar-network-status" '' - active=$( - ${lib.getExe' pkgs.networkmanager "nmcli"} -t -f DEVICE,TYPE,STATE,CONNECTION device status \ - | ${lib.getExe' pkgs.gawk "awk"} -F: '$3 == "connected" && $2 != "loopback" { print; exit }' - ) - - if [ -z "$active" ]; then - ${lib.getExe pkgs.jq} -cn \ - --arg text "${glyph "f127"} off" \ - --arg tooltip "Network disconnected" \ - --arg class "disconnected" \ - '{ text: $text, tooltip: $tooltip, class: $class }' - exit 0 - fi - - IFS=: read -r device type _state connection <<< "$active" - - case "$type" in - wifi) icon="${glyph "f1eb"}" ;; - ethernet) icon="LAN" ;; - *) icon="NET" ;; - esac - - ipaddr=$(${lib.getExe' pkgs.iproute2 "ip"} -4 -o addr show dev "$device" | ${lib.getExe' pkgs.gawk "awk"} '{ print $4; exit }') - - ${lib.getExe pkgs.jq} -cn \ - --arg text "$icon $connection" \ - --arg tooltip "$device: ''${ipaddr:-no IPv4}" \ - --arg class "$type" \ - '{ text: $text, tooltip: $tooltip, class: $class }' - ''; -in -{ - options.modules.desktop.utilities.network.enable = - lib.mkEnableOption "desktop network status integration"; - - config = lib.mkIf config.modules.desktop.utilities.network.enable { - registry.waybar.${config.networking.hostName}."custom/network" = { - order = 60; - settings = { - return-type = "json"; - exec = "${networkStatus}"; - interval = 5; - }; - }; - }; -}