Skip to content

Conversation

@jerome-benoit
Copy link
Contributor

@jerome-benoit jerome-benoit commented Jan 12, 2026

Summary

Fixes #8029 and #4853 by installing only platform-specific optional dependencies instead of all platforms.

Changes

  • Parse bunTarget map to extract OS and CPU for bun install flags
  • Replace --cpu="*" and --os="*" with platform-specific values
  • Support per-system node_modules hashes (different content per platform)
  • Update CI workflow to generate hashes for all platforms
  • Fail explicitly for missing hashes (no silent fallbacks)

Implementation

  • Added parseBunTarget helper to extract OS/CPU from bunTarget
  • Modified nodeModulesHashFor to support both {system: hash} and legacy single hash
  • Updated nix/hashes.json with per-system hashes (x86_64-linux, aarch64-darwin)
  • Modified update-hashes.sh script to write per-system hash format
  • Split update-nix-hashes workflow into sequential Linux + macOS jobs
  • Removed code duplication by reusing existing bunTarget map
  • Removed fallback hashes to prevent silent failures

Impact

Supported Systems

Currently with hashes:

  • x86_64-linux
  • aarch64-darwin

Defined but pending CI hash generation:

  • x86_64-darwin (will be generated on next dependency change)
  • aarch64-linux (will be generated on next dependency change)

Missing hashes will fail with clear Nix error instead of using wrong hash.

Copilot AI review requested due to automatic review settings January 12, 2026 17:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical build failure on macOS/Linux where Nix was attempting to install Windows-specific optional dependencies, causing "Operation not permitted" errors. The fix introduces platform-specific filtering of optional dependencies during bun install by mapping Nix system identifiers to Bun's --cpu and --os flag values.

Changes:

  • Added system parameter to node-modules.nix with mappings for CPU architectures (arm64, x64, ia32, arm) and operating systems (darwin, linux)
  • Replaced wildcard values ("*") in bun install flags with platform-specific values to filter optional dependencies
  • Implemented fallback to "*" for unsupported platforms to maintain compatibility

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
nix/node-modules.nix Added system parameter and mapping logic to convert Nix system identifiers to Bun CPU/OS values, replacing wildcard flags with platform-specific values
flake.nix Passed system parameter to node-modules.nix via inherit system in the callPackage invocation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Fixes anomalyco#8029 by installing only platform-specific optional dependencies
instead of all platforms, preventing 'Operation not permitted' errors
on Windows DLLs when building on macOS/Linux.

Changes:
- Add system parameter to node-modules.nix
- Map Nix systems to Bun --cpu/--os flags
- Replace --cpu="*" --os="*" with platform-specific values
- Fallback to "*" for unknown systems to preserve compatibility

This reduces package size from ~4GB to a few hundred MB and eliminates
cross-platform binary file access issues in Nix build sandboxes.
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@jerome-benoit jerome-benoit force-pushed the fix/nix-platform-specific-deps branch from 8698663 to f2e8138 Compare January 12, 2026 17:32
Since we now install platform-specific dependencies only, node_modules
content differs per system. Update hash structure to support per-system
hashes while maintaining backward compatibility with single-hash format.

Hashes obtained from CI build errors:
- x86_64-linux: sha256-6GotwCHx/cw+6ShOcGz29DjuMUBGWD00CJXZHQzW9D8=
- aarch64-darwin: sha256-+T96JNNTCcbP4Ta1ezI1obI+YQYtfqMcp+G/eaUwTFQ=
Parse bunTarget values to extract OS and CPU instead of maintaining
separate cpuMap and osMap in node-modules.nix. This ensures single
source of truth and reduces maintenance burden.

- Added parseBunTarget helper function in flake.nix
- Removed duplicate cpuMap and osMap from node-modules.nix
- Pass bunCpu and bunOs as parameters to mkNodeModules
Add example to show input/output format more clearly.
Fallback to --cpu="*" --os="*" for systems not in bunTarget map to
prevent build failures on unsupported architectures.
Fallback to --cpu="*" --os="*" produces different node_modules content
that won't match per-system hashes. Better to fail explicitly with clear
error than silently use wrong hash.
Update write_node_modules_hash to write per-system format:
- Detect if nodeModules is object (per-system) or string (legacy)
- Convert legacy format to per-system on first run
- Update specific system hash while preserving others
Split workflow into two jobs:
- update-linux: runs first on x86_64-linux
- update-macos: runs after on aarch64-darwin

Each job updates hash for its platform and commits sequentially.
@rekram1-node
Copy link
Collaborator

Ping me when ready for review :)

Remove defaultNodeModules fallback - missing system hashes should fail
with clear error instead of silently using wrong hash.
@jerome-benoit
Copy link
Contributor Author

Ping me when ready for review :)

The CI is now working and I do not think I've overlooked any dependent code, so I think the PR is ready for review now ;)

@rekram1-node
Copy link
Collaborator

/review

@github-actions
Copy link
Contributor

lgtm

@jerome-benoit
Copy link
Contributor Author

jerome-benoit commented Jan 12, 2026

Any CI failure related to hashes or conflict in the hashes file are harmless, the GH workflow will regenerate it properly once merged.

- x86_64-linux: sha256-8nur5CuUCSV/SzD16hNXVoIlKsiPBXDzCnoITK0IhC4=
- aarch64-darwin: sha256-vD1g9dviI2nMBTTPwI87sK01hSZ+cdnmb1V72AdJYq4=
@rekram1-node rekram1-node merged commit ca1b597 into anomalyco:dev Jan 12, 2026
5 checks passed
@tvi
Copy link

tvi commented Jan 12, 2026

Hi @jerome-benoit , not sure if I am doing something wrong but now i am getting this error, when i update nix (it was working yesterday):

sudo darwin-rebuild switch
building the system configuration...
evaluation warning: 'system' has been renamed to/replaced by 'stdenv.hostPlatform.system'
error: hash mismatch in fixed-output derivation '/nix/store/dhyxb0f6r7pf7c78caxdwjxhkv9migmx-opencode-node_modules-1.1.15.drv':
         specified: sha256-vD1g9dviI2nMBTTPwI87sK01hSZ+cdnmb1V72AdJYq4=
            got:    sha256-Y3o6lovahSWoG9un/l1qxu7hCmIlZXm2LxOLKNiPQfQ=
error: Cannot build '/nix/store/xal9vzx1j02xz1w8sj1ghmm4r00nv25j-opencode-1.1.15.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/8yn22xmakg90d2nnlbshypnq039rw1va-opencode-1.1.15
error: Cannot build '/nix/store/l1hyr79m037y5hjj006an3jy4xk6hlj8-system-applications.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/8hp0f65l41dmq9l234yjkbbnis37mlng-system-applications
error: Cannot build '/nix/store/g79w184c83npgs5ncwz73zwcdpqpdcyj-system-path.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/iw9sa17x54nxgg7fax4frmlx41azkyaz-system-path
error: Cannot build '/nix/store/ydlhawmrl43m3mpmahlqw4fbn7wgipag-darwin-system-26.05.7b1d394.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/aw1q6d3cwz6hycb1f79ikwkyjpd196jd-darwin-system-26.05.7b1d394
         

@jerome-benoit
Copy link
Contributor Author

Pushed fix for hashes.json initialization bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Nix/macOS] Build fails with 'Operation not permitted' on Windows DLL - Regression since Jan 2026

3 participants