65 lines
1.8 KiB
Nix
65 lines
1.8 KiB
Nix
|
{ pkgs, lib, ... }:
|
||
|
|
||
|
with pkgs;
|
||
|
|
||
|
writeShellApplication rec {
|
||
|
name = "attic-action";
|
||
|
|
||
|
runtimeInputs = [ attic-client ];
|
||
|
|
||
|
# Define the shell script
|
||
|
text = ''
|
||
|
#!/usr/bin/env bash
|
||
|
set -euo pipefail
|
||
|
|
||
|
# Default values
|
||
|
ATTIC_ENDPOINT="${ATTIC_ENDPOINT:-https://cache.252.no}"
|
||
|
ATTIC_CACHE="${ATTIC_CACHE:-nix-gitops}"
|
||
|
ATTIC_TOKEN="${ATTIC_TOKEN:-}"
|
||
|
SKIP_PUSH="${SKIP_PUSH:-false}"
|
||
|
SKIP_USE="${SKIP_USE:-false}"
|
||
|
|
||
|
# Ensure required inputs are provided
|
||
|
if [[ -z "$ATTIC_ENDPOINT" || -z "$ATTIC_CACHE" ]]; then
|
||
|
echo "Error: Both ATTIC_ENDPOINT and ATTIC_CACHE are required."
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
if [[ -z "$ATTIC_TOKEN" ]]; then
|
||
|
echo "Warning: ATTIC_TOKEN is not set. Operations requiring authentication might fail."
|
||
|
fi
|
||
|
|
||
|
# Add the cache as a substituter unless SKIP_USE is true
|
||
|
if [[ "$SKIP_USE" != "true" ]]; then
|
||
|
echo "Adding $ATTIC_ENDPOINT as a substituter..."
|
||
|
attic use --endpoint "$ATTIC_ENDPOINT" "$ATTIC_CACHE" || {
|
||
|
echo "Error: Failed to add substituter."
|
||
|
exit 1
|
||
|
}
|
||
|
else
|
||
|
echo "Skipping use of cache as substituter."
|
||
|
fi
|
||
|
|
||
|
# Push to the cache unless SKIP_PUSH is true
|
||
|
if [[ "$SKIP_PUSH" != "true" ]]; then
|
||
|
echo "Pushing results to $ATTIC_ENDPOINT/$ATTIC_CACHE..."
|
||
|
attic push --endpoint "$ATTIC_ENDPOINT" "$ATTIC_CACHE" || {
|
||
|
echo "Error: Failed to push to cache."
|
||
|
exit 1
|
||
|
}
|
||
|
else
|
||
|
echo "Skipping cache push."
|
||
|
fi
|
||
|
|
||
|
echo "Attic action completed successfully."
|
||
|
'';
|
||
|
|
||
|
# Metadata for the package
|
||
|
meta = with lib; {
|
||
|
homepage = "https://code.252.no/tommy/containers";
|
||
|
description = "Binary cache server action script for CI pipelines";
|
||
|
license = licenses.mit;
|
||
|
maintainers = with maintainers; [ "tommy-skaug" ];
|
||
|
};
|
||
|
}
|