From 8f0491a33b9ac995db239b2f60f85498e8a83017 Mon Sep 17 00:00:00 2001 From: Patrik Stutz Date: Sat, 6 Dec 2025 12:43:45 +0100 Subject: [PATCH 1/3] 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 --- flake.nix | 16 +++--- legacy-api.md | 147 +++++++++++++++++++++++++++++++++++++++++++++++ lib/parsers.nix | 44 ++++++++------ prisma.nix | 49 +++++++++------- readme.md | 150 ++---------------------------------------------- 5 files changed, 218 insertions(+), 188 deletions(-) create mode 100644 legacy-api.md diff --git a/flake.nix b/flake.nix index 1aa1d3d..bde0b4b 100644 --- a/flake.nix +++ b/flake.nix @@ -88,7 +88,7 @@ prisma-next = (self.lib.prisma-factory { pkgs = pkgs; - _commit = "next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513"; + versionString = "6.20.0-16.next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513"; hash = { x86_64-linux = "sha256-JWX+N/mmp9uJLcv4XFbQ3yg34fFf2BLIUpOLrrfTjEM="; @@ -103,15 +103,17 @@ (prisma-factory { inherit pkgs; hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; - _commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e"; + versionString = "5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e"; }).package; devShells.default = let - prisma = prisma-factory { - inherit pkgs; - hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; - _commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e"; - }; + prisma = ( + prisma-factory { + inherit pkgs; + hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; + versionString = "5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e"; + } + ); in pkgs.mkShell { buildInputs = [ diff --git a/legacy-api.md b/legacy-api.md new file mode 100644 index 0000000..55abc55 --- /dev/null +++ b/legacy-api.md @@ -0,0 +1,147 @@ +# Legacy API +In earlier versions of nix-prisma-utils the API was more like a factory pattern. +This API still works, but is now deprecated and we recommend switching to the new API. +We still try to support the legacy API for backwards compatibility, though. + +## Using `npm` + +```nix +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + prisma-utils.url = "github:VanCoding/nix-prisma-utils"; + }; + + outputs = + { nixpkgs, prisma-utils, ... }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + prisma = + (prisma-utils.lib.prisma-factory { + inherit pkgs; + # just copy these hashes for now, and then change them when nix complains about the mismatch + prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; + query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; + libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; + schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; + }).fromNpmLock + ./package-lock.json; # <--- path to our package-lock.json file that contains the version of prisma-engines + in + { + devShells.${system}.default = pkgs.mkShell { + env = prisma.env; + # or, you can use `shellHook` instead of `env` to load the same environment variables. + # shellHook = prisma.shellHook; + }; + }; +} + +``` + +## Using `yarn` + +both yarn v1 and yarn-berry should work. + +```nix +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + prisma-utils.url = "github:VanCoding/nix-prisma-utils"; + }; + + outputs = + { nixpkgs, prisma-utils, ... }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + prisma = + (prisma-utils.lib.prisma-factory { + inherit pkgs; + # just copy these hashes for now, and then change them when nix complains about the mismatch + prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; + query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; + libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; + schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; + }).fromYarnLock + ./yarn.lock; # <--- path to our yarn.lock file that contains the version of prisma-engines + in + { + devShells.${system}.default = pkgs.mkShell { + shellHook = prisma.shellHook; + }; + }; +} +``` + +## Using `pnpm` + +```nix +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + prisma-utils.url = "github:VanCoding/nix-prisma-utils"; + }; + + outputs = + { nixpkgs, prisma-utils, ... }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + prisma = + (prisma-utils.lib.prisma-factory { + inherit pkgs; + # just copy these hashes for now, and then change them when nix complains about the mismatch + prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; + query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; + libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; + schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; + }).fromPnpmLock + ./pnpm-lock.yaml; # <--- path to our pnpm-lock.yaml file that contains the version of prisma-engines + in + { + devShells.${system}.default = pkgs.mkShell { + env = prisma.env; + # or, you can use `shellHook` instead of `env` to load the same environment variables. + # shellHook = prisma.shellHook; + }; + }; +} + +``` + +## Using `bun` + +```nix +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + prisma-utils.url = "github:VanCoding/nix-prisma-utils"; + }; + + outputs = + { nixpkgs, prisma-utils, ... }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + prisma = + (prisma-utils.lib.prisma-factory { + inherit pkgs; + # just copy these hashes for now, and then change them when nix complains about the mismatch + prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; + query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; + libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; + schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; + }).fromBunLock + ./bun.lock; # <--- path to our bun.lock file that contains the version of prisma-engines. + # NOTE: does not work with bun.lockb! + in + { + devShells.${system}.default = pkgs.mkShell { + env = prisma.env; + # or, you can use `shellHook` instead of `env` to load the same environment variables. + # shellHook = prisma.shellHook; + }; + }; +} +``` diff --git a/lib/parsers.nix b/lib/parsers.nix index e5eb4f0..453c9fb 100644 --- a/lib/parsers.nix +++ b/lib/parsers.nix @@ -25,8 +25,7 @@ let # example: # a.b123c.d.e12345 # => e12345 - afterLastDot = text: lib.lists.last (lib.strings.splitString "." text); - + afterLastAt = text: lib.lists.last (lib.strings.splitString "@" text); readYAML = callPackage ./readYAML.nix { }; in # 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 let version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split "@prisma/engines-version/" pnpmLock) 2)) 0; in - lib.lists.last (lib.strings.splitString "." version); + lib.lists.last (lib.strings.splitString "/" version); # example line: # /@prisma/engines-version@5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e: @@ -59,7 +58,7 @@ in let version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split "@prisma/engines-version@" pnpmLock) 2)) 0; in - lib.lists.last (lib.strings.splitString "." version); + lib.lists.last (lib.strings.splitString "@" version); # exmple line: # '@prisma/engines-version@5.15.0-29.12e25d8d06f6ea5a0252864dd9a03b1bb51f3022': @@ -68,26 +67,25 @@ in let version = builtins.elemAt (builtins.split "'" (builtins.elemAt (builtins.split "@prisma/engines-version@" pnpmLock) 2)) 0; in - lib.lists.last (lib.strings.splitString "." version); + lib.lists.last (lib.strings.splitString "@" version); }; pnpmLock = builtins.readFile path; pnpmLockVersion = parsePnpmLockVersion pnpmLock; pnpmLockParser = pnpmLockParsers.${pnpmLockVersion}; - commit = pnpmLockParser pnpmLock; + versionString = pnpmLockParser pnpmLock; in - commit; + versionString; parseNpmLock = path: let packageLock = builtins.fromJSON (builtins.readFile path); - version = + versionString = if builtins.hasAttr "dependencies" packageLock then packageLock.dependencies.${"@prisma/engines-version"}.version else packageLock.packages.${"node_modules/@prisma/engines-version"}.version; - commit = lib.lists.last (lib.strings.splitString "." version); in - commit; + versionString; parseYarnLock = path: let @@ -109,15 +107,14 @@ in # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": # -> ["@prisma/engines-version@npm" "6" "3" "0-17" "acc0b9dd43eb689cbd20c9470515d719db10d0b0"] # -> acc0b9dd43eb689cbd20c9470515d719db10d0b0 - version = lib.lists.last ( + versionString = lib.lists.last ( splitMultipleAndFilterEmpty [ "\"" ":" - "." ] versionLine ); in - version; + versionString; isYarnLockV1 = file: lib.lists.any (line: lib.strings.trim line == "# yarn lockfile v1") ( @@ -190,7 +187,7 @@ in "0" = bunLockParsers."1"; "1" = lock: - afterLastDot ( + afterLastAt ( builtins.elemAt (lock."packages"."@prisma/engines-version" or (throw '' nix-prisma-utils: lockfile parsing error: package @prisma/engines-version not found. please make sure that you have @prisma/client installed. @@ -208,7 +205,22 @@ in nix-prisma-utils: Unsupported lockfile version: ${lockfileVersion} nix-prisma-utils currently supports bun.lock version of 0 and 1. ''); - commit = parse lockfile; + versionString = parse lockfile; in - commit; + versionString; + + parseVersionString = + versionString: + let + matches = lib.strings.match ''^([0-9]+)\.([0-9]+)\.([0-9]+).*([0-9a-fA-F]{40})$'' versionString; + in + if matches != null then + { + majorVersion = lib.toInt (lib.lists.elemAt matches 0); + minorVersion = lib.toInt (lib.lists.elemAt matches 1); + patchVersion = lib.toInt (lib.lists.elemAt matches 2); + commit = lib.lists.elemAt matches 3; + } + else + throw "nix-prisma-utils: Version string '${versionString}' does not match the expected format."; } diff --git a/prisma.nix b/prisma.nix index 386ff81..3599a01 100644 --- a/prisma.nix +++ b/prisma.nix @@ -6,8 +6,9 @@ openssl ? pkgs.openssl, # the openssl package to use # new fetcher args hash ? null, + versionString ? null, + version ? null, components ? null, # components to fetch - _commit ? null, # because package `commit` exists in nixpkgs npmLock ? null, yarnLock ? null, pnpmLock ? null, @@ -30,37 +31,33 @@ let inherit (pkgs) lib; parsers = pkgs.callPackage ./lib/parsers.nix { }; binaryTarget = binaryTargetBySystem.${pkgs.system}; - fromCommit = - _commit: + fromVersionString = + versionString: 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; + version = parsers.parseVersionString versionString; in - if builtins.stringLength commit != 40 then - throw "invalid commit: got ${commit}" - else if hash != null then + fromVersion version; + fromVersion = + version: + if hash != null then # use new fetcher pkgs.callPackage ./lib/fetcher.nix { inherit - commit openssl opensslVersion binaryTarget hash components - isv7 ; + commit = version.commit; + isv7 = version.majorVersion >= 7; } else pkgs.callPackage ./lib/legacyFetcher.nix { inherit - commit openssl opensslVersion binaryTarget - isv7 prisma-fmt-hash query-engine-hash libquery-engine-hash @@ -68,11 +65,13 @@ let migration-engine-hash schema-engine-hash ; + commit = version.commit; + isv7 = version.majorVersion >= 7; }; - fromNpmLock = file: fromCommit (parsers.parseNpmLock file); - fromPnpmLock = file: fromCommit (parsers.parsePnpmLock file); - fromYarnLock = file: fromCommit (parsers.parseYarnLock file); - fromBunLock = file: fromCommit (parsers.parseBunLock file); + fromNpmLock = file: fromVersionString (parsers.parseNpmLock file); + fromPnpmLock = file: fromVersionString (parsers.parsePnpmLock file); + fromYarnLock = file: fromVersionString (parsers.parseYarnLock file); + fromBunLock = file: fromVersionString (parsers.parseBunLock file); in lib.warnIf (nixpkgs != null) '' @@ -82,8 +81,10 @@ lib.warnIf (nixpkgs != null) if your code has `nixpkgs = pkgs;`, replace it with `pkgs = pkgs;` or `inherit pkgs;`. '' ( - if _commit != null then - fromCommit _commit + if version != null then + fromVersion version + else if versionString != null then + fromVersionString versionString else if npmLock != null then fromNpmLock npmLock else if yarnLock != null then @@ -96,11 +97,17 @@ lib.warnIf (nixpkgs != null) { # builder pattern inherit - fromCommit + fromVersionString + fromVersion fromNpmLock fromYarnLock fromPnpmLock fromBunLock ; + + fromCommit = + commit: + builtins.throw "nix-prisma-utils: fromCommit is no longer supported. please set either npmLock, yarnLock, pnpmLock, bunLock or use fromVersion instead."; + } ) diff --git a/readme.md b/readme.md index 5e72914..80e711b 100644 --- a/readme.md +++ b/readme.md @@ -42,7 +42,10 @@ With nix-prisma-utils it's the other way around. You can simply install prisma t # pnpmLock = ./pnpm-lock.yaml; # bunLock = ./bun.lock; # or if you want to specify the prisma commit directly - # _commit = "..."; + # version = { + # majorVersion = 7; + # commit = "...."; + # }; }; in { @@ -55,150 +58,9 @@ With nix-prisma-utils it's the other way around. You can simply install prisma t } ``` -## Legacy fetchers & API +## Legacy API -### Using `npm` - -```nix -{ - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - prisma-utils.url = "github:VanCoding/nix-prisma-utils"; - }; - - outputs = - { nixpkgs, prisma-utils, ... }: - let - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - prisma = - (prisma-utils.lib.prisma-factory { - inherit pkgs; - # just copy these hashes for now, and then change them when nix complains about the mismatch - prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; - query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; - libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; - schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; - }).fromNpmLock - ./package-lock.json; # <--- path to our package-lock.json file that contains the version of prisma-engines - in - { - devShells.${system}.default = pkgs.mkShell { - env = prisma.env; - # or, you can use `shellHook` instead of `env` to load the same environment variables. - # shellHook = prisma.shellHook; - }; - }; -} - -``` - -### Using `yarn` - -both yarn v1 and yarn-berry should work. - -```nix -{ - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - prisma-utils.url = "github:VanCoding/nix-prisma-utils"; - }; - - outputs = - { nixpkgs, prisma-utils, ... }: - let - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - prisma = - (prisma-utils.lib.prisma-factory { - inherit pkgs; - # just copy these hashes for now, and then change them when nix complains about the mismatch - prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; - query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; - libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; - schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; - }).fromYarnLock - ./yarn.lock; # <--- path to our yarn.lock file that contains the version of prisma-engines - in - { - devShells.${system}.default = pkgs.mkShell { - shellHook = prisma.shellHook; - }; - }; -} -``` - -### Using `pnpm` - -```nix -{ - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - prisma-utils.url = "github:VanCoding/nix-prisma-utils"; - }; - - outputs = - { nixpkgs, prisma-utils, ... }: - let - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - prisma = - (prisma-utils.lib.prisma-factory { - inherit pkgs; - # just copy these hashes for now, and then change them when nix complains about the mismatch - prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; - query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; - libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; - schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; - }).fromPnpmLock - ./pnpm-lock.yaml; # <--- path to our pnpm-lock.yaml file that contains the version of prisma-engines - in - { - devShells.${system}.default = pkgs.mkShell { - env = prisma.env; - # or, you can use `shellHook` instead of `env` to load the same environment variables. - # shellHook = prisma.shellHook; - }; - }; -} - -``` - -### Using `bun` - -```nix -{ - inputs = { - nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - prisma-utils.url = "github:VanCoding/nix-prisma-utils"; - }; - - outputs = - { nixpkgs, prisma-utils, ... }: - let - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - prisma = - (prisma-utils.lib.prisma-factory { - inherit pkgs; - # just copy these hashes for now, and then change them when nix complains about the mismatch - prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; - query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; - libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; - schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; - }).fromBunLock - ./bun.lock; # <--- path to our bun.lock file that contains the version of prisma-engines. - # NOTE: does not work with bun.lockb! - in - { - devShells.${system}.default = pkgs.mkShell { - env = prisma.env; - # or, you can use `shellHook` instead of `env` to load the same environment variables. - # shellHook = prisma.shellHook; - }; - }; -} -``` +The [Legacy API](./legacy-api.md) (with fromNpmLock, fromYarnLock, etc.) is now deprecated and we recommend switching to the new API above. ## Contributing From 4458baccee07dc03f45bb0b005c2d3361b40b0a7 Mon Sep 17 00:00:00 2001 From: Patrik Stutz Date: Mon, 8 Dec 2025 12:10:28 +0100 Subject: [PATCH 2/3] 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 --- lib/components.nix | 60 ++++++++++++++++++++++++++++++ lib/fetcher.nix | 44 ++++------------------ lib/legacyFetcher.nix | 86 +++++++++---------------------------------- lib/parsers.nix | 5 ++- prisma.nix | 8 +--- 5 files changed, 90 insertions(+), 113 deletions(-) create mode 100644 lib/components.nix diff --git a/lib/components.nix b/lib/components.nix new file mode 100644 index 0000000..41c143c --- /dev/null +++ b/lib/components.nix @@ -0,0 +1,60 @@ +{ lib, ... }: +let + isv7 = + version: + version.majorVersion >= 7 + || ( + version.majorVersion == 6 + && version.minorVersion >= 19 + && lib.strings.hasInfix "next" version.preReleaseVersion + ); + components = [ + { + name = "migration-engine"; + getFileName = isDarwin: "migration-engine.gz"; + path = "bin/migration-engine"; + variable = "PRISMA_MIGRATION_ENGINE_BINARY"; + isIncluded = version: false; + } + { + name = "prisma-fmt"; + getFileName = isDarwin: "prisma-fmt.gz"; + path = "bin/prisma-fmt"; + variable = "PRISMA_FMT_BINARY"; + isIncluded = version: true; + } + { + name = "schema-engine"; + getFileName = isDarwin: "schema-engine.gz"; + path = "bin/schema-engine"; + variable = "PRISMA_SCHEMA_ENGINE_BINARY"; + isIncluded = version: true; + } + { + name = "query-engine"; + getFileName = isDarwin: "query-engine.gz"; + path = "bin/query-engine"; + variable = "PRISMA_QUERY_ENGINE_BINARY"; + isIncluded = version: !(isv7 version); + } + { + name = "libquery-engine"; + getFileName = + isDarwin: if isDarwin then "libquery_engine.dylib.node.gz" else "libquery_engine.so.node.gz"; + path = "lib/libquery_engine.node"; + variable = "PRISMA_QUERY_ENGINE_LIBRARY"; + isIncluded = version: !(isv7 version); + } + { + name = "introspection-engine"; + getFileName = isDarwin: "introspection-engine.gz"; + path = "bin/introspection-engine"; + variable = "PRISMA_INTROSPECTION_ENGINE_BINARY"; + isIncluded = version: false; + } + ]; +in +{ + fromVersion = version: lib.filter (component: component.isIncluded version) components; + fromHashes = hashes: lib.filter (component: ((hashes."${component.name}-hash") != null)) components; +} diff --git a/lib/fetcher.nix b/lib/fetcher.nix index c23eb6d..e619381 100644 --- a/lib/fetcher.nix +++ b/lib/fetcher.nix @@ -8,46 +8,18 @@ runCommand, gzip, # variables - commit, openssl, opensslVersion, binaryTarget, hash, - components, - isv7, + version, + callPackage, }: let - componentsToFetch = - if components != null then - components - else - [ - { - url = "prisma-fmt.gz"; - 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"; - env = "PRISMA_QUERY_ENGINE_BINARY"; - } - { - url = if isDarwin then "libquery_engine.dylib.node.gz" else "libquery_engine.so.node.gz"; - path = "lib/libquery_engine.node"; - env = "PRISMA_QUERY_ENGINE_LIBRARY"; - } - ]; + componentsToFetch = (callPackage ./components.nix { }).fromVersion version; isDarwin = lib.strings.hasPrefix "darwin" binaryTarget; target = if isDarwin then binaryTarget else "${binaryTarget}-openssl-${opensslVersion}"; - toUrl = url: "https://binaries.prisma.sh/all_commits/${commit}/${target}/${url}"; + toUrl = url: "https://binaries.prisma.sh/all_commits/${version.commit}/${target}/${url}"; deps = runCommand "prisma-deps-bin" { @@ -66,15 +38,15 @@ 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} + echo '[nix-prisma-utils] fetching ${toUrl (component.getFileName isDarwin)} to $out/${component.path}' + curl "${toUrl (component.getFileName isDarwin)}" -L | gunzip > $out/${component.path} '') componentsToFetch )} ''; package = stdenv.mkDerivation { pname = "prisma-bin"; src = deps; - version = commit; + version = version.commit; nativeBuildInputs = [ zlib openssl @@ -101,7 +73,7 @@ let package: builtins.listToAttrs ( builtins.map (c: { - name = c.env; + name = c.variable; value = "${package}/${c.path}"; }) componentsToFetch ); diff --git a/lib/legacyFetcher.nix b/lib/legacyFetcher.nix index b747335..8180cb4 100644 --- a/lib/legacyFetcher.nix +++ b/lib/legacyFetcher.nix @@ -1,4 +1,4 @@ -{ +hashes@{ # dependencies lib, fetchurl, @@ -7,10 +7,8 @@ autoPatchelfHook, # variables openssl, - commit, opensslVersion, binaryTarget, - isv7, # = hashes prisma-fmt-hash, query-engine-hash, @@ -18,6 +16,8 @@ introspection-engine-hash, migration-engine-hash, schema-engine-hash, + version, + callPackage, }: let hostname = "binaries.prisma.sh"; @@ -25,76 +25,24 @@ let isDarwin = lib.strings.hasPrefix "darwin" binaryTarget; target = if isDarwin then binaryTarget else "${binaryTarget}-openssl-${opensslVersion}"; baseUrl = "https://${hostname}/${channel}"; - files = - [ - { - name = "prisma-fmt"; - hash = prisma-fmt-hash; - 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; - path = "bin/query-engine"; - variable = "PRISMA_QUERY_ENGINE_BINARY"; - } - { - name = if isDarwin then "libquery_engine.dylib.node" else "libquery_engine.so.node"; - hash = libquery-engine-hash; - path = "lib/libquery_engine.node"; - variable = "PRISMA_QUERY_ENGINE_LIBRARY"; - } - ] - ++ ( - if introspection-engine-hash == null then - [ ] - else - [ - { - name = "introspection-engine"; - hash = introspection-engine-hash; - path = "bin/introspection-engine"; - variable = "PRISMA_INTROSPECTION_ENGINE_BINARY"; - } - ] - ) - ++ ( - if migration-engine-hash == null then - [ ] - else - [ - { - name = "migration-engine"; - hash = migration-engine-hash; - path = "bin/migration-engine"; - variable = "PRISMA_MIGRATION_ENGINE_BINARY"; - } - ] - ); + files = (callPackage ./components.nix { }).fromHashes { + inherit + prisma-fmt-hash + query-engine-hash + libquery-engine-hash + introspection-engine-hash + migration-engine-hash + schema-engine-hash + ; + }; downloadedFiles = builtins.map ( file: file // { file = fetchurl { - name = "${baseUrl}/${commit}/${target}/${file.name}.gz"; - url = "${baseUrl}/${commit}/${target}/${file.name}.gz"; - hash = file.hash; + name = "${baseUrl}/${version.commit}/${target}/${file.getFileName isDarwin}"; + url = "${baseUrl}/${version.commit}/${target}/${file.getFileName isDarwin}"; + hash = hashes."${file.name}-hash"; }; } ) files; @@ -136,7 +84,7 @@ in rec { package = stdenv.mkDerivation { pname = "prisma-bin"; - version = commit; + version = version.commit; nativeBuildInputs = [ zlib openssl diff --git a/lib/parsers.nix b/lib/parsers.nix index 453c9fb..c2bb43f 100644 --- a/lib/parsers.nix +++ b/lib/parsers.nix @@ -212,14 +212,15 @@ in parseVersionString = versionString: let - matches = lib.strings.match ''^([0-9]+)\.([0-9]+)\.([0-9]+).*([0-9a-fA-F]{40})$'' versionString; + matches = lib.strings.match ''^([0-9]+)\.([0-9]+)\.([0-9]+)(.*)([0-9a-fA-F]{40})$'' versionString; in if matches != null then { majorVersion = lib.toInt (lib.lists.elemAt matches 0); minorVersion = lib.toInt (lib.lists.elemAt matches 1); patchVersion = lib.toInt (lib.lists.elemAt matches 2); - commit = lib.lists.elemAt matches 3; + preReleaseVersion = lib.lists.elemAt matches 3; + commit = lib.lists.elemAt matches 4; } else throw "nix-prisma-utils: Version string '${versionString}' does not match the expected format."; diff --git a/prisma.nix b/prisma.nix index 3599a01..24d61ae 100644 --- a/prisma.nix +++ b/prisma.nix @@ -8,7 +8,6 @@ hash ? null, versionString ? null, version ? null, - components ? null, # components to fetch npmLock ? null, yarnLock ? null, pnpmLock ? null, @@ -47,10 +46,8 @@ let opensslVersion binaryTarget hash - components + version ; - commit = version.commit; - isv7 = version.majorVersion >= 7; } else pkgs.callPackage ./lib/legacyFetcher.nix { @@ -64,9 +61,8 @@ let introspection-engine-hash migration-engine-hash schema-engine-hash + version ; - commit = version.commit; - isv7 = version.majorVersion >= 7; }; fromNpmLock = file: fromVersionString (parsers.parseNpmLock file); fromPnpmLock = file: fromVersionString (parsers.parsePnpmLock file); From 15b656c1c3b866cbb8c6a12e77b177cb3d602d66 Mon Sep 17 00:00:00 2001 From: Patrik Stutz Date: Mon, 8 Dec 2025 12:21:49 +0100 Subject: [PATCH 3/3] do not include the first dash in preReleaseVersion --- lib/parsers.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/parsers.nix b/lib/parsers.nix index c2bb43f..6398a62 100644 --- a/lib/parsers.nix +++ b/lib/parsers.nix @@ -212,7 +212,7 @@ in parseVersionString = versionString: let - matches = lib.strings.match ''^([0-9]+)\.([0-9]+)\.([0-9]+)(.*)([0-9a-fA-F]{40})$'' versionString; + matches = lib.strings.match ''^([0-9]+)\.([0-9]+)\.([0-9]+)-(.*)([0-9a-fA-F]{40})$'' versionString; in if matches != null then {