diff --git a/flake.nix b/flake.nix index 07827cd..1aa1d3d 100644 --- a/flake.nix +++ b/flake.nix @@ -85,6 +85,19 @@ (prisma-legacy.fromNpmLock ./npm/package-lock.json).env == (prisma-new "npmLock" ./npm/package-lock.json).env; pkgs.hello; + prisma-next = + (self.lib.prisma-factory { + pkgs = pkgs; + _commit = "next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513"; + hash = + { + x86_64-linux = "sha256-JWX+N/mmp9uJLcv4XFbQ3yg34fFf2BLIUpOLrrfTjEM="; + x86_64-darwin = "sha256-WNwFOoeDOebbfAh4y/NvZCyE9otaJdg2hHb4ifEFD+Y="; + aarch64-linux = "sha256-f9FuPZaGx0FwKo4pA9f8g82MTcAzYLwWslxjb7oqk6E="; + aarch64-darwin = "sha256-NMI+JcP3epBO3V37D19TDgzivMnPekgrYqUrXB6qNV0="; + } + .${pkgs.system}; + }).package; }; packages.default = (prisma-factory { diff --git a/lib/fetcher.nix b/lib/fetcher.nix index c5dd463..c23eb6d 100644 --- a/lib/fetcher.nix +++ b/lib/fetcher.nix @@ -14,6 +14,7 @@ binaryTarget, hash, components, + isv7, }: let componentsToFetch = @@ -26,6 +27,13 @@ let path = "bin/prisma-fmt"; env = "PRISMA_FMT_BINARY"; } + { + url = "schema-engine.gz"; + path = "bin/schema-engine"; + env = "PRISMA_SCHEMA_ENGINE_BINARY"; + } + ] + ++ lib.optionals (!isv7) [ { url = "query-engine.gz"; path = "bin/query-engine"; @@ -36,11 +44,6 @@ let path = "lib/libquery_engine.node"; env = "PRISMA_QUERY_ENGINE_LIBRARY"; } - { - url = "schema-engine.gz"; - path = "bin/schema-engine"; - env = "PRISMA_SCHEMA_ENGINE_BINARY"; - } ]; isDarwin = lib.strings.hasPrefix "darwin" binaryTarget; target = if isDarwin then binaryTarget else "${binaryTarget}-openssl-${opensslVersion}"; @@ -63,6 +66,7 @@ let mkdir -p $out $out/lib $out/bin ${lib.concatLines ( map (component: '' + echo '[nix-prisma-utils] fetching ${toUrl component.url} to $out/${component.path}' curl "${toUrl component.url}" -L | gunzip > $out/${component.path} '') componentsToFetch )} diff --git a/lib/legacyFetcher.nix b/lib/legacyFetcher.nix index 70ea33a..b747335 100644 --- a/lib/legacyFetcher.nix +++ b/lib/legacyFetcher.nix @@ -10,6 +10,7 @@ commit, opensslVersion, binaryTarget, + isv7, # = hashes prisma-fmt-hash, query-engine-hash, @@ -32,6 +33,21 @@ let path = "bin/prisma-fmt"; variable = "PRISMA_FMT_BINARY"; } + ] + ++ ( + if schema-engine-hash == null then + [ ] + else + [ + { + name = "schema-engine"; + hash = schema-engine-hash; + path = "bin/schema-engine"; + variable = "PRISMA_SCHEMA_ENGINE_BINARY"; + } + ] + ) + ++ lib.optionals (!isv7) [ { name = "query-engine"; hash = query-engine-hash; @@ -70,19 +86,6 @@ let variable = "PRISMA_MIGRATION_ENGINE_BINARY"; } ] - ) - ++ ( - if schema-engine-hash == null then - [ ] - else - [ - { - name = "schema-engine"; - hash = schema-engine-hash; - path = "bin/schema-engine"; - variable = "PRISMA_SCHEMA_ENGINE_BINARY"; - } - ] ); downloadedFiles = builtins.map ( file: diff --git a/prisma.nix b/prisma.nix index e1f9954..386ff81 100644 --- a/prisma.nix +++ b/prisma.nix @@ -31,10 +31,17 @@ let parsers = pkgs.callPackage ./lib/parsers.nix { }; binaryTarget = binaryTargetBySystem.${pkgs.system}; fromCommit = - commit: + _commit: + let + # HACK: _commit may be "next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513" instead of "0c19ccc313cf9911a90d99d2ac2eb0280c76c513" + commit = lib.strings.removePrefix "next-" _commit; + # prisma >= v7 has fewer components + isv7 = lib.strings.hasPrefix "next-" _commit; + in if builtins.stringLength commit != 40 then throw "invalid commit: got ${commit}" else if hash != null then + # use new fetcher pkgs.callPackage ./lib/fetcher.nix { inherit commit @@ -43,9 +50,9 @@ let binaryTarget hash components + isv7 ; } - # use new fetcher else pkgs.callPackage ./lib/legacyFetcher.nix { inherit @@ -53,6 +60,7 @@ let openssl opensslVersion binaryTarget + isv7 prisma-fmt-hash query-engine-hash libquery-engine-hash