diff --git a/dotfiles/config/waybar/scripts/diskfree b/dotfiles/config/waybar/scripts/diskfree new file mode 100755 index 00000000..4960adc7 --- /dev/null +++ b/dotfiles/config/waybar/scripts/diskfree @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +set -euo pipefail + +config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/waybar" +list_file="${config_dir}/disks" + +mounts=() + +if [[ -n "${WAYBAR_DISKS:-}" ]]; then + # Accept comma or space separated values. + IFS=', ' read -r -a mounts <<< "${WAYBAR_DISKS//:/,}" +elif [[ -f "$list_file" ]]; then + while IFS= read -r line; do + line="${line%%#*}" + line="${line#"${line%%[![:space:]]*}"}" + line="${line%"${line##*[![:space:]]}"}" + [[ -z "$line" ]] && continue + mounts+=("$line") + done < "$list_file" +fi + +if [[ ${#mounts[@]} -eq 0 ]]; then + mounts=("/") +fi + +items=() +for mount in "${mounts[@]}"; do + if df_out=$(df -h --output=avail,target "$mount" 2>/dev/null | awk 'NR==2 {print $2, $1}'); then + items+=("$df_out") + fi +done + +if [[ ${#items[@]} -eq 0 ]]; then + exit 0 +fi + +output="" +for item in "${items[@]}"; do + if [[ -n "$output" ]]; then + output+=" | " + fi + output+="$item" +done + +printf '%s\n' "$output" diff --git a/nixos/machines/strixi-minaj.nix b/nixos/machines/strixi-minaj.nix index ca25657a..99310324 100644 --- a/nixos/machines/strixi-minaj.nix +++ b/nixos/machines/strixi-minaj.nix @@ -76,6 +76,7 @@ swapDevices = [ { device = "/dev/disk/by-uuid/27f277a0-b552-43a0-904d-625e48922bb9"; } + { device = "/swapfile"; size = 16384; } # size is in MiB (adds 16 GiB) ]; networking.hostName = "strixi-minaj"; @@ -86,6 +87,10 @@ home-manager.sharedModules = [ { home.stateVersion = "23.05"; + xdg.configFile."waybar/disks".text = '' + # One mountpoint per line (comments with # are ignored). + / + ''; } ];