-
Notifications
You must be signed in to change notification settings - Fork 3
chore(nix): add reproducible tarball build with nix #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f292ca5
7900b6a
c8766bb
8b443b3
38078e9
ffce38e
39eca4c
5878e77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,3 +181,4 @@ dist | |
| .direnv | ||
| !.envrc | ||
|
|
||
| result | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,49 @@ | |
| ]; | ||
|
|
||
| perSystem = | ||
| { pkgs, ... }: | ||
| { pkgs, system, ... }: | ||
| { | ||
| packages.default = | ||
| let | ||
| packageJson = builtins.fromJSON (builtins.readFile ./package.json); | ||
| pnpmDepsHash = { | ||
| x86_64-linux = "sha256-PrCGXf5r03gfsoGJAzew592Al1G5dx6xa/qFxazuqUo="; | ||
| aarch64-linux = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; | ||
|
||
| aarch64-darwin = "sha256-GDY7RZUl6A0d3l8Rz6X1sHQfwHgM2GKpcJ65yAKOmrg="; | ||
| }; | ||
| in | ||
| pkgs.stdenv.mkDerivation (finalAttrs: { | ||
| pname = "stackone-ai"; | ||
| version = packageJson.version; | ||
|
|
||
| src = ./.; | ||
|
|
||
| nativeBuildInputs = with pkgs; [ | ||
| nodejs_24 | ||
| pnpm_10 | ||
| pnpm_10.configHook | ||
| ]; | ||
|
|
||
| pnpmDeps = pkgs.pnpm_10.fetchDeps { | ||
| inherit (finalAttrs) pname version src; | ||
| hash = pnpmDepsHash.${system}; | ||
| fetcherVersion = 1; | ||
| }; | ||
|
|
||
| buildPhase = '' | ||
| runHook preBuild | ||
| pnpm run build | ||
| runHook postBuild | ||
| ''; | ||
|
|
||
| installPhase = '' | ||
| runHook preInstall | ||
| mkdir -p $out | ||
| pnpm pack --pack-destination $out | ||
| runHook postInstall | ||
| ''; | ||
| }); | ||
|
|
||
| devShells.default = pkgs.mkShell { | ||
| buildInputs = with pkgs; [ | ||
| # runtime | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,10 @@ pre-commit: | |||||
| glob: '*.nix' | ||||||
| run: nix develop --command nixfmt {staged_files} | ||||||
| stage_fixed: true | ||||||
| - name: update-pnpm-hash | ||||||
| glob: 'pnpm-lock.yaml' | ||||||
| run: ./scripts/update-pnpm-hash.sh | ||||||
|
||||||
| run: ./scripts/update-pnpm-hash.sh | |
| run: bash ./scripts/update-pnpm-hash.sh |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -45,7 +45,6 @@ | |||||
| "lint:oxfmt": "oxfmt --no-error-on-unmatched-pattern --check .", | ||||||
| "lint:oxlint": "oxlint --max-warnings=0 --type-aware --type-check", | ||||||
| "lint:knip": "knip", | ||||||
| "preinstall": "npx only-allow pnpm", | ||||||
| "prepack": "npm pkg delete scripts.preinstall && pnpm run build", | ||||||
|
||||||
| "prepack": "npm pkg delete scripts.preinstall && pnpm run build", | |
| "prepack": "pnpm run build", |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| # Ensure the script is running under Bash | |
| if [[ -z "${BASH_VERSION:-}" ]]; then | |
| echo "Error: This script must be run with bash." >&2 | |
| exit 1 | |
| fi | |
| # Verify required commands are available | |
| for cmd in nix sed grep; do | |
| if ! command -v "$cmd" >/dev/null 2>&1; then | |
| echo "Error: Required command '$cmd' not found in PATH." >&2 | |
| exit 1 | |
| fi | |
| done |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script assumes the presence of the nix command and doesn't check for its availability. If nix is not installed or not in PATH, the script will fail with an unclear error message. Consider adding a check to verify nix is available before attempting to run it, or handle the error more gracefully with a helpful error message.
| # Check if nix is available | |
| if ! command -v nix >/dev/null 2>&1; then | |
| echo "Error: 'nix' command not found. Please install Nix and ensure it is in your PATH." >&2 | |
| exit 1 | |
| fi |
Copilot
AI
Dec 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hash extraction pattern grep "got:" | sed 's/.*got:[[:space:]]*//' assumes a specific nix error message format. The pattern is fragile and may break if nix changes its error message format. Additionally, the sed regex pattern should be more explicit to match the expected format. Consider using a more robust extraction method or adding validation that the extracted hash matches the expected sha256 format (e.g., sha256-[A-Za-z0-9+/=]+).
| # Extract the new hash | |
| NEW_HASH=$(echo "$OUTPUT" | grep "got:" | sed 's/.*got:[[:space:]]*//' | tr -d '[:space:]') | |
| if [[ -z "$NEW_HASH" ]]; then | |
| echo "Error: Could not extract new hash" | |
| # Extract the new hash by matching the expected sha256 format in the output | |
| NEW_HASH=$(printf '%s\n' "$OUTPUT" | grep -oE 'sha256-[A-Za-z0-9+/=]+' | head -n1 || true) | |
| if [[ -z "$NEW_HASH" || ! "$NEW_HASH" =~ ^sha256-[A-Za-z0-9+/=]+$ ]]; then | |
| echo "Error: Could not extract valid sha256 hash from nix output" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command
ls result/*.tgz | head -n 1assumes that thenix buildcommand creates exactly one .tgz file in the result directory. If multiple .tgz files exist or if the build produces a different file structure, this will either select an unexpected file or fail. Consider being more explicit about the expected filename pattern or adding error handling to verify exactly one tarball exists before attempting to publish.