Skip to content

Commit 8f0491a

Browse files
committed
extract the whole version string from lock files, and then break it apart into commit and major/minor/patch version so we can decide which binaries to download more reliably
1 parent c4880d9 commit 8f0491a

File tree

5 files changed

+218
-188
lines changed

5 files changed

+218
-188
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/parsers.nix

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ let
2525
# example:
2626
# a.b123c.d.e12345
2727
# => e12345
28-
afterLastDot = text: lib.lists.last (lib.strings.splitString "." text);
29-
28+
afterLastAt = text: lib.lists.last (lib.strings.splitString "@" text);
3029
readYAML = callPackage ./readYAML.nix { };
3130
in
3231
# polyfill: the function in nixis implemented on Dec 6, 2024. replace this with one from lib after 24.11 reaches EOL.
@@ -50,7 +49,7 @@ in
5049
let
5150
version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split "@prisma/engines-version/" pnpmLock) 2)) 0;
5251
in
53-
lib.lists.last (lib.strings.splitString "." version);
52+
lib.lists.last (lib.strings.splitString "/" version);
5453

5554
# example line:
5655
# /@prisma/[email protected]:
@@ -59,7 +58,7 @@ in
5958
let
6059
version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split "@prisma/engines-version@" pnpmLock) 2)) 0;
6160
in
62-
lib.lists.last (lib.strings.splitString "." version);
61+
lib.lists.last (lib.strings.splitString "@" version);
6362

6463
# exmple line:
6564
# '@prisma/engines-version@5.15.0-29.12e25d8d06f6ea5a0252864dd9a03b1bb51f3022':
@@ -68,26 +67,25 @@ in
6867
let
6968
version = builtins.elemAt (builtins.split "'" (builtins.elemAt (builtins.split "@prisma/engines-version@" pnpmLock) 2)) 0;
7069
in
71-
lib.lists.last (lib.strings.splitString "." version);
70+
lib.lists.last (lib.strings.splitString "@" version);
7271
};
7372
pnpmLock = builtins.readFile path;
7473
pnpmLockVersion = parsePnpmLockVersion pnpmLock;
7574
pnpmLockParser = pnpmLockParsers.${pnpmLockVersion};
76-
commit = pnpmLockParser pnpmLock;
75+
versionString = pnpmLockParser pnpmLock;
7776
in
78-
commit;
77+
versionString;
7978
parseNpmLock =
8079
path:
8180
let
8281
packageLock = builtins.fromJSON (builtins.readFile path);
83-
version =
82+
versionString =
8483
if builtins.hasAttr "dependencies" packageLock then
8584
packageLock.dependencies.${"@prisma/engines-version"}.version
8685
else
8786
packageLock.packages.${"node_modules/@prisma/engines-version"}.version;
88-
commit = lib.lists.last (lib.strings.splitString "." version);
8987
in
90-
commit;
88+
versionString;
9189
parseYarnLock =
9290
path:
9391
let
@@ -109,15 +107,14 @@ in
109107
# "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0":
110108
# -> ["@prisma/engines-version@npm" "6" "3" "0-17" "acc0b9dd43eb689cbd20c9470515d719db10d0b0"]
111109
# -> acc0b9dd43eb689cbd20c9470515d719db10d0b0
112-
version = lib.lists.last (
110+
versionString = lib.lists.last (
113111
splitMultipleAndFilterEmpty [
114112
"\""
115113
":"
116-
"."
117114
] versionLine
118115
);
119116
in
120-
version;
117+
versionString;
121118
isYarnLockV1 =
122119
file:
123120
lib.lists.any (line: lib.strings.trim line == "# yarn lockfile v1") (
@@ -190,7 +187,7 @@ in
190187
"0" = bunLockParsers."1";
191188
"1" =
192189
lock:
193-
afterLastDot (
190+
afterLastAt (
194191
builtins.elemAt (lock."packages"."@prisma/engines-version" or (throw ''
195192
nix-prisma-utils: lockfile parsing error: package @prisma/engines-version not found.
196193
please make sure that you have @prisma/client installed.
@@ -208,7 +205,22 @@ in
208205
nix-prisma-utils: Unsupported lockfile version: ${lockfileVersion}
209206
nix-prisma-utils currently supports bun.lock version of 0 and 1.
210207
'');
211-
commit = parse lockfile;
208+
versionString = parse lockfile;
212209
in
213-
commit;
210+
versionString;
211+
212+
parseVersionString =
213+
versionString:
214+
let
215+
matches = lib.strings.match ''^([0-9]+)\.([0-9]+)\.([0-9]+).*([0-9a-fA-F]{40})$'' versionString;
216+
in
217+
if matches != null then
218+
{
219+
majorVersion = lib.toInt (lib.lists.elemAt matches 0);
220+
minorVersion = lib.toInt (lib.lists.elemAt matches 1);
221+
patchVersion = lib.toInt (lib.lists.elemAt matches 2);
222+
commit = lib.lists.elemAt matches 3;
223+
}
224+
else
225+
throw "nix-prisma-utils: Version string '${versionString}' does not match the expected format.";
214226
}

0 commit comments

Comments
 (0)