Skip to content
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

feat: support NixOS natively out of the box #23672

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft

feat: support NixOS natively out of the box #23672

wants to merge 11 commits into from

Conversation

aqrln
Copy link
Member

@aqrln aqrln commented Mar 30, 2024

Using Prisma on NixOS is unnecessarily difficult right now and requires using custom engines and setting environment variables, using flakes etc, so let's fix it and make it just work out of the box as well.

Additionally, when trying to use Prisma on other Linux systems with Node.js installed with Nix (including Replit), the query engine library fails with misleading and incomprehensible error messages, leading users to believe that the problem is with incorrect OpenSSL version being detected or with OpenSSL not being installed (see #17635 and #20905). By using NixOS compatible engines in those setups as well, those issues will be solved.

All of these setups should just work, out of the box, with no extra effort from the user, on both x86_64 and ARM64, like Prisma works on other distros or with Node.js installed via other package managers.

This requires downloading the binaries the Nix way and putting them into the store, which this PR implements.

It is not expected to share a generated client between NixOS machines without re-generating but it is possible if the engines closures are exported from the store too. The recommended way to do that, however, would be to package the app with Nix, which users who need this likely do anyway. The primary use case this PR has in mind is local development, especially in projects/teams where most people don't use Nix and it is undesirable to introduce Nix-specific tooling in the project.

Lurkers beware: this is not planned work but my own personal contribution in my spare time to solve my own pain point. There's no guarantee this will be merged at all as this was never discussed with anyone yet, and the team as a whole may still decide we do not want to directly support NixOS and other Nix-based environments if this means maintaining extra code.

Fixes: #17635
Fixes: #18531
Fixes: #20905
Closes: #11820
Closes: #21056
Closes: #17818
Ref: #17900 (technically not directly related but NixOS seems to be the main/only way to run into that so we can decide to close anyway)

  • Add linux-nixos-arm64 target
  • Don't show OpenSSL warning on NixOS
  • Make list of libssl paths empty on NixOS
  • Treat Nix on other Linux as NixOS too
  • Handle the case when Nix is present but /etc/os-release is not (e.g. nix docker image)
  • Don't search for OpenSSL on NixOS
  • Translate NixOS binary targets to Debian in download logic
  • Remove NixOS without custom binaries warning
  • Download sha256 sums only instead of gzipped debian binaries
  • Skip caching and integrity check of existing engines, Nix handles those; check the we have a valid link to the store instead as the integrity check
  • Generate Nix expressions for derivations that download binaries and run autoPatchelfHook
  • Realize those derivations in the store
  • Add checks to disallow generating the client with linux-nixos or linux-nixos-arm64 if we are not on Linux with nix-build and nix-store available in PATH
  • Consider a warning/error if linux-nixos is added in binaryTargets explicitly rather than being native
  • Add symlinks to store paths in the generated client directory as indirect GC roots
  • Download native binary target engines as well on generic Linux with Nix to enable seamless jumping between Node.js versions installed via different means
  • Add ecosystem tests

@aqrln aqrln added this to the 5.12.0 milestone Mar 30, 2024
Copy link
Contributor

github-actions bot commented Mar 30, 2024

size-limit report 📦

Path Size
packages/client/runtime/library.js 177.93 KB (+0.26% 🔺)
packages/client/runtime/library.d.ts 81 B (0%)
packages/client/runtime/binary.js 596.75 KB (+0.08% 🔺)
packages/client/runtime/binary.d.ts 26 B (0%)
packages/client/runtime/edge.js 156.41 KB (0%)
packages/client/runtime/edge-esm.js 156.3 KB (0%)
packages/client/runtime/wasm.js 112.64 KB (+0.02% 🔺)
packages/client/runtime/index-browser.js 33.77 KB (0%)
packages/client/runtime/index-browser.d.ts 89 B (0%)
packages/cli/build/index.js 2.74 MB (+0.08% 🔺)
packages/client/prisma-client-0.0.0.tgz 2.89 MB (+0.02% 🔺)
packages/cli/prisma-0.0.0.tgz 3.88 MB (+0.02% 🔺)
packages/bundle-size/da-workers-libsql/output.tgz 863.76 KB (+0.01% 🔺)
packages/bundle-size/da-workers-neon/output.tgz 941.69 KB (+0.01% 🔺)
packages/bundle-size/da-workers-pg/output.tgz 963.11 KB (0%)
packages/bundle-size/da-workers-pg-worker/output.tgz 916.23 KB (+0.01% 🔺)
packages/bundle-size/da-workers-planetscale/output.tgz 878.67 KB (+0.01% 🔺)
packages/bundle-size/da-workers-d1/output.tgz 836.83 KB (0%)

@aqrln aqrln changed the title feat: support NixOS natively feat: support NixOS natively out of the box Mar 31, 2024
@aqrln aqrln modified the milestones: 5.12.0, 5.13.0 Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment