Skip to content

Commit 50f1c5b

Browse files
committed
hack: fix new prisma commit parsing failure
1 parent 54b13e3 commit 50f1c5b

File tree

3 files changed

+131
-120
lines changed

3 files changed

+131
-120
lines changed

flake.nix

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,35 @@
55
treefmt-nix.url = "github:numtide/treefmt-nix";
66
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
77
};
8-
outputs =
9-
{
10-
self,
11-
nixpkgs,
12-
flake-utils,
13-
treefmt-nix,
14-
}:
15-
let
16-
prisma-factory = import ./prisma.nix;
17-
in
8+
outputs = {
9+
self,
10+
nixpkgs,
11+
flake-utils,
12+
treefmt-nix,
13+
}: let
14+
prisma-factory = import ./prisma.nix;
15+
in
1816
flake-utils.lib.eachDefaultSystem (
19-
system:
20-
let
17+
system: let
2118
pkgs = nixpkgs.legacyPackages.${system};
2219

2320
yarn-v1 = pkgs.writeShellApplication {
2421
name = "yarn-v1";
2522
checkPhase = "";
26-
runtimeInputs = [ pkgs.yarn ];
23+
runtimeInputs = [pkgs.yarn];
2724
text = "yarn $@";
2825
};
2926
yarn-berry = pkgs.writeShellApplication {
3027
name = "yarn-berry";
3128
checkPhase = "";
32-
runtimeInputs = [ pkgs.yarn-berry ];
29+
runtimeInputs = [pkgs.yarn-berry];
3330
text = "yarn $@";
3431
};
3532
treefmt = treefmt-nix.lib.evalModule pkgs {
3633
# nixfmt is nixfmt-rfc-style
3734
programs.nixfmt.enable = true;
3835
};
39-
in
40-
{
36+
in {
4137
formatter = treefmt.config.build.wrapper;
4238
checks =
4339
(pkgs.callPackages ./tests.nix {
@@ -60,46 +56,47 @@
6056
})
6157
// {
6258
format = treefmt.config.build.check self;
63-
fetcher-assert-npm =
64-
let
65-
# force download debian for consistent hash across systems
66-
binaryTargetBySystem = {
67-
x86_64-linux = "debian";
68-
aarch64-linux = "debian";
69-
x86_64-darwin = "debian";
70-
aarch64-darwin = "debian";
71-
};
72-
prisma-legacy = prisma-factory {
59+
fetcher-assert-npm = let
60+
# force download debian for consistent hash across systems
61+
binaryTargetBySystem = {
62+
x86_64-linux = "debian";
63+
aarch64-linux = "debian";
64+
x86_64-darwin = "debian";
65+
aarch64-darwin = "debian";
66+
};
67+
prisma-legacy = prisma-factory {
68+
inherit pkgs binaryTargetBySystem;
69+
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
70+
};
71+
prisma-new = lockName: lockFile:
72+
prisma-factory {
7373
inherit pkgs binaryTargetBySystem;
7474
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
75+
${lockName} = lockFile;
7576
};
76-
prisma-new =
77-
lockName: lockFile:
78-
prisma-factory {
79-
inherit pkgs binaryTargetBySystem;
80-
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
81-
${lockName} = lockFile;
82-
};
83-
in
84-
assert
85-
(prisma-legacy.fromNpmLock ./npm/package-lock.json).env
86-
== (prisma-new "npmLock" ./npm/package-lock.json).env;
87-
pkgs.hello;
77+
in
78+
assert (prisma-legacy.fromNpmLock ./npm/package-lock.json).env
79+
== (prisma-new "npmLock" ./npm/package-lock.json).env;
80+
pkgs.hello;
81+
prisma-next =
82+
(self.lib.prisma-factory {
83+
inherit pkgs;
84+
_commit = "next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513";
85+
}).package;
8886
};
8987
packages.default =
9088
(prisma-factory {
9189
inherit pkgs;
9290
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
9391
_commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e";
9492
}).package;
95-
devShells.default =
96-
let
97-
prisma = prisma-factory {
98-
inherit pkgs;
99-
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
100-
_commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e";
101-
};
102-
in
93+
devShells.default = let
94+
prisma = prisma-factory {
95+
inherit pkgs;
96+
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
97+
_commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e";
98+
};
99+
in
103100
pkgs.mkShell {
104101
buildInputs = [
105102
pkgs.nodejs-18_x

lib/fetcher.nix

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,68 +14,80 @@
1414
binaryTarget,
1515
hash,
1616
components,
17-
}:
18-
let
17+
isv7,
18+
}: let
1919
componentsToFetch =
20-
if components != null then
21-
components
20+
if components != null
21+
then components
2222
else
2323
[
2424
{
2525
url = "prisma-fmt.gz";
2626
path = "bin/prisma-fmt";
2727
env = "PRISMA_FMT_BINARY";
2828
}
29+
{
30+
url = "schema-engine.gz";
31+
path = "bin/schema-engine";
32+
env = "PRISMA_SCHEMA_ENGINE_BINARY";
33+
}
34+
]
35+
++ lib.optionals (! isv7) [
2936
{
3037
url = "query-engine.gz";
3138
path = "bin/query-engine";
3239
env = "PRISMA_QUERY_ENGINE_BINARY";
3340
}
3441
{
35-
url = if isDarwin then "libquery_engine.dylib.node.gz" else "libquery_engine.so.node.gz";
42+
url =
43+
if isDarwin
44+
then "libquery_engine.dylib.node.gz"
45+
else "libquery_engine.so.node.gz";
3646
path = "lib/libquery_engine.node";
3747
env = "PRISMA_QUERY_ENGINE_LIBRARY";
3848
}
39-
{
40-
url = "schema-engine.gz";
41-
path = "bin/schema-engine";
42-
env = "PRISMA_SCHEMA_ENGINE_BINARY";
43-
}
4449
];
4550
isDarwin = lib.strings.hasPrefix "darwin" binaryTarget;
46-
target = if isDarwin then binaryTarget else "${binaryTarget}-openssl-${opensslVersion}";
51+
target =
52+
if isDarwin
53+
then binaryTarget
54+
else "${binaryTarget}-openssl-${opensslVersion}";
4755
toUrl = url: "https://binaries.prisma.sh/all_commits/${commit}/${target}/${url}";
4856
deps =
4957
runCommand "prisma-deps-bin"
50-
{
51-
nativeBuildInputs = [
52-
curl
53-
cacert
54-
gzip
55-
];
56-
outputHashAlgo = "sha256";
57-
outputHashMode = "recursive";
58-
outputHash = hash;
59-
}
60-
''
61-
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
62-
export CURL_CA_BUNDLE=$SSL_CERT_FILE
63-
mkdir -p $out $out/lib $out/bin
64-
${lib.concatLines (
65-
map (component: ''
66-
curl "${toUrl component.url}" -L | gunzip > $out/${component.path}
67-
'') componentsToFetch
68-
)}
69-
'';
58+
{
59+
nativeBuildInputs = [
60+
curl
61+
cacert
62+
gzip
63+
];
64+
outputHashAlgo = "sha256";
65+
outputHashMode = "recursive";
66+
outputHash = hash;
67+
}
68+
''
69+
export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt
70+
export CURL_CA_BUNDLE=$SSL_CERT_FILE
71+
mkdir -p $out $out/lib $out/bin
72+
${lib.concatLines (
73+
map (component: ''
74+
echo '[nix-prisma-utils] fetching ${toUrl component.url} to $out/${component.path}'
75+
curl "${toUrl component.url}" -L | gunzip > $out/${component.path}
76+
'')
77+
componentsToFetch
78+
)}
79+
'';
7080
package = stdenv.mkDerivation {
7181
pname = "prisma-bin";
7282
src = deps;
7383
version = commit;
74-
nativeBuildInputs = [
75-
zlib
76-
openssl
77-
stdenv.cc.cc.lib
78-
] ++ lib.optionals (!isDarwin) [ autoPatchelfHook ];
84+
nativeBuildInputs =
85+
[
86+
zlib
87+
openssl
88+
stdenv.cc.cc.lib
89+
]
90+
++ lib.optionals (!isDarwin) [autoPatchelfHook];
7991
phases = [
8092
"installPhase"
8193
"postFixupHooks"
@@ -88,22 +100,20 @@ let
88100
find $out/bin -type f -exec chmod +x {} +
89101
'';
90102
};
91-
toExportStyle =
92-
attrset:
103+
toExportStyle = attrset:
93104
"\n"
94105
+ (lib.concatMapAttrsStringSep "\n" (name: value: "export ${name}=\"${value}\"") attrset)
95106
+ "\n";
96-
mkEnv =
97-
package:
107+
mkEnv = package:
98108
builtins.listToAttrs (
99109
builtins.map (c: {
100110
name = c.env;
101111
value = "${package}/${c.path}";
102-
}) componentsToFetch
112+
})
113+
componentsToFetch
103114
);
104115
env = mkEnv package;
105-
in
106-
{
116+
in {
107117
inherit package env;
108118
shellHook = toExportStyle env;
109119
}

prisma.nix

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,21 @@
2525
x86_64-darwin = "darwin";
2626
aarch64-darwin = "darwin-arm64";
2727
},
28-
}:
29-
let
28+
}: let
3029
inherit (pkgs) lib;
31-
parsers = pkgs.callPackage ./lib/parsers.nix { };
30+
parsers = pkgs.callPackage ./lib/parsers.nix {};
3231
binaryTarget = binaryTargetBySystem.${pkgs.system};
33-
fromCommit =
34-
commit:
35-
if builtins.stringLength commit != 40 then
36-
throw "invalid commit: got ${commit}"
37-
else if hash != null then
32+
fromCommit = _commit: let
33+
# HACK: _commit may be "next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513" instead of "0c19ccc313cf9911a90d99d2ac2eb0280c76c513"
34+
commit = lib.lists.last (lib.splitString "-" _commit);
35+
# prisma >= v7 has fewer components;
36+
isv7 = lib.strings.hasPrefix "next-" _commit;
37+
in
38+
if builtins.stringLength commit != 40
39+
then throw "invalid commit: got ${commit}"
40+
else if hash != null
41+
then
42+
# use new fetcher
3843
pkgs.callPackage ./lib/fetcher.nix {
3944
inherit
4045
commit
@@ -43,9 +48,9 @@ let
4348
binaryTarget
4449
hash
4550
components
51+
isv7
4652
;
4753
}
48-
# use new fetcher
4954
else
5055
pkgs.callPackage ./lib/legacyFetcher.nix {
5156
inherit
@@ -66,33 +71,32 @@ let
6671
fromYarnLock = file: fromCommit (parsers.parseYarnLock file);
6772
fromBunLock = file: fromCommit (parsers.parseBunLock file);
6873
in
69-
lib.warnIf (nixpkgs != null)
74+
lib.warnIf (nixpkgs != null)
7075
''
7176
`nixpkgs` argument in nix-prisma-utils is deprecated. please replace it with `pkgs`.
7277
examples:
7378
if your code has `inherit nixpkgs;`, replace it with `pkgs = nixpkgs;`.
7479
if your code has `nixpkgs = pkgs;`, replace it with `pkgs = pkgs;` or `inherit pkgs;`.
7580
''
7681
(
77-
if _commit != null then
78-
fromCommit _commit
79-
else if npmLock != null then
80-
fromNpmLock npmLock
81-
else if yarnLock != null then
82-
fromYarnLock yarnLock
83-
else if pnpmLock != null then
84-
fromPnpmLock pnpmLock
85-
else if bunLock != null then
86-
fromBunLock bunLock
87-
else
88-
{
89-
# builder pattern
90-
inherit
91-
fromCommit
92-
fromNpmLock
93-
fromYarnLock
94-
fromPnpmLock
95-
fromBunLock
96-
;
97-
}
82+
if _commit != null
83+
then fromCommit _commit
84+
else if npmLock != null
85+
then fromNpmLock npmLock
86+
else if yarnLock != null
87+
then fromYarnLock yarnLock
88+
else if pnpmLock != null
89+
then fromPnpmLock pnpmLock
90+
else if bunLock != null
91+
then fromBunLock bunLock
92+
else {
93+
# builder pattern
94+
inherit
95+
fromCommit
96+
fromNpmLock
97+
fromYarnLock
98+
fromPnpmLock
99+
fromBunLock
100+
;
101+
}
98102
)

0 commit comments

Comments
 (0)