Skip to content

Instantly share code, notes, and snippets.

@schickling
Created August 17, 2021 11:10
Show Gist options
  • Select an option

  • Save schickling/065dede7b5b57d5b6d1ceb9853c178b5 to your computer and use it in GitHub Desktop.

Select an option

Save schickling/065dede7b5b57d5b6d1ceb9853c178b5 to your computer and use it in GitHub Desktop.
Prisma 2.29.1 nixos
with import <nixpkgs> {};
# prisma-bin.nix
let
prismaDrv = {stdenv,fetchurl,openssl,zlib,autoPatchelfHook,lib} :
let
hostname = "binaries.prisma.sh";
channel = "all_commits";
target = "debian-openssl-1.1.x";
baseUrl = "https://${hostname}/${channel}";
commit = "1be4cd60b89afa04b192acb1ef47758a39810f3a";
hashes = {
introspection-engine = "37d4c7d940294283bdd863f3115a2a3aa2a00cd4ef3d82b284b5111a3c9562d8";
migration-engine = "61b11a193a779e0af2fde6bcc87c2feaa929683cfec9d799bc48b493b22a2985";
prisma-fmt = "c031eda8ea3e05ea6505b6ac7b0815c383d09d6afb874edd356543c3467a5594";
query-engine = "867709d94095e1346cd80e919b39fd140391c82bb6c1dd635806f0daaede1002";
};
files = lib.mapAttrs (name: sha256: fetchurl {
url = "${baseUrl}/${commit}/${target}/${name}.gz";
inherit sha256;
}) hashes;
unzipCommands = lib.mapAttrsToList (name: file: "gunzip -c ${file} > $out/bin/${name}") files;
in
stdenv.mkDerivation rec {
pname = "prisma-bin";
version = "2.29.1";
nativeBuildInputs = [
autoPatchelfHook
zlib
openssl
];
phases = ["buildPhase" "postFixupHooks" ];
buildPhase = ''
mkdir -p $out/bin
${lib.concatStringsSep "\n" unzipCommands}
chmod +x $out/bin/*
'';
};
prismaPkg = callPackage prismaDrv {};
in mkShell {
buildInputs = [
nodejs-14_x
yarn
prismaPkg
];
shellHook = ''
export PRISMA_MIGRATION_ENGINE_BINARY="${prismaPkg}/bin/migration-engine"
export PRISMA_QUERY_ENGINE_BINARY="${prismaPkg}/bin/query-engine"
export PRISMA_INTROSPECTION_ENGINE_BINARY="${prismaPkg}/bin/introspection-engine"
export PRISMA_FMT_BINARY="${prismaPkg}/bin/prisma-fmt"
'';
}
@naripok
Copy link
Copy Markdown

naripok commented Nov 24, 2021

Hello mate! All fine?

Does it work?
I'm having issues making the prisma/cli to discover the correct engines.
Maybe could you give me a hand, please?

Now I have prisma-engines and nodePackeages.prisma installed, prisma generate seems to work well, but when I try to query anything from code I get this:

Invalid `prisma.user.findUnique()` invocation in
/web-app/backend/src/middleware/user.ts:38:36

  35 }
  36
  37 try {
→ 38   const user = await prisma.user.findUnique(
  Query engine library for current platform "linux-nixos" could not be found.
You incorrectly pinned it to linux-nixos

This probably happens, because you built Prisma Client on a different platform.
(Prisma Client looked in "/web-app/backend/node_modules/@prisma/client/runtime/libquery_engine-linux-nixos.so.node")

Searched Locations:

/web-app/backend/node_modules/.prisma/client
/web-app/backend/node_modules/@prisma/client
/web-app/backend/node_modules/@prisma/client
/web-app/backend/node_modules/.prisma/client
/web-app/backend/prisma
/tmp/prisma-engines
/web-app/backend/node_modules/.prisma/client

You already added the platform "linux-nixos" to the "generator" block
in the "schema.prisma" file as described in https://pris.ly/d/client-generator,
but something went wrong. That's suboptimal.

Please create an issue at https://github.com/prisma/prisma/issues/new%

I really don't want to have to leave nixos just because of prisma T_T
Thanks in advance!

@pimeys
Copy link
Copy Markdown

pimeys commented Nov 24, 2021

Do you have the right variables in place, did you read this example?

https://github.com/pimeys/nix-prisma-example/

@naripok
Copy link
Copy Markdown

naripok commented Nov 25, 2021

Hey mate! Thank you very much for the reply!

Yes, I did read the example and I did have the variables in place (at least I think).
Anyway, I've dropped it for docker as I needed to get things done.
I'll get back to it later and see if I can get it working.

Thanks again, mate!
Have a great day! =D

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