mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-06 07:06:16 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
104187e42b | ||
|
|
80977ad6f0 |
@@ -1,61 +0,0 @@
|
||||
name: Nix Update Hash
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "nix/**"
|
||||
- "flake.nix"
|
||||
- "flake.lock"
|
||||
- "package.json"
|
||||
- "package-lock.json"
|
||||
- "packages/highlight/**"
|
||||
- "packages/plugin/**"
|
||||
- "packages/server/**"
|
||||
- "packages/relay/**"
|
||||
- "packages/cli/**"
|
||||
- "scripts/update-nix.sh"
|
||||
- "scripts/fix-lockfile.mjs"
|
||||
- ".github/workflows/nix-update-hash.yml"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
update-hash:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/create-github-app-token@d72941d797fd3113feb6b93fd0dec494b13a2547 # v1
|
||||
id: app-token
|
||||
with:
|
||||
app-id: ${{ secrets.PASEO_BOT_APP_ID }}
|
||||
private-key: ${{ secrets.PASEO_BOT_APP_PRIVATE_KEY }}
|
||||
|
||||
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
||||
with:
|
||||
ref: ${{ github.ref }}
|
||||
token: ${{ steps.app-token.outputs.token }}
|
||||
|
||||
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
|
||||
with:
|
||||
node-version: "22"
|
||||
cache: "npm"
|
||||
|
||||
- uses: cachix/install-nix-action@3dc140bfc76c49fbd4dd958429132e3746bcb086 # v31
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
|
||||
- name: Update lockfile + Nix hash if stale
|
||||
run: ./scripts/update-nix.sh
|
||||
|
||||
- name: Build Nix package
|
||||
run: nix build .#default -o result
|
||||
|
||||
- name: Commit hash/lockfile updates
|
||||
run: |
|
||||
git diff --quiet package-lock.json nix/npm-deps.hash && exit 0
|
||||
git config user.name "paseo-ai[bot]"
|
||||
git config user.email "266920839+paseo-ai[bot]@users.noreply.github.com"
|
||||
git add package-lock.json nix/npm-deps.hash
|
||||
git commit -m "fix: update lockfile signatures and Nix hash [skip ci]"
|
||||
git push
|
||||
@@ -27,8 +27,6 @@ on:
|
||||
- "scripts/trace-daemon.mjs"
|
||||
- "scripts/is-main-module.mjs"
|
||||
- "scripts/build-daemon-web-ui.mjs"
|
||||
- "scripts/update-nix.sh"
|
||||
- "scripts/fix-lockfile.mjs"
|
||||
- ".github/workflows/nix.yml"
|
||||
workflow_dispatch:
|
||||
|
||||
@@ -45,17 +43,12 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
||||
|
||||
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
|
||||
with:
|
||||
node-version: "22"
|
||||
cache: "npm"
|
||||
|
||||
- uses: cachix/install-nix-action@3dc140bfc76c49fbd4dd958429132e3746bcb086 # v31
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
|
||||
- name: Update lockfile + Nix hash if stale
|
||||
run: ./scripts/update-nix.sh
|
||||
- name: Fetch npm dependencies
|
||||
run: nix build .#default.npmDeps --no-link --max-jobs 64
|
||||
|
||||
- name: Build Nix package
|
||||
run: nix build .#default -o result
|
||||
@@ -142,6 +135,9 @@ jobs:
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
|
||||
- name: Fetch npm dependencies
|
||||
run: nix build .#desktop.npmDeps --no-link --max-jobs 64
|
||||
|
||||
- name: Build Nix desktop package
|
||||
run: nix build .#desktop -o result-desktop
|
||||
|
||||
|
||||
+10
-8
@@ -2,6 +2,7 @@
|
||||
lib,
|
||||
stdenv,
|
||||
buildNpmPackage,
|
||||
importNpmLock,
|
||||
nodejs_22,
|
||||
python3,
|
||||
makeWrapper,
|
||||
@@ -11,10 +12,9 @@
|
||||
electron,
|
||||
libuv,
|
||||
buildVersion,
|
||||
# Reuse the daemon's prebuilt npm-deps FOD. Same lockfile, same content —
|
||||
# without this, the desktop drv produces a separately-named store path
|
||||
# (`paseo-desktop-<v>-npm-deps`) and refetches the entire registry. Override
|
||||
# the upstream hash via `paseo.override { npmDepsHash = "..."; }`.
|
||||
# Reuse the daemon's prebuilt npmDeps derivation. Same lockfile, same content —
|
||||
# without this, the desktop drv builds its own npm-deps derivation and
|
||||
# rewrites the lockfile a second time.
|
||||
paseo,
|
||||
}:
|
||||
buildNpmPackage {
|
||||
@@ -61,6 +61,7 @@ buildNpmPackage {
|
||||
|
||||
nodejs = nodejs_22;
|
||||
inherit (paseo) npmDeps;
|
||||
npmConfigHook = importNpmLock.npmConfigHook;
|
||||
|
||||
# Prevent onnxruntime-node's install script from running during automatic
|
||||
# npm rebuild. We manually rebuild only node-pty in buildPhase.
|
||||
@@ -99,10 +100,11 @@ buildNpmPackage {
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
# npm ci runs with --ignore-scripts, so the root postinstall that applies
|
||||
# patches/ never runs. The web bundle imports modules those patches add
|
||||
# (lucide-react-native/context). The script spawns patch-package by name,
|
||||
# which only resolves with node_modules/.bin on PATH (npm run sets it).
|
||||
# importNpmLock.npmConfigHook runs `npm install --ignore-scripts` offline,
|
||||
# so the root postinstall that applies patches/ never runs. The web bundle
|
||||
# imports modules those patches add (lucide-react-native/context). The
|
||||
# script spawns patch-package by name, which only resolves with
|
||||
# node_modules/.bin on PATH (npm run sets it).
|
||||
PATH="$PWD/node_modules/.bin:$PATH" node scripts/postinstall-patches.mjs
|
||||
|
||||
# Native deps (terminal emulation; libuv-linked on Linux)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
sha256-nWaU16CvKjT2bhQ/Q0gxZOv2NGxODBwn7lZ/EQgE+u0=
|
||||
@@ -0,0 +1,50 @@
|
||||
# npm dependencies for the Nix packages, taken straight from package-lock.json.
|
||||
#
|
||||
# Each registry tarball is its own fixed-output fetch, keyed by the `integrity`
|
||||
# npm already recorded for it. There is no aggregate hash to keep in sync, so
|
||||
# any lockfile change (a dependency bump, a release version bump) builds as
|
||||
# committed, on every branch and tag.
|
||||
#
|
||||
# nixpkgs' importNpmLock is not used for the lockfile rewrite: it also rewrites
|
||||
# the root package.json dependencies to store paths, which npm rejects against
|
||||
# our `overrides` (EOVERRIDE), and it drops `link`, which turns workspace
|
||||
# symlinks into copies of unbuilt sources. Only its install hook is reused.
|
||||
{
|
||||
lib,
|
||||
fetchurl,
|
||||
runCommand,
|
||||
}:
|
||||
let
|
||||
packageLock = lib.importJSON ../package-lock.json;
|
||||
|
||||
isRegistryTarball = module: builtins.match "https?://.*" (module.resolved or "") != null;
|
||||
|
||||
fromStore =
|
||||
path: module:
|
||||
if isRegistryTarball module then
|
||||
module
|
||||
// {
|
||||
resolved = "file:${
|
||||
fetchurl {
|
||||
url = module.resolved;
|
||||
hash = module.integrity;
|
||||
}
|
||||
}";
|
||||
}
|
||||
else if lib.hasInfix "node_modules/" path && !(module.link or false) && !(module.inBundle or false) then
|
||||
throw "package-lock.json: ${path} has no registry tarball URL. Run `node scripts/fix-lockfile.mjs`."
|
||||
else
|
||||
module;
|
||||
in
|
||||
runCommand "paseo-npm-deps"
|
||||
{
|
||||
passAsFile = [ "packageLock" ];
|
||||
packageLock = builtins.toJSON (
|
||||
packageLock // { packages = lib.mapAttrs fromStore packageLock.packages; }
|
||||
);
|
||||
}
|
||||
''
|
||||
mkdir $out
|
||||
cp ${../package.json} $out/package.json
|
||||
cp "$packageLockPath" $out/package-lock.json
|
||||
''
|
||||
+17
-18
@@ -2,24 +2,23 @@
|
||||
lib,
|
||||
stdenv,
|
||||
buildNpmPackage,
|
||||
importNpmLock,
|
||||
callPackage,
|
||||
nodejs_22,
|
||||
python3,
|
||||
makeWrapper,
|
||||
autoPatchelfHook,
|
||||
# node-pty needs libuv headers on Linux
|
||||
libuv,
|
||||
# Exposed so downstream flakes that follow a different nixpkgs revision
|
||||
# (where `fetchNpmDeps` may produce a different hash for the same lockfile)
|
||||
# can override via `.override { npmDepsHash = "sha256-..."; }` without
|
||||
# `overrideAttrs` gymnastics — `npmDepsHash` is destructured from
|
||||
# `buildNpmPackage`'s args, so `overrideAttrs` cannot reach it.
|
||||
#
|
||||
# The default is read from a sidecar file so the CI auto-updater can replace
|
||||
# the hash with a single file write instead of a sed against this source.
|
||||
npmDepsHash ? lib.fileContents ./npm-deps.hash,
|
||||
npmDeps ? callPackage ./npm-deps.nix { },
|
||||
# COMPAT(npmDepsHash): removed after v0.19.2, drop after 2027-06-06.
|
||||
# Downstream flakes used to override this; keep it accepted so they still evaluate.
|
||||
npmDepsHash ? null,
|
||||
}:
|
||||
|
||||
buildNpmPackage rec {
|
||||
lib.warnIf (npmDepsHash != null)
|
||||
"paseo: npmDepsHash is no longer used because dependencies are fetched per tarball from package-lock.json."
|
||||
(buildNpmPackage rec {
|
||||
pname = "paseo";
|
||||
version = (builtins.fromJSON (builtins.readFile ../package.json)).version;
|
||||
|
||||
@@ -63,9 +62,8 @@ buildNpmPackage rec {
|
||||
|
||||
nodejs = nodejs_22;
|
||||
|
||||
# Default hash lives in nix/npm-deps.hash (see arg default above).
|
||||
# CI auto-updates that file when package-lock.json changes (see .github/workflows/).
|
||||
inherit npmDepsHash;
|
||||
inherit npmDeps;
|
||||
npmConfigHook = importNpmLock.npmConfigHook;
|
||||
|
||||
# Prevent onnxruntime-node's install script from running during automatic
|
||||
# npm rebuild (it tries to download from api.nuget.org, which fails in the sandbox).
|
||||
@@ -90,10 +88,11 @@ buildNpmPackage rec {
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
|
||||
# npm ci runs with --ignore-scripts, so the root postinstall that applies
|
||||
# patches/ never runs. The web bundle imports modules those patches add
|
||||
# (lucide-react-native/context). The script spawns patch-package by name,
|
||||
# which only resolves with node_modules/.bin on PATH (npm run sets it).
|
||||
# importNpmLock.npmConfigHook runs `npm install --ignore-scripts` offline,
|
||||
# so the root postinstall that applies patches/ never runs. The web bundle
|
||||
# imports modules those patches add (lucide-react-native/context). The
|
||||
# script spawns patch-package by name, which only resolves with
|
||||
# node_modules/.bin on PATH (npm run sets it).
|
||||
PATH="$PWD/node_modules/.bin:$PATH" node scripts/postinstall-patches.mjs
|
||||
|
||||
# Rebuild only node-pty (native addon for terminal emulation). The sherpa
|
||||
@@ -158,4 +157,4 @@ buildNpmPackage rec {
|
||||
mainProgram = "paseo";
|
||||
platforms = lib.platforms.linux ++ lib.platforms.darwin;
|
||||
};
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFileSync, spawnSync } from "node:child_process";
|
||||
import { readFileSync, readdirSync, mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
||||
import {
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
readdirSync,
|
||||
readFileSync,
|
||||
rmSync,
|
||||
writeFileSync,
|
||||
} from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { relative as relativePath } from "node:path";
|
||||
@@ -431,9 +439,13 @@ test("Docker packaging runs on main while Nix verifies packaging PRs on Linux",
|
||||
assert.match(nixTrigger, /pull_request:\s*\n\s+paths:/);
|
||||
for (const expectedPath of [
|
||||
"nix/**",
|
||||
"package.json",
|
||||
"package-lock.json",
|
||||
"patches/**",
|
||||
"packages/server/**",
|
||||
"packages/cli/**",
|
||||
"packages/desktop/**",
|
||||
"scripts/postinstall-patches.mjs",
|
||||
"scripts/trace-daemon.mjs",
|
||||
"scripts/is-main-module.mjs",
|
||||
".github/workflows/nix.yml",
|
||||
@@ -1265,3 +1277,68 @@ test("npm release offers a main-only canary with trusted publishing", () => {
|
||||
assert.ok(actions.length > 0);
|
||||
for (const [, action] of actions) assert.match(action, /@[a-f0-9]{40}$/);
|
||||
});
|
||||
|
||||
test("Nix packaging has no hash derived from the lockfile", () => {
|
||||
for (const removed of [
|
||||
"nix/npm-deps.hash",
|
||||
"scripts/update-nix.sh",
|
||||
".github/workflows/nix-update-hash.yml",
|
||||
]) {
|
||||
assert.equal(existsSync(new URL(removed, repoRoot)), false, `${removed} must not exist`);
|
||||
}
|
||||
|
||||
for (const nixFile of filesUnder("nix", (path) => path.endsWith(".nix"))) {
|
||||
const source = readFileSync(new URL(nixFile, repoRoot), "utf8");
|
||||
assert.doesNotMatch(source, /\b(?:fetchNpmDeps|prefetch-npm-deps)\b/, nixFile);
|
||||
assert.doesNotMatch(source, /\bnpmDepsHash\s*=/, nixFile);
|
||||
}
|
||||
|
||||
for (const nixPackage of ["nix/package.nix", "nix/desktop-package.nix"]) {
|
||||
const source = readFileSync(new URL(nixPackage, repoRoot), "utf8");
|
||||
assert.match(
|
||||
source,
|
||||
/^\s*npmConfigHook\s*=\s*importNpmLock\.npmConfigHook;/m,
|
||||
`${nixPackage} must set npmConfigHook = importNpmLock.npmConfigHook`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("no Nix workflow can write to the repository", () => {
|
||||
const nixWorkflows = [];
|
||||
for (const path of filesUnder(".github/workflows", (candidate) => /\.ya?ml$/.test(candidate))) {
|
||||
const source = readFileSync(new URL(path, repoRoot), "utf8");
|
||||
if (!/\bnix build\b/.test(source)) continue;
|
||||
nixWorkflows.push(path);
|
||||
|
||||
const topLevel = source.split(/\njobs:\r?\n/, 1)[0];
|
||||
const permBlock = topLevel.match(/^permissions:\s*\n((?:[ \t]+[^\n]+\n?)*)/m);
|
||||
assert.ok(permBlock, `${path} must declare top-level permissions`);
|
||||
const permLines = permBlock[1]
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter(Boolean);
|
||||
assert.deepEqual(permLines, ["contents: read"], `${path} must have contents: read only`);
|
||||
assert.doesNotMatch(source, /^[ \t]+permissions:/m, `${path} must not override permissions`);
|
||||
assert.doesNotMatch(source, /actions\/create-github-app-token/, path);
|
||||
assert.doesNotMatch(source, /\bgit\s+push\b/, path);
|
||||
}
|
||||
assert.ok(nixWorkflows.length > 0, "expected at least one Nix build workflow");
|
||||
});
|
||||
|
||||
test("every installable lockfile entry can be fetched by Nix", () => {
|
||||
const lockfile = JSON.parse(readFileSync(new URL("package-lock.json", repoRoot), "utf8"));
|
||||
const incomplete = [];
|
||||
for (const [key, entry] of Object.entries(lockfile.packages ?? {})) {
|
||||
if (!key.includes("node_modules/") || entry.link || entry.inBundle) continue;
|
||||
const hasHttpUrl = typeof entry.resolved === "string" && /^https?:\/\//.test(entry.resolved);
|
||||
const hasIntegrity = typeof entry.integrity === "string" && entry.integrity.length > 0;
|
||||
if (!hasHttpUrl || !hasIntegrity) {
|
||||
incomplete.push(key);
|
||||
}
|
||||
}
|
||||
assert.equal(
|
||||
incomplete.length,
|
||||
0,
|
||||
`package-lock.json entries cannot be fetched by Nix (${incomplete.join(", ")}). Run: node scripts/fix-lockfile.mjs`,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Fix workspace-local lockfile entries and update the Nix dependency hash.
|
||||
# Requires: node, npm, nix
|
||||
#
|
||||
# Usage:
|
||||
# ./scripts/update-nix.sh # fix lockfile + update hash
|
||||
# ./scripts/update-nix.sh --check # verify everything is up to date (CI mode)
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
LOCK_FILE="$ROOT_DIR/package-lock.json"
|
||||
HASH_FILE="$ROOT_DIR/nix/npm-deps.hash"
|
||||
|
||||
CHECK_MODE=false
|
||||
if [[ "${1:-}" == "--check" ]]; then
|
||||
CHECK_MODE=true
|
||||
fi
|
||||
|
||||
# 1. Fix lockfile (add resolved/integrity for workspace-local entries)
|
||||
# Workaround for https://github.com/npm/cli/issues/4460
|
||||
echo "Fixing lockfile..."
|
||||
node "$SCRIPT_DIR/fix-lockfile.mjs" "$LOCK_FILE"
|
||||
|
||||
# 2. Prefetch deps and compute hash
|
||||
echo "Prefetching npm dependencies..."
|
||||
|
||||
# Resolve prefetch-npm-deps from the same nixpkgs pinned in flake.lock
|
||||
NIXPKGS_URL="$(node -p "
|
||||
const l = JSON.parse(require('fs').readFileSync('$ROOT_DIR/flake.lock', 'utf8'));
|
||||
const n = l.nodes.nixpkgs.locked;
|
||||
'github:' + n.owner + '/' + n.repo + '/' + n.rev;
|
||||
")"
|
||||
|
||||
STDERR_LOG="$(mktemp)"
|
||||
trap "rm -f '$STDERR_LOG'" EXIT
|
||||
|
||||
if ! NEW_HASH="$(nix shell "${NIXPKGS_URL}#prefetch-npm-deps" -c prefetch-npm-deps "$LOCK_FILE" 2>"$STDERR_LOG")"; then
|
||||
echo "ERROR: prefetch-npm-deps failed:" >&2
|
||||
tail -20 "$STDERR_LOG" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "Computed hash: $NEW_HASH"
|
||||
|
||||
# 3. Read current hash from the sidecar file
|
||||
CURRENT_HASH="$(tr -d '[:space:]' < "$HASH_FILE")"
|
||||
|
||||
if [[ "$NEW_HASH" == "$CURRENT_HASH" ]]; then
|
||||
echo "Hash is already up to date."
|
||||
else
|
||||
if $CHECK_MODE; then
|
||||
echo "ERROR: npmDepsHash is stale."
|
||||
echo " current: $CURRENT_HASH"
|
||||
echo " correct: $NEW_HASH"
|
||||
echo "Run ./scripts/update-nix.sh to fix."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Updating nix/npm-deps.hash..."
|
||||
printf '%s\n' "$NEW_HASH" > "$HASH_FILE"
|
||||
echo "Updated: $CURRENT_HASH -> $NEW_HASH"
|
||||
fi
|
||||
Reference in New Issue
Block a user