Skip to content

Commit 4458bac

Browse files
committed
also detect 6.19 and 6.20 as v7 if they have "next" in the pre-release version, use the same component list for both fetchers
1 parent 8f0491a commit 4458bac

File tree

5 files changed

+90
-113
lines changed

5 files changed

+90
-113
lines changed

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
);

lib/legacyFetcher.nix

Lines changed: 17 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
hashes@{
22
# dependencies
33
lib,
44
fetchurl,
@@ -7,94 +7,42 @@
77
autoPatchelfHook,
88
# variables
99
openssl,
10-
commit,
1110
opensslVersion,
1211
binaryTarget,
13-
isv7,
1412
# = hashes
1513
prisma-fmt-hash,
1614
query-engine-hash,
1715
libquery-engine-hash,
1816
introspection-engine-hash,
1917
migration-engine-hash,
2018
schema-engine-hash,
19+
version,
20+
callPackage,
2121
}:
2222
let
2323
hostname = "binaries.prisma.sh";
2424
channel = "all_commits";
2525
isDarwin = lib.strings.hasPrefix "darwin" binaryTarget;
2626
target = if isDarwin then binaryTarget else "${binaryTarget}-openssl-${opensslVersion}";
2727
baseUrl = "https://${hostname}/${channel}";
28-
files =
29-
[
30-
{
31-
name = "prisma-fmt";
32-
hash = prisma-fmt-hash;
33-
path = "bin/prisma-fmt";
34-
variable = "PRISMA_FMT_BINARY";
35-
}
36-
]
37-
++ (
38-
if schema-engine-hash == null then
39-
[ ]
40-
else
41-
[
42-
{
43-
name = "schema-engine";
44-
hash = schema-engine-hash;
45-
path = "bin/schema-engine";
46-
variable = "PRISMA_SCHEMA_ENGINE_BINARY";
47-
}
48-
]
49-
)
50-
++ lib.optionals (!isv7) [
51-
{
52-
name = "query-engine";
53-
hash = query-engine-hash;
54-
path = "bin/query-engine";
55-
variable = "PRISMA_QUERY_ENGINE_BINARY";
56-
}
57-
{
58-
name = if isDarwin then "libquery_engine.dylib.node" else "libquery_engine.so.node";
59-
hash = libquery-engine-hash;
60-
path = "lib/libquery_engine.node";
61-
variable = "PRISMA_QUERY_ENGINE_LIBRARY";
62-
}
63-
]
64-
++ (
65-
if introspection-engine-hash == null then
66-
[ ]
67-
else
68-
[
69-
{
70-
name = "introspection-engine";
71-
hash = introspection-engine-hash;
72-
path = "bin/introspection-engine";
73-
variable = "PRISMA_INTROSPECTION_ENGINE_BINARY";
74-
}
75-
]
76-
)
77-
++ (
78-
if migration-engine-hash == null then
79-
[ ]
80-
else
81-
[
82-
{
83-
name = "migration-engine";
84-
hash = migration-engine-hash;
85-
path = "bin/migration-engine";
86-
variable = "PRISMA_MIGRATION_ENGINE_BINARY";
87-
}
88-
]
89-
);
28+
files = (callPackage ./components.nix { }).fromHashes {
29+
inherit
30+
prisma-fmt-hash
31+
query-engine-hash
32+
libquery-engine-hash
33+
introspection-engine-hash
34+
migration-engine-hash
35+
schema-engine-hash
36+
;
37+
};
9038
downloadedFiles = builtins.map (
9139
file:
9240
file
9341
// {
9442
file = fetchurl {
95-
name = "${baseUrl}/${commit}/${target}/${file.name}.gz";
96-
url = "${baseUrl}/${commit}/${target}/${file.name}.gz";
97-
hash = file.hash;
43+
name = "${baseUrl}/${version.commit}/${target}/${file.getFileName isDarwin}";
44+
url = "${baseUrl}/${version.commit}/${target}/${file.getFileName isDarwin}";
45+
hash = hashes."${file.name}-hash";
9846
};
9947
}
10048
) files;
@@ -136,7 +84,7 @@ in
13684
rec {
13785
package = stdenv.mkDerivation {
13886
pname = "prisma-bin";
139-
version = commit;
87+
version = version.commit;
14088
nativeBuildInputs = [
14189
zlib
14290
openssl

lib/parsers.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,15 @@ in
212212
parseVersionString =
213213
versionString:
214214
let
215-
matches = lib.strings.match ''^([0-9]+)\.([0-9]+)\.([0-9]+).*([0-9a-fA-F]{40})$'' versionString;
215+
matches = lib.strings.match ''^([0-9]+)\.([0-9]+)\.([0-9]+)(.*)([0-9a-fA-F]{40})$'' versionString;
216216
in
217217
if matches != null then
218218
{
219219
majorVersion = lib.toInt (lib.lists.elemAt matches 0);
220220
minorVersion = lib.toInt (lib.lists.elemAt matches 1);
221221
patchVersion = lib.toInt (lib.lists.elemAt matches 2);
222-
commit = lib.lists.elemAt matches 3;
222+
preReleaseVersion = lib.lists.elemAt matches 3;
223+
commit = lib.lists.elemAt matches 4;
223224
}
224225
else
225226
throw "nix-prisma-utils: Version string '${versionString}' does not match the expected format.";

prisma.nix

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
hash ? null,
99
versionString ? null,
1010
version ? null,
11-
components ? null, # components to fetch
1211
npmLock ? null,
1312
yarnLock ? null,
1413
pnpmLock ? null,
@@ -47,10 +46,8 @@ let
4746
opensslVersion
4847
binaryTarget
4948
hash
50-
components
49+
version
5150
;
52-
commit = version.commit;
53-
isv7 = version.majorVersion >= 7;
5451
}
5552
else
5653
pkgs.callPackage ./lib/legacyFetcher.nix {
@@ -64,9 +61,8 @@ let
6461
introspection-engine-hash
6562
migration-engine-hash
6663
schema-engine-hash
64+
version
6765
;
68-
commit = version.commit;
69-
isv7 = version.majorVersion >= 7;
7066
};
7167
fromNpmLock = file: fromVersionString (parsers.parseNpmLock file);
7268
fromPnpmLock = file: fromVersionString (parsers.parsePnpmLock file);

0 commit comments

Comments
 (0)