Skip to content

Commit 39eca4c

Browse files
committed
fix(nix): use system-specific hashes for pnpm deps
Different platforms download different platform-specific npm packages (e.g., darwin-arm64 vs linux-x64 binaries), resulting in different hashes for pnpm deps. - Add pnpmDepsHash map with per-system hashes - Update hash script to detect current system and update only that hash - Add hashes for x86_64-linux (CI) and aarch64-darwin (local dev)
1 parent ffce38e commit 39eca4c

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

flake.nix

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
];
1717

1818
perSystem =
19-
{ pkgs, ... }:
19+
{ pkgs, system, ... }:
2020
{
2121
packages.default =
2222
let
2323
packageJson = builtins.fromJSON (builtins.readFile ./package.json);
24+
pnpmDepsHash = {
25+
x86_64-linux = "sha256-PrCGXf5r03gfsoGJAzew592Al1G5dx6xa/qFxazuqUo=";
26+
aarch64-linux = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
27+
aarch64-darwin = "sha256-GDY7RZUl6A0d3l8Rz6X1sHQfwHgM2GKpcJ65yAKOmrg=";
28+
};
2429
in
2530
pkgs.stdenv.mkDerivation (finalAttrs: {
2631
pname = "stackone-ai";
@@ -36,7 +41,7 @@
3641

3742
pnpmDeps = pkgs.pnpm_10.fetchDeps {
3843
inherit (finalAttrs) pname version src;
39-
hash = "sha256-GDY7RZUl6A0d3l8Rz6X1sHQfwHgM2GKpcJ65yAKOmrg=";
44+
hash = pnpmDepsHash.${system};
4045
fetcherVersion = 1;
4146
};
4247

scripts/update-pnpm-hash.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
# Update pnpm deps hash in flake.nix
4+
# Update pnpm deps hash in flake.nix for the current system
55
# This script runs nix build to get the correct hash and updates flake.nix
66

77
FLAKE_FILE="flake.nix"
@@ -12,6 +12,10 @@ if [[ ! -f "$FLAKE_FILE" ]]; then
1212
exit 1
1313
fi
1414

15+
# Detect current system
16+
SYSTEM=$(nix eval --impure --raw --expr 'builtins.currentSystem')
17+
echo "Current system: $SYSTEM"
18+
1519
# Run nix build and capture the output
1620
echo "Calculating pnpm deps hash..."
1721
OUTPUT=$(nix build --no-link 2>&1 || true)
@@ -26,13 +30,13 @@ if echo "$OUTPUT" | grep -q "hash mismatch"; then
2630
exit 1
2731
fi
2832

29-
echo "New hash: $NEW_HASH"
33+
echo "New hash for $SYSTEM: $NEW_HASH"
3034

31-
# Update the hash in flake.nix (simple pattern for the hash line)
32-
sed -i.bak "s|hash = \"sha256-[^\"]*\"|hash = \"${NEW_HASH}\"|" "$FLAKE_FILE"
35+
# Update the hash for current system in flake.nix
36+
sed -i.bak "s|${SYSTEM} = \"sha256-[^\"]*\"|${SYSTEM} = \"${NEW_HASH}\"|" "$FLAKE_FILE"
3337
rm -f "${FLAKE_FILE}.bak"
3438

35-
echo "Updated $FLAKE_FILE with new hash"
39+
echo "Updated $FLAKE_FILE with new hash for $SYSTEM"
3640
else
37-
echo "Hash is up to date"
41+
echo "Hash is up to date for $SYSTEM"
3842
fi

0 commit comments

Comments
 (0)