update nix ssh cache

This commit is contained in:
Leonardo Eugênio 2025-06-03 12:56:29 -03:00
parent 868496d2b9
commit 72e4e38fe9
No known key found for this signature in database
GPG key ID: 2F8F21CE8721456B
4 changed files with 43 additions and 43 deletions

View file

@ -1,18 +1,49 @@
#!/bin/sh
echo "nix-cache: Setting up ssh key and host"
STORE_HOST_PUB_KEY="IyBuaXgtY2FjaGUud29wdXMuZGV2OjIyIFNTSC0yLjAtT3BlblNTSF8xMC4wCm5peC1jYWNoZS53b3B1cy5kZXYgc3NoLWVkMjU1MTkgQUFBQUMzTnphQzFsWkRJMU5URTVBQUFBSU5VNzFONVF4ZENtTTdOMjVTbk9nNnUrWUxtdjkyem5wZURjeUlEYW1sZEkK"
echo "nix-cache: Setting up ssh key and host" >&2
STORE_HOST_PUB_KEY="$(echo "$NIX_CACHE_SSH_PUBLIC_KEY" | base64 | tr -d '\n')"
STORE_URL="ssh://nix-ssh@nix-cache.wopus.dev?trusted=true&compress=true&ssh-key=$NIX_CACHE_SSH_PRIVATE_KEY_PATH&base64-ssh-public-host-key=$STORE_HOST_PUB_KEY"
echo STORE_URL="$STORE_URL"
echo STORE_URL="$STORE_URL" >&2
NIX_EXTRA_CONFIG_FILE=$(mktemp)
cat > "$NIX_EXTRA_CONFIG_FILE" <<EOF
extra-substituters = $STORE_URL
EOF
echo "nix-cache: Adding remote cache as substituter"
echo "nix-cache: Adding remote cache as substituter" >&2
export NIX_USER_CONF_FILES="$NIX_EXTRA_CONFIG_FILE:$NIX_USER_CONF_FILES"
echo "nix-cache: Storing existing store items"
OLD_NIX_STORE_CONTENTS_FILE=$(mktemp)
find /nix/store/ -maxdepth 1 > $OLD_NIX_STORE_CONTENTS_FILE
echo "nix-cache: Setting up nix hook" >&2
nix() {
echo "nix-cache: executing nix hook" >&2
command nix "$@"
local STATUS="$?"
local BUILD=no
if test "$STATUS" = "0"; then
for arg in "$@"; do
echo "nix-cache: evaluating arg '$arg'" >&2
case "$arg" in
build)
echo "nix-cache: enablig upload" >&2
BUILD=yes
;;
-*)
echo "nix-cache: ignoring argument '$arg'" >&2
;;
*)
if test "$BUILD" = yes; then
echo "nix-cache: Sending path $arg" >&2
command nix copy --to "$STORE_URL" "$arg" || true
else
echo "nix-cache: not building, ignoring argument '$arg'" >&2
fi
;;
esac
done
else
echo "nix-cache: nix exited with code '$STATUS', ignoring" >&2
fi
return "$STATUS"
}