Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ jobs:
run: nix run .#build
env:
ICEDOS_SUBSTITUTER: ${{ vars.ICEDOS_SUBSTITUTER }}
ATTIC_TOKEN: ${{ secrets.ATTIC_TOKEN }}
35 changes: 34 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ set -o pipefail

root="$PWD"

# Check if a store path already exists in the Attic cache.
# Returns 0 if the path IS in the cache (i.e., we can skip building it).
is_path_cached() {
local store_path="$1"
# Attic's get-missing-paths expects just the hash part (first 32 chars after /nix/store/)
local hash="${store_path#/nix/store/}"
hash="${hash:0:32}"

local resp
resp=$(curl -sf -X POST \
-H "Authorization: Bearer $ATTIC_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"cache\":\"icedos\",\"store_path_hashes\":[\"$hash\"]}" \
"$ICEDOS_SUBSTITUTER/_api/v1/get-missing-paths" 2>/dev/null) || return 1

# If missing_paths is empty, the path exists in cache
local missing_count
missing_count=$(echo "$resp" | jq '.missing_paths | length')
[ "$missing_count" -eq 0 ]
}

[ -d build ] && rm -rf build
mkdir -p build/status

Expand Down Expand Up @@ -44,9 +65,21 @@ build_and_push() {

mkdir -p "$out"

echo "building $cfg..."
cd "$work"

# Check if this config's top-level system closure is already in the cache.
# Evaluate the store path without building, then query the Attic API.
if [ -n "${ATTIC_TOKEN:-}" ] && [ -n "${ICEDOS_SUBSTITUTER:-}" ]; then
top_path=$(nix eval --raw path:.#config.system.build.toplevel.outPath 2>/dev/null) || true
if [ -n "$top_path" ] && is_path_cached "$top_path"; then
echo "$cfg: top-level closure already in cache ($top_path), skipping build"
echo ok >"$root/build/status/$name"
return 0
fi
fi

echo "building $cfg..."

TMPDIR="$out" nix run path:.#icedos -- --build \
--nh-args --no-nom \
--build-args \
Expand Down
Loading