monolith: enable nix cache over ssh

This commit is contained in:
Leonardo Eugênio 2025-06-03 01:15:57 -03:00
parent 22dc422b63
commit 868496d2b9
No known key found for this signature in database
GPG key ID: 2F8F21CE8721456B
5 changed files with 138 additions and 52 deletions

View file

@ -0,0 +1,21 @@
#!/bin/sh
echo "nix-cache: Storing new store items"
NEW_NIX_STORE_CONTENTS_FILE=$(mktemp)
find /nix/store/ -maxdepth 1 > $NEW_NIX_STORE_CONTENTS_FILE
sort $OLD_NIX_STORE_CONTENTS_FILE -o $OLD_NIX_STORE_CONTENTS_FILE
sort $NEW_NIX_STORE_CONTENTS_FILE -o $NEW_NIX_STORE_CONTENTS_FILE
echo "nix-cache: Comparing store paths"
FILTERED_NIX_STORE_CONTENTS_FILE=$(mktemp)
comm -13 $OLD_NIX_STORE_CONTENTS_FILE $NEW_NIX_STORE_CONTENTS_FILE > $FILTERED_NIX_STORE_CONTENTS_FILE
echo "nix-cache: New store paths:"
cat $FILTERED_NIX_STORE_CONTENTS_FILE | sed 's/^/ /g'
if test -n "$(head -n1 $FILTERED_NIX_STORE_CONTENTS_FILE)"; then
echo "nix-cache: Sending new paths to cache"
nix copy --to "$STORE_URL" $(cat $FILTERED_NIX_STORE_CONTENTS_FILE) || true
else
echo "nix-cache: Nothing to send"
fi