Skip to content

Commit ea8e857

Browse files
committed
optimise cache store
1 parent e8653a5 commit ea8e857

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

environments/cache/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ let
2626
# log-type = "file";
2727
# logfile = "/var/log/nix-serve-ng.log";
2828
# };
29+
services.gc.env.IS_CACHE = "true";
2930
# Umbrella service for cache
3031
services.cache = {
3132
type = "internal";

environments/modules/gc.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@
3434
''
3535
while :; do
3636
# Copy everything to cache
37-
CACHE_ENABLED="''${CACHE_ENABLED:-false}"
37+
CACHE_ENABLED="''${CACHE_ENABLED:-"false"}"
38+
IS_CACHE="''${IS_CACHE:-"false"}"
3839
if test "$CACHE_ENABLED" = "true"; then
3940
nix copy --all --store local --to ssh-ng://nix@nix-cache || true
4041
fi
4142
# Garbage collect anything older than an hour
4243
nix path-info --store local --all --json | \
4344
jq -r --argjson age ${rs} 'map(select(.registrationTime < (now - $age)) | .path) | .[]' | \
4445
nix store delete --store local --stdin --skip-live
46+
if test "$IS_CACHE" = "true"; then
47+
nix store optimise
48+
fi
4549
# chill
4650
SLEEP=$(shuf -i ${lis}-${uis} -n 1)
4751
echo Sleeping for "$SLEEP" seconds

0 commit comments

Comments
 (0)