albatros/hcl/nixcache/gc.sh

26 lines
543 B
Bash
Raw Permalink Normal View History

2023-03-24 15:53:56 +00:00
#!/usr/bin/env bash
set -euxo pipefail
# prepare workspace just in case
mkdir -p /nix/var/nix/gcroots/albatros
cd /nix/var/nix/gcroots/albatros
# remove any symlink that is older than 7 days
NOW=$(date +%s)
2023-03-24 15:56:16 +00:00
EXPIRE=$((60*60*24*7)) # 7 days in seconds
2023-03-24 15:53:56 +00:00
for f in $(ls); do
CR=$(stat $f -c %W)
DIFF=$((NOW-CR))
if [[ $DIFF -gt $EXPIRE ]]; then
echo "deleting $f"
rm -f $f
else
echo "keeping $f";
fi
done
# we don't want to slow down the build too much, so
# we limit to 1GB of deletion
nix store gc --verbose --max 1G