kommode/gitea: hire cleaners
Some checks failed
Eval nix flake / evals (pull_request) Failing after 34s

This commit is contained in:
2025-10-30 17:11:43 +09:00
parent 3faad36418
commit bd5cb05ecf
2 changed files with 60 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ in {
./customization
./gpg.nix
./import-users
./vaskepersonalet.nix
./web-secret-provider
];

View File

@@ -0,0 +1,59 @@
{ config, ... }:
let
cfg = config.services.gitea;
cacheDir = "/var/cache/${config.systemd.services.gitea.serviceConfig.CacheDirectory}";
in
{
systemd.services."gitea-vaskepersonalet" = {
description = "yeeet";
startAt = "hourly";
serviceConfig = rec {
User = cfg.user;
Group = cfg.group;
RuntimeDirectory = "gitea-vaskepersonalet";
RootDirectory = "/run/${RuntimeDirectory}";
BindPaths = [
builtins.storeDir
cacheDir
cfg.dump.backupDir
];
};
script = let
percentageLimit = 80;
in ''
USED=$(df --output=pcent '${cacheDir}' | grep '[0-9]' | tr -d '%')
if [[ $USED -lt ${toString percentageLimit} ]]; then exit 0; fi
echo "omg omg, we're running out of space, imma yeet the cache"
rm -rf '${cacheDir}'/*
echo "yeetus deletus"
USED=$(df --output=pcent '${cacheDir}' | grep '[0-9]' | tr -d '%')
if [[ $USED -lt ${toString percentageLimit} ]]; then exit 0; fi
echo ""
echo "bruh, still low on space, yeeting old backups"
echo ""
# tail -n+2 ensure we keep at least one backup.
for file in $(ls -t1 '${cfg.dump.backupDir}' | sort --reverse | tail -n+2); do
echo "> Chose $file"
echo "> Do you really want to release this pokemon? [Y/n] Y"
rm "$file"
echo "> ..."
echo "> The pokemon was released back into the wild"
echo ""
USED=$(df --output=pcent '${cacheDir}' | grep '[0-9]' | tr -d '%')
if [[ $USED -lt ${toString percentageLimit} ]]; then exit 0; fi
done
echo "No way, we're still out of space? Not my problem anymore"
'';
};
}