Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
seanaye/fix/try to fix nix bun (#4392)
Sean Ayee71be6f23e2e
diff --git a/.github/workflows/check_node_modules_nix.yml b/.github/workflows/check_node_modules_nix.ymlnew file mode 100644index 0000000000..f785dfd024--- /dev/null+++ b/.github/workflows/check_node_modules_nix.yml@@ -0,0 +1,78 @@+# DO NOT EDIT — regenerate with `cargo x workflows` (from rust/cloud-storage).+# Source: rust/cloud-storage/tools/xtask/src/workflows/check_node_modules_nix.rs+name: check node_modules nix+'on':+ pull_request:+ branches:+ - main+ paths:+ - js/bun.lock+ - js/**/package.json+ - js/app/patches/**+ - nix-support/node_modules.nix+ - nix-support/node_modules-hashes.json+ - nix/tauri-desktop.nix+ - scripts/update-node-modules-hash.sh+ - flake.nix+ - flake.lock+ - '.github/workflows/check_node_modules_nix.yml'+permissions:+ contents: read+jobs:+ check-linux-node-modules-nix:+ name: check Linux node_modules nix+ runs-on: namespace-profile-linux-small+ steps:+ - name: Checkout+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd+ with:+ clean: 'false'+ persist-credentials: 'false'+ - name: Setup Nix+ uses: './.github/actions/setup-nix'+ - name: Configure Cachix fallback+ uses: './.github/actions/setup-cachix'+ with:+ cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}+ - name: verify js node_modules derivation is up to date+ run: nix build .#js-node-modules --no-link+ check-darwin-node-modules-nix:+ name: check Darwin node_modules nix+ runs-on: macos-15+ steps:+ - name: Checkout+ uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd+ with:+ clean: 'false'+ persist-credentials: 'false'+ - name: Assert arm64 runner+ run: |+ set -euo pipefail+ if [ "$(uname -m)" != "arm64" ]; then+ echo "macOS node_modules checks must run on an arm64/aarch64 runner, got $(uname -m)" >&2+ exit 1+ fi+ shell: bash+ - name: Install Nix+ run: |+ set -euo pipefail+ if ! command -v nix >/dev/null 2>&1; then+ curl --http1.1 --retry 5 --retry-delay 5 --retry-all-errors \+ --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | \+ sh -s -- install macos --no-confirm \+ --extra-conf "experimental-features = nix-command flakes" \+ --extra-conf "sandbox = false" \+ --extra-conf "trusted-users = root runner"+ fi+ echo "/nix/var/nix/profiles/default/bin" >> "$GITHUB_PATH"+ echo "NIX_REMOTE=daemon" >> "$GITHUB_ENV"+ export PATH="/nix/var/nix/profiles/default/bin:$PATH"+ export NIX_REMOTE=daemon+ nix --version+ shell: bash+ - name: Configure Cachix fallback+ uses: './.github/actions/setup-cachix'+ with:+ cachix-auth-token: ${{ secrets.CACHIX_AUTH_TOKEN }}+ - name: verify js node_modules derivation is up to date+ run: nix build .#js-node-modules --no-linkdiff --git a/justfile b/justfileindex af757434a0..c155500c71 100644--- a/justfile+++ b/justfile@@ -60,6 +60,14 @@ local-e2e-seed:# local services with extra env/dependency requirements blocking E2E.local-e2e-services := "authentication-service connection_gateway contacts_service document_storage_service email_service notification_service static_file_service static_file_cdn sync_service websocket_service"+# Update the fixed-output js node_modules hash after js/bun.lock changes.+update-node-modules-hash:+ scripts/update-node-modules-hash.sh++# Verify the fixed-output js node_modules derivation matches js/bun.lock.+check-node-modules-nix:+ nix build .#js-node-modules --no-link+# Start the local stack, seed deterministic data, and run the Playwright smoke suite.local-e2e *ARGS:AWS_ACCESS_KEY_ID=test AWS_SECRET_ACCESS_KEY=test AWS_DEFAULT_REGION=us-east-1 just setup_localstackdiff --git a/nix-support/node_modules-hashes.json b/nix-support/node_modules-hashes.jsonnew file mode 100644index 0000000000..edc00349b0--- /dev/null+++ b/nix-support/node_modules-hashes.json@@ -0,0 +1,6 @@+{+ "nodeModules": {+ "aarch64-darwin": "sha256-nKmzyfYud90IlOgOsUOu8EjucFhC80q3ikgmaF2SPiI=",+ "x86_64-linux": "sha256-4cs5WCMEty9Nl9Qu5RZc+iAw134VL4fKiQO+o0sACLU="+ }+}diff --git a/nix-support/node_modules.nix b/nix-support/node_modules.nixnew file mode 100644index 0000000000..6d16c08cac--- /dev/null+++ b/nix-support/node_modules.nix@@ -0,0 +1,109 @@+{+ lib,+ stdenvNoCC,+ bun,+ coreutils,+ findutils,+ git,+ src ? ../js,+ hash ? (+ (builtins.fromJSON (builtins.readFile ./node_modules-hashes.json))+ .nodeModules.${stdenvNoCC.hostPlatform.system} or lib.fakeHash+ ),+}:+let+ packageJson = builtins.fromJSON (builtins.readFile ../js/app/packages/app/package.json);+ platform = stdenvNoCC.hostPlatform;+ bunCpu =+ if platform.isAarch64 then+ "arm64"+ else if platform.isx86_64 then+ "x64"+ else+ throw "unsupported Bun CPU for ${platform.system}";+ bunOs =+ if platform.isLinux then+ "linux"+ else if platform.isDarwin then+ "darwin"+ else+ throw "unsupported Bun OS for ${platform.system}";++ nodeModulesSrc = lib.cleanSourceWith {+ inherit src;+ filter =+ path: type:+ let+ rel = lib.removePrefix ((toString src) + "/") (toString path);+ in+ if type == "directory" then+ !(lib.hasInfix "/node_modules" rel)+ && !(lib.hasInfix "/dist" rel)+ && !(lib.hasInfix "/target" rel)+ && !(lib.hasInfix "/.direnv" rel)+ && rel != "node_modules"+ && rel != "dist"+ && rel != "target"+ && rel != ".direnv"+ else+ rel == "bun.lock"+ || rel == "package.json"+ || lib.hasSuffix "/package.json" rel+ || lib.hasPrefix "app/patches/" rel;+ };+in+stdenvNoCC.mkDerivation {+ pname = "macro-js-node-modules";+ version = packageJson.version;++ src = nodeModulesSrc;++ impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [+ "GIT_PROXY_COMMAND"+ "SOCKS_SERVER"+ ];++ nativeBuildInputs = [+ bun+ coreutils+ findutils+ git+ ];++ dontConfigure = true;++ buildPhase = ''+ runHook preBuild++ export HOME="$TMPDIR/home"+ export BUN_INSTALL_CACHE_DIR="$TMPDIR/bun-cache"+ mkdir -p "$HOME" "$BUN_INSTALL_CACHE_DIR"++ bun install \+ --cpu="${bunCpu}" \+ --os="${bunOs}" \+ --linker=hoisted \+ --frozen-lockfile \+ --ignore-scripts \+ --no-progress++ runHook postBuild+ '';++ installPhase = ''+ runHook preInstall+ mkdir -p "$out"+ find . -type d -name node_modules -exec cp -R --parents {} "$out" \;+ runHook postInstall+ '';++ dontFixup = true;++ outputHashAlgo = "sha256";+ outputHashMode = "recursive";+ outputHash = hash;++ meta.platforms = builtins.attrNames (+ (builtins.fromJSON (builtins.readFile ./node_modules-hashes.json)).nodeModules+ );+}diff --git a/nix/tauri-desktop.nix b/nix/tauri-desktop.nixindex 3469c22ee2..5746151a27 100644--- a/nix/tauri-desktop.nix+++ b/nix/tauri-desktop.nix@@ -51,40 +51,8 @@&& rel != "app/tauri/target";};- bunDeps = pkgs.stdenvNoCC.mkDerivation {- pname = "macro-js-bun-deps";- version = appVersion;- src = jsSrc;-- nativeBuildInputs = with pkgs; [- bun- git- ];-- dontConfigure = true;- dontBuild = true;- dontFixup = true;-- installPhase = ''- runHook preInstall-- export HOME="$TMPDIR"- export BUN_INSTALL_CACHE_DIR="$TMPDIR/bun-cache"- bun install --frozen-lockfile --no-progress-- mkdir -p "$out"- cp -a node_modules "$out/node_modules"-- runHook postInstall- '';-- outputHashAlgo = "sha256";- outputHashMode = "recursive";- outputHash =- if isAarch64Darwin then- "sha256-R0C2jkhk/QiS5v5Lm5cLiv3qU/8UzssTF37+8f3wrH4="- else- "sha256-T7LUQ6yNLxTnq6TK9nFzYKSqvrZ9MYRwCK/cYzPzuv8=";+ nodeModules = pkgs.callPackage ../nix-support/node_modules.nix {+ src = jsRoot;};frontend = pkgs.stdenvNoCC.mkDerivation {@@ -92,29 +60,34 @@version = appVersion;src = jsSrc;- nativeBuildInputs = with pkgs; [- bun- git+ nativeBuildInputs = [+ pkgs.bun+ pkgs.git];dontConfigure = true;buildPhase = ''- runHook preBuild-- export HOME="$TMPDIR"- cp -a ${bunDeps}/node_modules ./node_modules- chmod -R u+w ./node_modules-- printf production > app/tauri/src-tauri/.macro-tauri-env- (- cd app/packages/app- MODE=production NODE_ENV=production bun ../../../node_modules/vite/bin/vite.js build -c vite.config.ts- printf '${appVersion}+${gitRev}\n' > dist/semver.txt- BUNDLE_BUILD_NUMBER=1 MIN_NATIVE_BUILD=0 bun scripts/write-bundle-manifest.mjs- )-- runHook postBuild+ runHook preBuild++ cp -a ${nodeModules}/. .++ vite_resolve_replacement=' resolve: {+ alias: [+ { find: /^@tauri-apps\/api/, replacement: resolve(__dirname, "../../../node_modules/@tauri-apps/api") },+ ],'+ substituteInPlace app/packages/app/vite.base.ts \+ --replace-fail " resolve: {" "$vite_resolve_replacement"++ printf production > app/tauri/src-tauri/.macro-tauri-env+ (+ cd app/packages/app+ MODE=production NODE_ENV=production bun ../../../node_modules/vite/bin/vite.js build -c vite.config.ts+ printf '${appVersion}+${gitRev}\n' > dist/semver.txt+ BUNDLE_BUILD_NUMBER=1 MIN_NATIVE_BUILD=0 bun scripts/write-bundle-manifest.mjs+ )++ runHook postBuild'';installPhase = ''@@ -693,20 +666,22 @@};};- packages =- lib.optionalAttrs isLinux {- tauri-frontend = frontend;- tauri-desktop = wrappedTauriDesktop;- tauri-desktop-unwrapped = tauri.app;- tauri-desktop-cargo-artifacts = tauri.cargoArtifacts;- }- // lib.optionalAttrs isX86_64Linux {- tauri-desktop-appimage = tauriDesktopAppImage;- }- // lib.optionalAttrs isAarch64Darwin {- tauri-frontend = frontend;- tauri-desktop-dmg = tauriDesktopDmg;- tauri-desktop-cargo-artifacts = tauri.cargoArtifacts;- };+ packages = {+ js-node-modules = nodeModules;+ }+ // lib.optionalAttrs isLinux {+ tauri-frontend = frontend;+ tauri-desktop = wrappedTauriDesktop;+ tauri-desktop-unwrapped = tauri.app;+ tauri-desktop-cargo-artifacts = tauri.cargoArtifacts;+ }+ // lib.optionalAttrs isX86_64Linux {+ tauri-desktop-appimage = tauriDesktopAppImage;+ }+ // lib.optionalAttrs isAarch64Darwin {+ tauri-frontend = frontend;+ tauri-desktop-dmg = tauriDesktopDmg;+ tauri-desktop-cargo-artifacts = tauri.cargoArtifacts;+ };};}diff --git a/rust/cloud-storage/tools/xtask/src/workflows/check_generated.rs b/rust/cloud-storage/tools/xtask/src/workflows/check_generated.rsindex 4cef3d0caa..09be67cc99 100644--- a/rust/cloud-storage/tools/xtask/src/workflows/check_generated.rs+++ b/rust/cloud-storage/tools/xtask/src/workflows/check_generated.rs@@ -23,7 +23,7 @@ pub fn check_generated_workflows() -> Workflow {fn check_workflows() -> Job {Job::default().runs_on(runners::Runner::LinuxSmall.to_string())- .add_step(steps::checkout(false))+ .add_step(steps::checkout(false, true)).add_step(steps::setup_rust_light()).add_step(Step::new("verify workflows are up to date").run(diff --git a/rust/cloud-storage/tools/xtask/src/workflows/check_node_modules_nix.rs b/rust/cloud-storage/tools/xtask/src/workflows/check_node_modules_nix.rsnew file mode 100644index 0000000000..a0cfbe953a--- /dev/null+++ b/rust/cloud-storage/tools/xtask/src/workflows/check_node_modules_nix.rs@@ -0,0 +1,82 @@+//! `check node_modules nix` — verifies the fixed-output Bun `node_modules`+//! derivation still matches the committed lockfile/package manifests. Generated+//! into `check_node_modules_nix.yml`.++use gh_workflow::{Event, Job, Level, Permissions, PullRequest, Step, Workflow};++use crate::workflows::{runners, steps};++/// Build the workflow.+pub fn check_node_modules_nix() -> Workflow {+ Workflow::new("check node_modules nix")+ .permissions(Permissions {+ contents: Some(Level::Read),+ ..Default::default()+ })+ .on(Event::default().pull_request(+ PullRequest::default()+ .add_branch("main")+ .add_path("js/bun.lock")+ .add_path("js/**/package.json")+ .add_path("js/app/patches/**")+ .add_path("nix-support/node_modules.nix")+ .add_path("nix-support/node_modules-hashes.json")+ .add_path("nix/tauri-desktop.nix")+ .add_path("scripts/update-node-modules-hash.sh")+ .add_path("flake.nix")+ .add_path("flake.lock")+ .add_path(".github/workflows/check_node_modules_nix.yml"),+ ))+ .add_job(+ "check-linux-node-modules-nix",+ check_linux_node_modules_nix(),+ )+ .add_job(+ "check-darwin-node-modules-nix",+ check_darwin_node_modules_nix(),+ )+}++fn check_linux_node_modules_nix() -> Job {+ Job::default()+ .name("check Linux node_modules nix")+ .runs_on(runners::Runner::LinuxSmall.to_string())+ .add_step(steps::checkout(false, false))+ .add_step(steps::setup_nix())+ .add_step(steps::setup_cachix())+ .add_step(verify_node_modules_nix())+}++fn check_darwin_node_modules_nix() -> Job {+ Job::default()+ .name("check Darwin node_modules nix")+ .runs_on("macos-15")+ .add_step(steps::checkout(false, false))+ .add_step(assert_arm64())+ .add_step(install_nix_macos())+ .add_step(steps::setup_cachix())+ .add_step(verify_node_modules_nix())+}++fn assert_arm64() -> Step<gh_workflow::Run> {+ Step::new("Assert arm64 runner")+ .run(indoc::indoc! {r#"+ set -euo pipefail+ if [ "$(uname -m)" != "arm64" ]; then+ echo "macOS node_modules checks must run on an arm64/aarch64 runner, got $(uname -m)" >&2+ exit 1+ fi+ "#})+ .shell("bash")+}++fn install_nix_macos() -> Step<gh_workflow::Run> {+ Step::new("Install Nix")+ .run(include_str!("scripts/install_nix_macos.sh"))+ .shell("bash")+}++fn verify_node_modules_nix() -> Step<gh_workflow::Run> {+ Step::new("verify js node_modules derivation is up to date")+ .run("nix build .#js-node-modules --no-link")+}diff --git a/rust/cloud-storage/tools/xtask/src/workflows/code_check_cloud_storage.rs b/rust/cloud-storage/tools/xtask/src/workflows/code_check_cloud_storage.rsindex 5c10dbcd5c..19827bba14 100644--- a/rust/cloud-storage/tools/xtask/src/workflows/code_check_cloud_storage.rs+++ b/rust/cloud-storage/tools/xtask/src/workflows/code_check_cloud_storage.rs@@ -47,7 +47,7 @@ fn path_check() -> Job {"doppler_config_bins","${{ steps.doppler-bins.outputs.doppler_config_bins }}",)- .add_step(steps::checkout(true))+ .add_step(steps::checkout(true, true)).add_step(steps::setup_rust_light()).add_step(paths_filter()).add_step(compute_changed_files())@@ -64,7 +64,7 @@ fn check() -> Job {"-Dwarnings -Dclippy::disallowed_methods -C link-arg=-fuse-ld=mold",)).add_env(("RUSTDOCFLAGS", "-Dwarnings"))- .add_step(steps::checkout(false))+ .add_step(steps::checkout(false, true)).add_step(steps::mount_cache_volume()).add_step(steps::setup_nix()).add_step(steps::setup_dev_shell())@@ -87,7 +87,7 @@ fn test() -> Job {.add_env(("RUSTFLAGS", "-Dwarnings -C link-arg=-fuse-ld=mold")).add_service("postgres", postgres_service()).add_service("redis", redis_service())- .add_step(steps::checkout(false))+ .add_step(steps::checkout(false, true)).add_step(steps::mount_cache_volume()).add_step(steps::setup_nix()).add_step(steps::setup_dev_shell())diff --git a/rust/cloud-storage/tools/xtask/src/workflows/mod.rs b/rust/cloud-storage/tools/xtask/src/workflows/mod.rsindex ad0086aa15..0c66e0adb3 100644--- a/rust/cloud-storage/tools/xtask/src/workflows/mod.rs+++ b/rust/cloud-storage/tools/xtask/src/workflows/mod.rs@@ -13,6 +13,7 @@ mod build_appimage_on_tag;mod build_desktop_on_tag;mod build_dmg_on_tag;mod check_generated;+mod check_node_modules_nix;mod code_check_cloud_storage;mod runners;mod steps;@@ -64,6 +65,10 @@ const WORKFLOWS: &[WorkflowFile] = &[slug: "code_check_cloud_storage",render_yaml: || render_gh_workflow(code_check_cloud_storage::code_check_cloud_storage)(),},+ WorkflowFile {+ slug: "check_node_modules_nix",+ render_yaml: || render_gh_workflow(check_node_modules_nix::check_node_modules_nix)(),+ },WorkflowFile {slug: "check_generated",render_yaml: || render_gh_workflow(check_generated::check_generated_workflows)(),diff --git a/rust/cloud-storage/tools/xtask/src/workflows/steps.rs b/rust/cloud-storage/tools/xtask/src/workflows/steps.rsindex 92b8361868..dd7176c33d 100644--- a/rust/cloud-storage/tools/xtask/src/workflows/steps.rs+++ b/rust/cloud-storage/tools/xtask/src/workflows/steps.rs@@ -41,7 +41,7 @@ fn uses_local(name: &str, path: &str) -> Step<Use> {/// `actions/checkout`, pinned. `full_history` fetches the full history, which the/// path-filter diff in `path-check` needs.-pub fn checkout(full_history: bool) -> Step<Use> {+pub fn checkout(full_history: bool, persist_credentials: bool) -> Step<Use> {Step::new("Checkout").uses("actions",@@ -50,6 +50,9 @@ pub fn checkout(full_history: bool) -> Step<Use> {) // v4.add_with(("clean", false)).when(full_history, |step| step.add_with(("fetch-depth", 0)))+ .when(!persist_credentials, |step| {+ step.add_with(("persist-credentials", false))+ })}/// Install the Rust toolchain only (no sccache, no cache) — for the lightweightdiff --git a/scripts/update-node-modules-hash.sh b/scripts/update-node-modules-hash.shnew file mode 100755index 0000000000..5b0d062c22--- /dev/null+++ b/scripts/update-node-modules-hash.sh@@ -0,0 +1,84 @@+#!/usr/bin/env bash+set -euo pipefail++update_hash_file() {+ local path=$1+ local system=$2+ local hash=$3+ local entries+ local sorted+ local tmp+ local updated=false+ local total=0+ local index=0+ local line key value comma++ entries=$(mktemp)+ sorted=$(mktemp)+ tmp=$(mktemp)++ while IFS= read -r line; do+ if [[ $line =~ ^[[:space:]]*\"([^\"]+)\"[[:space:]]*:[[:space:]]*\"([^\"]+)\" ]]; then+ key=${BASH_REMATCH[1]}+ value=${BASH_REMATCH[2]}+ if [ "$key" = "$system" ]; then+ value=$hash+ updated=true+ fi+ printf '%s\t%s\n' "$key" "$value" >> "$entries"+ fi+ done < "$path"++ if [ "$updated" = false ]; then+ printf '%s\t%s\n' "$system" "$hash" >> "$entries"+ fi++ LC_ALL=C sort "$entries" > "$sorted"+ total=$(wc -l < "$sorted" | tr -d ' ')++ {+ echo "{"+ echo " \"nodeModules\": {"+ while IFS=$'\t' read -r key value; do+ index=$((index + 1))+ comma=","+ if [ "$index" -eq "$total" ]; then+ comma=""+ fi+ printf ' "%s": "%s"%s\n' "$key" "$value" "$comma"+ done < "$sorted"+ echo " }"+ echo "}"+ } > "$tmp"++ mv "$tmp" "$path"+ rm -f "$entries" "$sorted"+}++repo_root=$(git rev-parse --show-toplevel)+cd "$repo_root"++system=$(nix eval --raw --impure --expr 'builtins.currentSystem')+log=$(mktemp)+trap 'rm -f "$log"' EXIT++set +e+nix build .#js-node-modules --no-link 2>&1 | tee "$log"+status=${PIPESTATUS[0]}+set -e++if [ "$status" -eq 0 ]; then+ echo "nix-support/node_modules-hashes.json is already up to date for $system"+ exit 0+fi++hash=$(grep -Eo 'got:[[:space:]]+sha256-[A-Za-z0-9+/=]+' "$log" | tail -n1 | awk '{print $2}')+if [ -z "$hash" ]; then+ echo "failed to extract expected node_modules hash from nix output" >&2+ exit "$status"+fi++update_hash_file "nix-support/node_modules-hashes.json" "$system" "$hash"++echo "updated nix-support/node_modules-hashes.json for $system to $hash"+nix build .#js-node-modules --no-link