flatpak-worker: Add script to automatically clear the flatpak-builder cache if it gets too large

This commit is contained in:
OatmealDome
2024-12-25 15:24:14 -05:00
parent 61774ef94f
commit 5cde50d2f8
2 changed files with 31 additions and 0 deletions

View File

@@ -30,8 +30,23 @@ let
pkgs.buildbot-worker
]);
flatpakScripts = with pkgs; stdenv.mkDerivation {
name = "flatpak-scripts";
src = ./utils;
propagatedBuildInputs = [ bash coreutils ];
unpackPhase = "true";
installPhase = ''
mkdir $out $out/bin
install -m755 $src/clean_cache.sh $out/bin
patchShebangs $out/bin
'';
};
flatpakEnvPackages = with pkgs; [
bash
flatpakScripts
flatpak
git
];

View File

@@ -0,0 +1,16 @@
#!/bin/bash
DIRECTORY_SIZE=$(du -sb .flatpak-builder | cut -f1)
MAX_SIZE=10737418240 # 10GiB
if [[ $DIRECTORY_SIZE -eq "" ]]; then
echo "Failed to calculate cache size, bailing out"
exit 0
fi
if [[ $DIRECTORY_SIZE -gt $MAX_SIZE ]]; then
echo "Cache is too large ($DIRECTORY_SIZE bytes), clearing"
rm -rf .flatpak-builder
else
echo "Cache is still within a reasonable size ($DIRECTORY_SIZE bytes)"
fi