From e4161bfed9e631c57837f9c5573704b376e975ca Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 13 Jun 2024 23:33:14 +0100 Subject: [PATCH] dwmblocks sb scripts --- home/common/core/default.nix | 9 +++- .../optional/desktop/common/default.nix | 6 +-- .../desktop/{startx => dwm}/default.nix | 15 +++++++ .../optional/desktop/hyprland/default.nix | 1 - .../optional/desktop/status-bar/default.nix | 10 +++++ .../optional/desktop/status-bar/sb-cpu-pct.sh | 1 + .../optional/desktop/status-bar/sb-mem-pct.sh | 3 ++ .../desktop/status-bar/sb-network-status.sh | 43 +++++++++++++++++++ .../optional/desktop/status-bar/sb-updates.sh | 6 +++ .../optional/desktop/status-bar/sb-volume.sh | 41 ++++++++++++++++++ home/common/optional/git.nix | 2 +- home/semita.nix | 2 +- pkgs/default.nix | 1 + pkgs/dwmblocks/default.nix | 26 ++++++----- pkgs/st/default.nix | 4 +- 15 files changed, 147 insertions(+), 23 deletions(-) rename home/common/optional/desktop/{startx => dwm}/default.nix (73%) create mode 100644 home/common/optional/desktop/status-bar/default.nix create mode 100644 home/common/optional/desktop/status-bar/sb-cpu-pct.sh create mode 100644 home/common/optional/desktop/status-bar/sb-mem-pct.sh create mode 100644 home/common/optional/desktop/status-bar/sb-network-status.sh create mode 100644 home/common/optional/desktop/status-bar/sb-updates.sh create mode 100644 home/common/optional/desktop/status-bar/sb-volume.sh diff --git a/home/common/core/default.nix b/home/common/core/default.nix index 7338634..96d29e5 100644 --- a/home/common/core/default.nix +++ b/home/common/core/default.nix @@ -1,4 +1,4 @@ -{ pkgs, inputs, ... }: +{ pkgs, inputs, outputs, ... }: { imports = [ inputs.nix-colors.homeManagerModules.default @@ -7,6 +7,11 @@ ./fonts.nix ]; + nixpkgs.overlays = [ + inputs.nur.overlay + outputs.overlays.additions + ]; + # Global home packages without config go here (for all hosts and users) home.packages = builtins.attrValues { inherit (pkgs) @@ -20,7 +25,7 @@ btop htop postgresql - hugo + bc ; }; home.stateVersion = "23.11"; diff --git a/home/common/optional/desktop/common/default.nix b/home/common/optional/desktop/common/default.nix index 49c9fd1..58b2ba4 100644 --- a/home/common/optional/desktop/common/default.nix +++ b/home/common/optional/desktop/common/default.nix @@ -1,14 +1,10 @@ -{ pkgs, inputs, ... }: { +{ pkgs, ... }: { imports = [ ./firefox.nix ./alacritty.nix ./zotero.nix ]; - nixpkgs.overlays = [ - inputs.nur.overlay - ]; - # Global packages for desktop environments home.packages = [ pkgs.alacritty diff --git a/home/common/optional/desktop/startx/default.nix b/home/common/optional/desktop/dwm/default.nix similarity index 73% rename from home/common/optional/desktop/startx/default.nix rename to home/common/optional/desktop/dwm/default.nix index cef6462..975f7e3 100644 --- a/home/common/optional/desktop/startx/default.nix +++ b/home/common/optional/desktop/dwm/default.nix @@ -1,6 +1,13 @@ +{ pkgs, ... }: { + imports = [ ../common + ../status-bar + ]; + + home.packages = [ + pkgs.dwmblocks ]; # TODO configure x11 to look in .config/x11 @@ -8,6 +15,14 @@ home.file.".xinitrc" = { recursive = true; text = '' + + autostart="dwmblocks" + + for program in $autostart; do + pidof -sx "$program" || "$program" & + done >/dev/null 2>&1 + + if test -z "$DBUS_SESSION_BUS_ADDRESS"; then eval $(dbus-launch --exit-with-session --sh-syntax) fi diff --git a/home/common/optional/desktop/hyprland/default.nix b/home/common/optional/desktop/hyprland/default.nix index 563323c..eac93c1 100644 --- a/home/common/optional/desktop/hyprland/default.nix +++ b/home/common/optional/desktop/hyprland/default.nix @@ -1,6 +1,5 @@ { lib , config -, pkgs , ... }: { diff --git a/home/common/optional/desktop/status-bar/default.nix b/home/common/optional/desktop/status-bar/default.nix new file mode 100644 index 0000000..7e749cc --- /dev/null +++ b/home/common/optional/desktop/status-bar/default.nix @@ -0,0 +1,10 @@ +{ pkgs, ... }: +{ + home.packages = [ + (pkgs.writeShellScriptBin "sb-cpu-pct" (builtins.readFile ./sb-cpu-pct.sh)) + (pkgs.writeShellScriptBin "sb-mem-pct" (builtins.readFile ./sb-mem-pct.sh)) + (pkgs.writeShellScriptBin "sb-volume" (builtins.readFile ./sb-volume.sh)) + (pkgs.writeShellScriptBin "sb-network-status" (builtins.readFile ./sb-network-status.sh)) + (pkgs.writeShellScriptBin "sb-updates" (builtins.readFile ./sb-updates.sh)) + ]; +} diff --git a/home/common/optional/desktop/status-bar/sb-cpu-pct.sh b/home/common/optional/desktop/status-bar/sb-cpu-pct.sh new file mode 100644 index 0000000..ab61fb9 --- /dev/null +++ b/home/common/optional/desktop/status-bar/sb-cpu-pct.sh @@ -0,0 +1 @@ +echo $(top -bn 1 |grep "Cpu(s)" | awk '{print $2+$6 "%"}' | sed "s/\..//g") diff --git a/home/common/optional/desktop/status-bar/sb-mem-pct.sh b/home/common/optional/desktop/status-bar/sb-mem-pct.sh new file mode 100644 index 0000000..158d95b --- /dev/null +++ b/home/common/optional/desktop/status-bar/sb-mem-pct.sh @@ -0,0 +1,3 @@ +# Gets current ram percent utilisation + +echo $(free | awk '/^Mem/ {print "100*" $3 " / " $2 }' | bc | awk '{print $1"%"}') diff --git a/home/common/optional/desktop/status-bar/sb-network-status.sh b/home/common/optional/desktop/status-bar/sb-network-status.sh new file mode 100644 index 0000000..d8e09ef --- /dev/null +++ b/home/common/optional/desktop/status-bar/sb-network-status.sh @@ -0,0 +1,43 @@ +# Nerd Font Symbols +wifi_symbol=" " +lan_symbol="󰌗 " +disconnected_symbol="󰲜 " +vpn_symbol="󰖂 " +internet="󰞉 " +internet_disconnected="󰪎 " + +# Get the network status +DEFAULT_INTERFACE=$(ip route | grep '^default' | awk '{print $5}' | uniq) +IP_ADDRESS=$(ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p') + +if [ -z "$DEFAULT_INTERFACE" ]; then + network_symbol="$disconnected_symbol" +else + # Check if it is a wireless interface (wlan*) + if [[ $DEFAULT_INTERFACE == wl* ]]; then + network_symbol="$wifi_symbol" + else + network_symbol="$lan_symbol" + fi +fi + +# Check internet connectivity +if ! ping -c 1 8.8.8.8 &> /dev/null; +then + network_symbol="$network_symbol $internet_disconnected" +else + network_symbol="$network_symbol $internet" +fi + +if ip addr show tun0 > /dev/null 2>&1; then + network_symbol="$network_symbol $vpn_symbol" +else + network_symbol="$network_symbol" +fi + +if [ -z "$IP_ADDRESS" ]; +then + printf "$network_symbol" +else +printf "$network_symbol|$IP_ADDRESS" +fi diff --git a/home/common/optional/desktop/status-bar/sb-updates.sh b/home/common/optional/desktop/status-bar/sb-updates.sh new file mode 100644 index 0000000..80bb055 --- /dev/null +++ b/home/common/optional/desktop/status-bar/sb-updates.sh @@ -0,0 +1,6 @@ +# Gets number of flake inputs that are ready for update +# Checks every 60 minutes +inputs=$(cd /etc/nixos && + nix flake update --output-lock-file <(cat flake.nix) 2> /tmp/update && + cat /tmp/update | grep -c Update) +printf " $inputs" diff --git a/home/common/optional/desktop/status-bar/sb-volume.sh b/home/common/optional/desktop/status-bar/sb-volume.sh new file mode 100644 index 0000000..1da6af3 --- /dev/null +++ b/home/common/optional/desktop/status-bar/sb-volume.sh @@ -0,0 +1,41 @@ +# Prints the current volume or 婢 if muted. + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e pulsemixer ;; + 2) pamixer -t && pkill -RTMIN+10 dwmblocks && exit 1 ;; + 4) pamixer --set-limit 150 --allow-boost -i 1 && pkill -RTMIN+10 dwmblocks && exit 1 ;; + 5) pamixer --set-limit 150 --allow-boost -d 1 && pkill -RTMIN+10 dwmblocks && exit 1 ;; + 3) notify-send "Volume module" "\- Shows volume , 婢 if muted. +- Middle click to mute. +- Scroll to change." ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +get_mic_status=$(pamixer --default-source --get-mute) +vol="$(pamixer --get-volume)" + +if [ $get_mic_status == false ]; then + mic_status="" +else + mic_status="" +fi + +if [ "$vol" -gt "90" ]; then + icon="" +elif [ "$vol" -gt "50" ]; then + icon="󰕾" +elif [ "$vol" -gt "30" ]; then + icon="" +elif [ "$vol" -gt "0" ]; then + icon="󰕿" +else + icon="󰝟" +fi + +if [ $(pamixer --get-mute) = true ]; then + icon="󰸈" + vol="0" +fi + +print_string="$mic_status $icon $vol%" +printf '%s' "${print_string}" diff --git a/home/common/optional/git.nix b/home/common/optional/git.nix index a6e6ebf..0f719b2 100644 --- a/home/common/optional/git.nix +++ b/home/common/optional/git.nix @@ -1,4 +1,4 @@ -{ pkgs, lib, config, ... }: +{ pkgs, ... }: { programs.git = { enable = true; diff --git a/home/semita.nix b/home/semita.nix index a6dc6e0..100441e 100644 --- a/home/semita.nix +++ b/home/semita.nix @@ -11,7 +11,7 @@ ./common/optional/git.nix ./common/optional/sops.nix ./common/optional/syncthing.nix - ./common/optional/desktop/startx + ./common/optional/desktop/dwm ]; diff --git a/pkgs/default.nix b/pkgs/default.nix index 693502b..bf3e172 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -3,4 +3,5 @@ pkgs: { sddm-theme = pkgs.callPackage ./sddm-theme { }; st = pkgs.callPackage ./st { }; + dwmblocks = pkgs.callPackage ./dwmblocks { }; } diff --git a/pkgs/dwmblocks/default.nix b/pkgs/dwmblocks/default.nix index b50e29f..d118abe 100644 --- a/pkgs/dwmblocks/default.nix +++ b/pkgs/dwmblocks/default.nix @@ -1,13 +1,8 @@ { pkgs ? import { } , fetchFromGitea ? pkgs.fetchFromGitea - #, stdenv ? pkgs.stdenv - #, pkg-config ? pkgs.pkg-config - #, fontconfig ? pkgs.fontconfig - #, freetype ? pkgs.freetype - #, libX11 ? pkgs.xorg.libX11 - #, libXft ? pkgs.xorg.libXft - #, ncurses ? pkgs.ncurses - #, extraLibs ? [ ] +, pkg-config ? pkgs.pkg-config +, libX11 ? pkgs.xorg.libX11 +, libXft ? pkgs.xorg.libXft }: pkgs.stdenv.mkDerivation { pname = "dwmblocks"; @@ -18,16 +13,25 @@ pkgs.stdenv.mkDerivation { owner = "sam"; repo = "dwmblocks"; rev = "c4e7a9b1eb98123e239ba76bc551934721fd18ca"; - sha256 = "sha256-4W9w/Efk+YCSP1VuUFr+jPXIyrlpktwxRPUOZHTAtx8="; + sha256 = "sha256-F1x8jOT+c2pPCF9qKq5boIWzegMBTCxwzKMVtmtMWGM="; }; + nativeBuildInputs = [ + pkg-config + ]; + + buildInputs = [ + libX11 + libXft + ]; + buildPhase = '' make ''; installPhase = '' - mkdir -p $out/usr/local/bin - mv st $out/usr/local/bin + mkdir -p $out/bin + mv dwmblocks $out/bin ''; } diff --git a/pkgs/st/default.nix b/pkgs/st/default.nix index fffa40e..2591bb4 100644 --- a/pkgs/st/default.nix +++ b/pkgs/st/default.nix @@ -30,8 +30,8 @@ pkgs.stdenv.mkDerivation { ''; installPhase = '' - mkdir -p $out/usr/local/bin - mv st $out/usr/local/bin + mkdir -p $out/bin + mv st $out/bin ''; }