#! /usr/bin/env sh set -eu notify-send "Running nix via the wrapper." if [ "$_NIX_WRAPPER_FALLBACK" = "true" ]; then # Allow skipping the size check. nix "$@" else usage="$(btrfs filesystem usage /nix --raw 2>/dev/null)" avail="$(echo "$usage" | grep 'Device size:' | cut -f 3 | sed 's/ //g')" used="$(echo "$usage" | grep 'Used:' | cut -f 4 | head -n 1 | sed 's/ //g')" perc="$(printf "scale=3\n%d / %d\n" "$used" "$avail" | bc)" perc="$(printf "%d * 100\n" "$perc" | bc)" if test -gt "$perc" "0.2"; then nix "$@" else echo "Not enough space free, in nix store: Only, $perc is still free." exit 3 fi fi # vim: ft=sh