fix: attic cache
This commit is contained in:
@@ -24,8 +24,17 @@ let
|
||||
fi
|
||||
|
||||
# Read the auth token from sops if available
|
||||
export ATTIC_AUTH_TOKEN
|
||||
ATTIC_AUTH_TOKEN=$(cat "${authTokenFile}")
|
||||
|
||||
# Login to Attic cache
|
||||
echo "Logging in to Attic cache at $ATTIC_URL..." >&2
|
||||
if ! ${pkgs.attic-client}/bin/attic login "$ATTIC_CACHE" "$ATTIC_URL" "$ATTIC_AUTH_TOKEN"; then
|
||||
echo "Failed to login to Attic cache, skipping push" >&2
|
||||
exit 0
|
||||
fi
|
||||
echo "Successfully logged in to Attic cache" >&2
|
||||
|
||||
# Function to check if a path exists in cache
|
||||
path_in_cache() {
|
||||
local path="$1"
|
||||
@@ -43,8 +52,22 @@ let
|
||||
fi
|
||||
}
|
||||
|
||||
# Read paths from stdin (provided by Nix post-build-hook)
|
||||
while IFS= read -r path; do
|
||||
# Read paths from OUT_PATHS environment variable (provided by Nix post-build-hook)
|
||||
echo "Reading paths from OUT_PATHS..." >&2
|
||||
echo "DRV_PATH: $DRV_PATH" >&2
|
||||
echo "OUT_PATHS: $OUT_PATHS" >&2
|
||||
|
||||
if [[ -z "$OUT_PATHS" ]]; then
|
||||
echo "No output paths provided, skipping push" >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
path_count=0
|
||||
# Split OUT_PATHS by space and process each path
|
||||
for path in $OUT_PATHS; do
|
||||
path_count=$((path_count + 1))
|
||||
echo "Processing path #$path_count: $path" >&2
|
||||
|
||||
if [[ -e "$path" ]]; then
|
||||
# Check if already in cache before pushing
|
||||
if ! path_in_cache "$path"; then
|
||||
@@ -52,10 +75,12 @@ let
|
||||
else
|
||||
echo "Path $path already in cache, skipping" >&2
|
||||
fi
|
||||
else
|
||||
echo "Path $path does not exist, skipping" >&2
|
||||
fi
|
||||
done
|
||||
|
||||
echo "Attic cache push completed" >&2
|
||||
echo "Attic cache push completed (processed $path_count paths)" >&2
|
||||
'';
|
||||
|
||||
in {
|
||||
@@ -63,6 +88,13 @@ in {
|
||||
sopsFile = ./secrets.yaml;
|
||||
};
|
||||
|
||||
# Create netrc file for authenticated cache access
|
||||
sops.secrets.attic_netrc = {
|
||||
sopsFile = ./secrets.yaml;
|
||||
mode = "0440";
|
||||
group = "nixbld";
|
||||
};
|
||||
|
||||
# Install attic client
|
||||
environment.systemPackages = with pkgs; [
|
||||
attic-client
|
||||
@@ -73,6 +105,7 @@ in {
|
||||
substituters = [ cacheUrl ];
|
||||
trusted-public-keys = [ publicKey ];
|
||||
post-build-hook = atticPushHook;
|
||||
netrc-file = config.sops.secrets.attic_netrc.path;
|
||||
};
|
||||
|
||||
# Create a systemd service for manual cache operations
|
||||
|
||||
Reference in New Issue
Block a user