|
10 | 10 | - "bun.lock" |
11 | 11 | - "package.json" |
12 | 12 | - "packages/*/package.json" |
| 13 | + - "flake.lock" |
13 | 14 | - ".github/workflows/update-nix-hashes.yml" |
14 | 15 | pull_request: |
15 | 16 | paths: |
16 | 17 | - "bun.lock" |
17 | 18 | - "package.json" |
18 | 19 | - "packages/*/package.json" |
| 20 | + - "flake.lock" |
19 | 21 | - ".github/workflows/update-nix-hashes.yml" |
20 | 22 |
|
21 | 23 | jobs: |
22 | | - compute-node-modules-hash: |
| 24 | + update-node-modules-hashes: |
23 | 25 | if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository |
24 | | - strategy: |
25 | | - fail-fast: false |
26 | | - matrix: |
27 | | - include: |
28 | | - - system: x86_64-linux |
29 | | - host: blacksmith-4vcpu-ubuntu-2404 |
30 | | - - system: aarch64-linux |
31 | | - host: blacksmith-4vcpu-ubuntu-2404-arm |
32 | | - - system: x86_64-darwin |
33 | | - host: macos-15-intel |
34 | | - - system: aarch64-darwin |
35 | | - host: macos-latest |
36 | | - runs-on: ${{ matrix.host }} |
| 26 | + runs-on: blacksmith-4vcpu-ubuntu-2404 |
37 | 27 | env: |
38 | | - SYSTEM: ${{ matrix.system }} |
| 28 | + TITLE: node_modules hashes |
39 | 29 |
|
40 | 30 | steps: |
41 | 31 | - name: Checkout repository |
@@ -49,104 +39,6 @@ jobs: |
49 | 39 | - name: Setup Nix |
50 | 40 | uses: nixbuild/nix-quick-install-action@v34 |
51 | 41 |
|
52 | | - - name: Compute node_modules hash |
53 | | - run: | |
54 | | - set -euo pipefail |
55 | | -
|
56 | | - DUMMY="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" |
57 | | - HASH_FILE="nix/hashes.json" |
58 | | - OUTPUT_FILE="hash-${SYSTEM}.txt" |
59 | | -
|
60 | | - export NIX_KEEP_OUTPUTS=1 |
61 | | - export NIX_KEEP_DERIVATIONS=1 |
62 | | -
|
63 | | - BUILD_LOG=$(mktemp) |
64 | | - TMP_JSON=$(mktemp) |
65 | | - trap 'rm -f "$BUILD_LOG" "$TMP_JSON"' EXIT |
66 | | -
|
67 | | - if [ ! -f "$HASH_FILE" ]; then |
68 | | - mkdir -p "$(dirname "$HASH_FILE")" |
69 | | - echo '{"nodeModules":{}}' > "$HASH_FILE" |
70 | | - fi |
71 | | -
|
72 | | - # Set dummy hash to force nix to rebuild and reveal correct hash |
73 | | - jq --arg system "$SYSTEM" --arg value "$DUMMY" \ |
74 | | - '.nodeModules = (.nodeModules // {}) | .nodeModules[$system] = $value' "$HASH_FILE" > "$TMP_JSON" |
75 | | - mv "$TMP_JSON" "$HASH_FILE" |
76 | | -
|
77 | | - MODULES_ATTR=".#packages.${SYSTEM}.default.node_modules" |
78 | | - DRV_PATH="$(nix eval --raw "${MODULES_ATTR}.drvPath")" |
79 | | -
|
80 | | - echo "Building node_modules for ${SYSTEM} to discover correct hash..." |
81 | | - echo "Attempting to realize derivation: ${DRV_PATH}" |
82 | | - REALISE_OUT=$(nix-store --realise "$DRV_PATH" --keep-failed 2>&1 | tee "$BUILD_LOG" || true) |
83 | | -
|
84 | | - BUILD_PATH=$(echo "$REALISE_OUT" | grep "^/nix/store/" | head -n1 || true) |
85 | | - CORRECT_HASH="" |
86 | | -
|
87 | | - if [ -n "$BUILD_PATH" ] && [ -d "$BUILD_PATH" ]; then |
88 | | - echo "Realized node_modules output: $BUILD_PATH" |
89 | | - CORRECT_HASH=$(nix hash path --sri "$BUILD_PATH" 2>/dev/null || true) |
90 | | - fi |
91 | | -
|
92 | | - # Try to extract hash from build log |
93 | | - if [ -z "$CORRECT_HASH" ]; then |
94 | | - CORRECT_HASH="$(grep -E 'got:\s+sha256-[A-Za-z0-9+/=]+' "$BUILD_LOG" | awk '{print $2}' | head -n1 || true)" |
95 | | - fi |
96 | | -
|
97 | | - if [ -z "$CORRECT_HASH" ]; then |
98 | | - CORRECT_HASH="$(grep -A2 'hash mismatch' "$BUILD_LOG" | grep 'got:' | awk '{print $2}' | sed 's/sha256:/sha256-/' || true)" |
99 | | - fi |
100 | | -
|
101 | | - # Try to hash from kept failed build directory |
102 | | - if [ -z "$CORRECT_HASH" ]; then |
103 | | - KEPT_DIR=$(grep -oE "build directory.*'[^']+'" "$BUILD_LOG" | grep -oE "'/[^']+'" | tr -d "'" | head -n1 || true) |
104 | | - if [ -z "$KEPT_DIR" ]; then |
105 | | - KEPT_DIR=$(grep -oE '/nix/var/nix/builds/[^ ]+' "$BUILD_LOG" | head -n1 || true) |
106 | | - fi |
107 | | -
|
108 | | - if [ -n "$KEPT_DIR" ] && [ -d "$KEPT_DIR" ]; then |
109 | | - HASH_PATH="$KEPT_DIR" |
110 | | - [ -d "$KEPT_DIR/build" ] && HASH_PATH="$KEPT_DIR/build" |
111 | | -
|
112 | | - if [ -d "$HASH_PATH/node_modules" ]; then |
113 | | - CORRECT_HASH=$(nix hash path --sri "$HASH_PATH" 2>/dev/null || true) |
114 | | - fi |
115 | | - fi |
116 | | - fi |
117 | | -
|
118 | | - if [ -z "$CORRECT_HASH" ]; then |
119 | | - echo "Failed to determine correct node_modules hash for ${SYSTEM}." |
120 | | - cat "$BUILD_LOG" |
121 | | - exit 1 |
122 | | - fi |
123 | | -
|
124 | | - echo "$CORRECT_HASH" > "$OUTPUT_FILE" |
125 | | - echo "Hash for ${SYSTEM}: $CORRECT_HASH" |
126 | | -
|
127 | | - - name: Upload hash artifact |
128 | | - uses: actions/upload-artifact@v6 |
129 | | - with: |
130 | | - name: hash-${{ matrix.system }} |
131 | | - path: hash-${{ matrix.system }}.txt |
132 | | - retention-days: 1 |
133 | | - |
134 | | - commit-node-modules-hashes: |
135 | | - needs: compute-node-modules-hash |
136 | | - if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository |
137 | | - runs-on: blacksmith-4vcpu-ubuntu-2404 |
138 | | - env: |
139 | | - TITLE: node_modules hashes |
140 | | - |
141 | | - steps: |
142 | | - - name: Checkout repository |
143 | | - uses: actions/checkout@v6 |
144 | | - with: |
145 | | - token: ${{ secrets.GITHUB_TOKEN }} |
146 | | - fetch-depth: 0 |
147 | | - ref: ${{ github.head_ref || github.ref_name }} |
148 | | - repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }} |
149 | | - |
150 | 42 | - name: Configure git |
151 | 43 | run: | |
152 | 44 | |
@@ -159,54 +51,47 @@ jobs: |
159 | 51 | BRANCH="${TARGET_BRANCH:-${GITHUB_REF_NAME}}" |
160 | 52 | git pull --rebase --autostash origin "$BRANCH" |
161 | 53 |
|
162 | | - - name: Download all hash artifacts |
163 | | - uses: actions/download-artifact@v7 |
164 | | - with: |
165 | | - pattern: hash-* |
166 | | - merge-multiple: true |
167 | | - |
168 | | - - name: Merge hashes into hashes.json |
| 54 | + - name: Compute all node_modules hashes |
169 | 55 | run: | |
170 | 56 | set -euo pipefail |
171 | 57 |
|
172 | 58 | HASH_FILE="nix/hashes.json" |
| 59 | + SYSTEMS="x86_64-linux aarch64-linux x86_64-darwin aarch64-darwin" |
173 | 60 |
|
174 | 61 | if [ ! -f "$HASH_FILE" ]; then |
175 | 62 | mkdir -p "$(dirname "$HASH_FILE")" |
176 | 63 | echo '{"nodeModules":{}}' > "$HASH_FILE" |
177 | 64 | fi |
178 | 65 |
|
179 | | - echo "Merging hashes into ${HASH_FILE}..." |
| 66 | + for SYSTEM in $SYSTEMS; do |
| 67 | + echo "Computing hash for ${SYSTEM}..." |
| 68 | + BUILD_LOG=$(mktemp) |
| 69 | + trap 'rm -f "$BUILD_LOG"' EXIT |
180 | 70 |
|
181 | | - shopt -s nullglob |
182 | | - files=(hash-*.txt) |
183 | | - if [ ${#files[@]} -eq 0 ]; then |
184 | | - echo "No hash files found, nothing to update" |
185 | | - exit 0 |
186 | | - fi |
| 71 | + # The updater derivations use fakeHash, so they will fail and reveal the correct hash |
| 72 | + UPDATER_ATTR=".#packages.x86_64-linux.${SYSTEM}_node_modules" |
187 | 73 |
|
188 | | - EXPECTED_SYSTEMS="x86_64-linux aarch64-linux x86_64-darwin aarch64-darwin" |
189 | | - for sys in $EXPECTED_SYSTEMS; do |
190 | | - if [ ! -f "hash-${sys}.txt" ]; then |
191 | | - echo "WARNING: Missing hash file for $sys" |
| 74 | + nix build "$UPDATER_ATTR" --no-link 2>&1 | tee "$BUILD_LOG" || true |
| 75 | +
|
| 76 | + CORRECT_HASH="$(grep -E 'got:\s+sha256-[A-Za-z0-9+/=]+' "$BUILD_LOG" | awk '{print $2}' | head -n1 || true)" |
| 77 | +
|
| 78 | + if [ -z "$CORRECT_HASH" ]; then |
| 79 | + CORRECT_HASH="$(grep -A2 'hash mismatch' "$BUILD_LOG" | grep 'got:' | awk '{print $2}' | sed 's/sha256:/sha256-/' || true)" |
192 | 80 | fi |
193 | | - done |
194 | 81 |
|
195 | | - for f in "${files[@]}"; do |
196 | | - system="${f#hash-}" |
197 | | - system="${system%.txt}" |
198 | | - hash=$(cat "$f") |
199 | | - if [ -z "$hash" ]; then |
200 | | - echo "WARNING: Empty hash for $system, skipping" |
201 | | - continue |
| 82 | + if [ -z "$CORRECT_HASH" ]; then |
| 83 | + echo "Failed to determine correct node_modules hash for ${SYSTEM}." |
| 84 | + cat "$BUILD_LOG" |
| 85 | + exit 1 |
202 | 86 | fi |
203 | | - echo " $system: $hash" |
204 | | - jq --arg sys "$system" --arg h "$hash" \ |
205 | | - '.nodeModules = (.nodeModules // {}) | .nodeModules[$sys] = $h' "$HASH_FILE" > "${HASH_FILE}.tmp" |
| 87 | +
|
| 88 | + echo " ${SYSTEM}: ${CORRECT_HASH}" |
| 89 | + jq --arg sys "$SYSTEM" --arg h "$CORRECT_HASH" \ |
| 90 | + '.nodeModules[$sys] = $h' "$HASH_FILE" > "${HASH_FILE}.tmp" |
206 | 91 | mv "${HASH_FILE}.tmp" "$HASH_FILE" |
207 | 92 | done |
208 | 93 |
|
209 | | - echo "All hashes merged:" |
| 94 | + echo "All hashes computed:" |
210 | 95 | cat "$HASH_FILE" |
211 | 96 |
|
212 | 97 | - name: Commit ${{ env.TITLE }} changes |
|