Skip to content

Commit fa5a27d

Browse files
authored
Merge pull request #30 from VanCoding/prisma-7
Fix prisma 7 support
2 parents c4880d9 + 15b656c commit fa5a27d

File tree

8 files changed

+302
-295
lines changed

8 files changed

+302
-295
lines changed

flake.nix

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
prisma-next =
8989
(self.lib.prisma-factory {
9090
pkgs = pkgs;
91-
_commit = "next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513";
91+
versionString = "6.20.0-16.next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513";
9292
hash =
9393
{
9494
x86_64-linux = "sha256-JWX+N/mmp9uJLcv4XFbQ3yg34fFf2BLIUpOLrrfTjEM=";
@@ -103,15 +103,17 @@
103103
(prisma-factory {
104104
inherit pkgs;
105105
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
106-
_commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e";
106+
versionString = "5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e";
107107
}).package;
108108
devShells.default =
109109
let
110-
prisma = prisma-factory {
111-
inherit pkgs;
112-
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
113-
_commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e";
114-
};
110+
prisma = (
111+
prisma-factory {
112+
inherit pkgs;
113+
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
114+
versionString = "5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e";
115+
}
116+
);
115117
in
116118
pkgs.mkShell {
117119
buildInputs = [

legacy-api.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Legacy API
2+
In earlier versions of nix-prisma-utils the API was more like a factory pattern.
3+
This API still works, but is now deprecated and we recommend switching to the new API.
4+
We still try to support the legacy API for backwards compatibility, though.
5+
6+
## Using `npm`
7+
8+
```nix
9+
{
10+
inputs = {
11+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
12+
prisma-utils.url = "github:VanCoding/nix-prisma-utils";
13+
};
14+
15+
outputs =
16+
{ nixpkgs, prisma-utils, ... }:
17+
let
18+
system = "x86_64-linux";
19+
pkgs = nixpkgs.legacyPackages.${system};
20+
prisma =
21+
(prisma-utils.lib.prisma-factory {
22+
inherit pkgs;
23+
# just copy these hashes for now, and then change them when nix complains about the mismatch
24+
prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s=";
25+
query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw=";
26+
libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc=";
27+
schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q=";
28+
}).fromNpmLock
29+
./package-lock.json; # <--- path to our package-lock.json file that contains the version of prisma-engines
30+
in
31+
{
32+
devShells.${system}.default = pkgs.mkShell {
33+
env = prisma.env;
34+
# or, you can use `shellHook` instead of `env` to load the same environment variables.
35+
# shellHook = prisma.shellHook;
36+
};
37+
};
38+
}
39+
40+
```
41+
42+
## Using `yarn`
43+
44+
both yarn v1 and yarn-berry should work.
45+
46+
```nix
47+
{
48+
inputs = {
49+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
50+
prisma-utils.url = "github:VanCoding/nix-prisma-utils";
51+
};
52+
53+
outputs =
54+
{ nixpkgs, prisma-utils, ... }:
55+
let
56+
system = "x86_64-linux";
57+
pkgs = nixpkgs.legacyPackages.${system};
58+
prisma =
59+
(prisma-utils.lib.prisma-factory {
60+
inherit pkgs;
61+
# just copy these hashes for now, and then change them when nix complains about the mismatch
62+
prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s=";
63+
query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw=";
64+
libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc=";
65+
schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q=";
66+
}).fromYarnLock
67+
./yarn.lock; # <--- path to our yarn.lock file that contains the version of prisma-engines
68+
in
69+
{
70+
devShells.${system}.default = pkgs.mkShell {
71+
shellHook = prisma.shellHook;
72+
};
73+
};
74+
}
75+
```
76+
77+
## Using `pnpm`
78+
79+
```nix
80+
{
81+
inputs = {
82+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
83+
prisma-utils.url = "github:VanCoding/nix-prisma-utils";
84+
};
85+
86+
outputs =
87+
{ nixpkgs, prisma-utils, ... }:
88+
let
89+
system = "x86_64-linux";
90+
pkgs = nixpkgs.legacyPackages.${system};
91+
prisma =
92+
(prisma-utils.lib.prisma-factory {
93+
inherit pkgs;
94+
# just copy these hashes for now, and then change them when nix complains about the mismatch
95+
prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s=";
96+
query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw=";
97+
libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc=";
98+
schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q=";
99+
}).fromPnpmLock
100+
./pnpm-lock.yaml; # <--- path to our pnpm-lock.yaml file that contains the version of prisma-engines
101+
in
102+
{
103+
devShells.${system}.default = pkgs.mkShell {
104+
env = prisma.env;
105+
# or, you can use `shellHook` instead of `env` to load the same environment variables.
106+
# shellHook = prisma.shellHook;
107+
};
108+
};
109+
}
110+
111+
```
112+
113+
## Using `bun`
114+
115+
```nix
116+
{
117+
inputs = {
118+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
119+
prisma-utils.url = "github:VanCoding/nix-prisma-utils";
120+
};
121+
122+
outputs =
123+
{ nixpkgs, prisma-utils, ... }:
124+
let
125+
system = "x86_64-linux";
126+
pkgs = nixpkgs.legacyPackages.${system};
127+
prisma =
128+
(prisma-utils.lib.prisma-factory {
129+
inherit pkgs;
130+
# just copy these hashes for now, and then change them when nix complains about the mismatch
131+
prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s=";
132+
query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw=";
133+
libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc=";
134+
schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q=";
135+
}).fromBunLock
136+
./bun.lock; # <--- path to our bun.lock file that contains the version of prisma-engines.
137+
# NOTE: does not work with bun.lockb!
138+
in
139+
{
140+
devShells.${system}.default = pkgs.mkShell {
141+
env = prisma.env;
142+
# or, you can use `shellHook` instead of `env` to load the same environment variables.
143+
# shellHook = prisma.shellHook;
144+
};
145+
};
146+
}
147+
```

lib/components.nix

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{ lib, ... }:
2+
let
3+
isv7 =
4+
version:
5+
version.majorVersion >= 7
6+
|| (
7+
version.majorVersion == 6
8+
&& version.minorVersion >= 19
9+
&& lib.strings.hasInfix "next" version.preReleaseVersion
10+
);
11+
components = [
12+
{
13+
name = "migration-engine";
14+
getFileName = isDarwin: "migration-engine.gz";
15+
path = "bin/migration-engine";
16+
variable = "PRISMA_MIGRATION_ENGINE_BINARY";
17+
isIncluded = version: false;
18+
}
19+
{
20+
name = "prisma-fmt";
21+
getFileName = isDarwin: "prisma-fmt.gz";
22+
path = "bin/prisma-fmt";
23+
variable = "PRISMA_FMT_BINARY";
24+
isIncluded = version: true;
25+
}
26+
{
27+
name = "schema-engine";
28+
getFileName = isDarwin: "schema-engine.gz";
29+
path = "bin/schema-engine";
30+
variable = "PRISMA_SCHEMA_ENGINE_BINARY";
31+
isIncluded = version: true;
32+
}
33+
{
34+
name = "query-engine";
35+
getFileName = isDarwin: "query-engine.gz";
36+
path = "bin/query-engine";
37+
variable = "PRISMA_QUERY_ENGINE_BINARY";
38+
isIncluded = version: !(isv7 version);
39+
}
40+
{
41+
name = "libquery-engine";
42+
getFileName =
43+
isDarwin: if isDarwin then "libquery_engine.dylib.node.gz" else "libquery_engine.so.node.gz";
44+
path = "lib/libquery_engine.node";
45+
variable = "PRISMA_QUERY_ENGINE_LIBRARY";
46+
isIncluded = version: !(isv7 version);
47+
}
48+
{
49+
name = "introspection-engine";
50+
getFileName = isDarwin: "introspection-engine.gz";
51+
path = "bin/introspection-engine";
52+
variable = "PRISMA_INTROSPECTION_ENGINE_BINARY";
53+
isIncluded = version: false;
54+
}
55+
];
56+
in
57+
{
58+
fromVersion = version: lib.filter (component: component.isIncluded version) components;
59+
fromHashes = hashes: lib.filter (component: ((hashes."${component.name}-hash") != null)) components;
60+
}

lib/fetcher.nix

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,18 @@
88
runCommand,
99
gzip,
1010
# variables
11-
commit,
1211
openssl,
1312
opensslVersion,
1413
binaryTarget,
1514
hash,
16-
components,
17-
isv7,
15+
version,
16+
callPackage,
1817
}:
1918
let
20-
componentsToFetch =
21-
if components != null then
22-
components
23-
else
24-
[
25-
{
26-
url = "prisma-fmt.gz";
27-
path = "bin/prisma-fmt";
28-
env = "PRISMA_FMT_BINARY";
29-
}
30-
{
31-
url = "schema-engine.gz";
32-
path = "bin/schema-engine";
33-
env = "PRISMA_SCHEMA_ENGINE_BINARY";
34-
}
35-
]
36-
++ lib.optionals (!isv7) [
37-
{
38-
url = "query-engine.gz";
39-
path = "bin/query-engine";
40-
env = "PRISMA_QUERY_ENGINE_BINARY";
41-
}
42-
{
43-
url = if isDarwin then "libquery_engine.dylib.node.gz" else "libquery_engine.so.node.gz";
44-
path = "lib/libquery_engine.node";
45-
env = "PRISMA_QUERY_ENGINE_LIBRARY";
46-
}
47-
];
19+
componentsToFetch = (callPackage ./components.nix { }).fromVersion version;
4820
isDarwin = lib.strings.hasPrefix "darwin" binaryTarget;
4921
target = if isDarwin then binaryTarget else "${binaryTarget}-openssl-${opensslVersion}";
50-
toUrl = url: "https://binaries.prisma.sh/all_commits/${commit}/${target}/${url}";
22+
toUrl = url: "https://binaries.prisma.sh/all_commits/${version.commit}/${target}/${url}";
5123
deps =
5224
runCommand "prisma-deps-bin"
5325
{
@@ -66,15 +38,15 @@ let
6638
mkdir -p $out $out/lib $out/bin
6739
${lib.concatLines (
6840
map (component: ''
69-
echo '[nix-prisma-utils] fetching ${toUrl component.url} to $out/${component.path}'
70-
curl "${toUrl component.url}" -L | gunzip > $out/${component.path}
41+
echo '[nix-prisma-utils] fetching ${toUrl (component.getFileName isDarwin)} to $out/${component.path}'
42+
curl "${toUrl (component.getFileName isDarwin)}" -L | gunzip > $out/${component.path}
7143
'') componentsToFetch
7244
)}
7345
'';
7446
package = stdenv.mkDerivation {
7547
pname = "prisma-bin";
7648
src = deps;
77-
version = commit;
49+
version = version.commit;
7850
nativeBuildInputs = [
7951
zlib
8052
openssl
@@ -101,7 +73,7 @@ let
10173
package:
10274
builtins.listToAttrs (
10375
builtins.map (c: {
104-
name = c.env;
76+
name = c.variable;
10577
value = "${package}/${c.path}";
10678
}) componentsToFetch
10779
);

0 commit comments

Comments
 (0)