From 28de217bc41d7c71873adda19e4fc9ca7ffff7b7 Mon Sep 17 00:00:00 2001 From: aster <137767097+aster-void@users.noreply.github.com> Date: Wed, 29 Oct 2025 14:04:09 +0900 Subject: [PATCH 1/5] feat: new fetcher with simplified API --- .gitignore | 2 + flake.nix | 64 ++++--- lib/fetcher.nix | 110 +++++++++++ lib/legacyFetcher.nix | 158 ++++++++++++++++ lib/parsers.nix | 193 +++++++++++++++++++ prisma.nix | 430 +++++++----------------------------------- readme.md | 36 ++++ tests.nix | 139 +++++++------- 8 files changed, 674 insertions(+), 458 deletions(-) create mode 100644 lib/fetcher.nix create mode 100644 lib/legacyFetcher.nix create mode 100644 lib/parsers.nix diff --git a/.gitignore b/.gitignore index 87f1d08..e31d13f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules .direnv +result +result-* diff --git a/flake.nix b/flake.nix index 3f0e607..c771029 100644 --- a/flake.nix +++ b/flake.nix @@ -5,42 +5,48 @@ treefmt-nix.url = "github:numtide/treefmt-nix"; treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = - { - self, - nixpkgs, - flake-utils, - treefmt-nix, - }: - let - prisma-factory = import ./prisma.nix; - in + outputs = { + self, + nixpkgs, + flake-utils, + treefmt-nix, + }: let + prisma-factory = import ./prisma.nix; + in flake-utils.lib.eachDefaultSystem ( - system: - let + system: let pkgs = nixpkgs.legacyPackages.${system}; yarn-v1 = pkgs.writeShellApplication { name = "yarn-v1"; checkPhase = ""; - runtimeInputs = [ pkgs.yarn ]; + runtimeInputs = [pkgs.yarn]; text = "yarn $@"; }; yarn-berry = pkgs.writeShellApplication { name = "yarn-berry"; checkPhase = ""; - runtimeInputs = [ pkgs.yarn-berry ]; + runtimeInputs = [pkgs.yarn-berry]; text = "yarn $@"; }; treefmt = treefmt-nix.lib.evalModule pkgs { # nixfmt is nixfmt-rfc-style programs.nixfmt.enable = true; }; - in - { + in { formatter = treefmt.config.build.wrapper; checks = (pkgs.callPackages ./tests.nix { + fetcherMode = "new"; + inherit + pkgs + prisma-factory + yarn-v1 + yarn-berry + ; + }) + // (pkgs.callPackages ./tests.nix { + fetcherMode = "legacy"; inherit pkgs prisma-factory @@ -51,19 +57,19 @@ // { format = treefmt.config.build.check self; }; - devShells.default = - let - prisma = ( - (prisma-factory { - inherit pkgs; - prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; - query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; - libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; - schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; - }).fromCommit - "6a3747c37ff169c90047725a05a6ef02e32ac97e" - ); - in + packages.default = + (prisma-factory { + inherit pkgs; + hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; + _commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e"; + }).package; + devShells.default = let + prisma = prisma-factory { + inherit pkgs; + hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; + _commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e"; + }; + in pkgs.mkShell { buildInputs = [ pkgs.nodejs-18_x diff --git a/lib/fetcher.nix b/lib/fetcher.nix new file mode 100644 index 0000000..14b96bd --- /dev/null +++ b/lib/fetcher.nix @@ -0,0 +1,110 @@ +{ + lib, + stdenv, + zlib, + curl, + cacert, + autoPatchelfHook, + runCommand, + gzip, + # variables + commit, + openssl, + opensslVersion, + binaryTarget, + hash, + components, +}: let + componentsToFetch = + if components != null + then components + else [ + { + url = "prisma-fmt.gz"; + path = "bin/prisma-fmt"; + env = "PRISMA_FMT_BINARY"; + } + { + 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"; + } + { + 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}"; + toUrl = url: "https://binaries.prisma.sh/all_commits/${commit}/${target}/${url}"; + deps = + runCommand "prisma-deps-bin" { + nativeBuildInputs = [ + curl + cacert + gzip + ]; + outputHashAlgo = "sha256"; + outputHashMode = "recursive"; + outputHash = hash; + } '' + export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt + export CURL_CA_BUNDLE=$SSL_CERT_FILE + mkdir -p $out $out/lib $out/bin + ${lib.concatLines ( + map (component: '' + curl "${toUrl component.url}" -L | gunzip > $out/${component.path} + '') + componentsToFetch + )} + ''; + package = stdenv.mkDerivation { + pname = "prisma-bin"; + src = deps; + version = commit; + nativeBuildInputs = + [ + zlib + openssl + stdenv.cc.cc.lib + ] + ++ lib.optionals (!isDarwin) [autoPatchelfHook]; + phases = [ + "installPhase" + "postFixupHooks" + ]; + installPhase = '' + mkdir -p $out + cp -r $src/. $out/ + mkdir -p $out/bin + chmod -R u+w $out + find $out/bin -type f -exec chmod +x {} + + ''; + }; + toExportStyle = attrset: + "\n" + (lib.concatMapAttrsStringSep "\n" (name: value: "export ${name}=\"${value}\"") attrset) + "\n"; + mkEnv = package: + builtins.listToAttrs ( + builtins.map (c: { + name = c.env; + value = "${package}/${c.path}"; + }) + componentsToFetch + ); + env = mkEnv package; +in { + inherit package env; + shellHook = toExportStyle env; +} diff --git a/lib/legacyFetcher.nix b/lib/legacyFetcher.nix new file mode 100644 index 0000000..725e2dc --- /dev/null +++ b/lib/legacyFetcher.nix @@ -0,0 +1,158 @@ +{ + # dependencies + lib, + fetchurl, + stdenv, + zlib, + autoPatchelfHook, + # variables + openssl, + commit, + opensslVersion, + binaryTarget, + # = hashes + prisma-fmt-hash, + query-engine-hash, + libquery-engine-hash, + introspection-engine-hash, + migration-engine-hash, + schema-engine-hash, +}: let + hostname = "binaries.prisma.sh"; + channel = "all_commits"; + 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"; + } + { + 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"; + } + ] + ) + ++ ( + 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: + file + // { + file = fetchurl { + name = "${baseUrl}/${commit}/${target}/${file.name}.gz"; + url = "${baseUrl}/${commit}/${target}/${file.name}.gz"; + hash = file.hash; + }; + } + ) + files; + unzipCommands = builtins.map (file: "gunzip -c ${file.file} > $out/${file.path}") downloadedFiles; + + mkEnv = package: + builtins.listToAttrs ( + builtins.map (file: { + name = file.variable; + value = "${package}/${file.path}"; + }) + files + ); + # polyfill: the function in nixpkgs is implemented on Dec 6, 2024. replace this with one from pkgs.lib after 24.11 reaches EOL. + concatMapAttrsStringSep = sep: f: attrs: + lib.concatStringsSep sep (lib.attrValues (lib.mapAttrs f attrs)); + /** + This function converts attrset to bash export style. + return value contains leading and trailing newlines. + + # Example + ```nix + toExportStyle { foo = "bar"; baz = "abc"; } + => + '' + export foo="bar" + export baz="abc" + '' + ``` + + # Type + toExportStyle :: Attrset -> String + */ + toExportStyle = attrset: + "\n" + (concatMapAttrsStringSep "\n" (name: value: "export ${name}=\"${value}\"") attrset) + "\n"; +in rec { + package = stdenv.mkDerivation { + pname = "prisma-bin"; + version = commit; + nativeBuildInputs = + [ + zlib + openssl + stdenv.cc.cc.lib + ] + ++ lib.optionals (!isDarwin) [autoPatchelfHook]; + phases = [ + "buildPhase" + "postFixupHooks" + ]; + buildPhase = '' + mkdir -p $out/bin + mkdir -p $out/lib + ${lib.concatStringsSep "\n" unzipCommands} + chmod +x $out/bin/* + ''; + }; + env = mkEnv package; + shellHook = toExportStyle env; +} diff --git a/lib/parsers.nix b/lib/parsers.nix new file mode 100644 index 0000000..8c1db36 --- /dev/null +++ b/lib/parsers.nix @@ -0,0 +1,193 @@ +{ + lib, + callPackage, +}: let + lines = s: lib.strings.splitString "\n" s; + + # example: + # splitMultiple ["|" "," "-"] "a-|b,c-d" + # -> ["a" "" "b" "c" "d"] + splitMultiple = delims: s: _splitMultiple delims [s]; + # example: + # _splitMultiple ["|" "," "-"] ["a-|b,c-d"] + # -> ["a" "" "b" "c" "d"] + _splitMultiple = delims: list: + if builtins.length delims == 0 + then list + else let + splitStr = map (str: lib.strings.splitString (builtins.elemAt delims 0) str) list; + in + _splitMultiple (lib.drop 1 delims) (lib.lists.concatLists splitStr); + splitMultipleAndFilterEmpty = delims: s: builtins.filter (str: str != "") (splitMultiple delims s); + # example: + # a.b123c.d.e12345 + # => e12345 + afterLastDot = text: lib.lists.last (lib.strings.splitString "." text); + + readYAML = callPackage ./lib/readYAML.nix {}; + # polyfill: the function in nixis implemented on Dec 6, 2024. replace this with one from lib after 24.11 reaches EOL. +in { + parsePnpmLock = path: let + parsePnpmLockVersion = pnpmLock: + if lib.strings.hasPrefix "lockfileVersion: 5" pnpmLock + then "5" + else if lib.strings.hasPrefix "lockfileVersion: '6" pnpmLock + then "6" + else "9"; + pnpmLockParsers = { + # example line: + # /@prisma/engines-version/5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e: + "5" = pnpmLock: let + version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split "@prisma/engines-version/" pnpmLock) 2)) 0; + in + lib.lists.last (lib.strings.splitString "." version); + + # example line: + # /@prisma/engines-version@5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e: + "6" = pnpmLock: let + version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split "@prisma/engines-version@" pnpmLock) 2)) 0; + in + lib.lists.last (lib.strings.splitString "." version); + + # exmple line: + # '@prisma/engines-version@5.15.0-29.12e25d8d06f6ea5a0252864dd9a03b1bb51f3022': + "9" = pnpmLock: let + version = builtins.elemAt (builtins.split "'" (builtins.elemAt (builtins.split "@prisma/engines-version@" pnpmLock) 2)) 0; + in + lib.lists.last (lib.strings.splitString "." version); + }; + pnpmLock = builtins.readFile path; + pnpmLockVersion = parsePnpmLockVersion pnpmLock; + pnpmLockParser = pnpmLockParsers.${pnpmLockVersion}; + commit = pnpmLockParser pnpmLock; + in + commit; + parseNpmLock = path: let + packageLock = builtins.fromJSON (builtins.readFile path); + version = + 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; + parseYarnLock = path: let + # find this line from yarn.lock: + # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": + yarnLockParser1 = file: let + versionLine = + lib.lists.findFirst + (line: builtins.length (lib.strings.splitString "@prisma/engines-version" line) >= 2) + # else + (throw '' + nix-prisma-utils/yarnLockParser1: package @prisma/engines-version not found in lockfile ${path} . + please make sure you have installed `@prisma/client`. + if you have already installed `@prisma/client` and still see this, please report this to nix-prisma-utils. + '') + (lines file); + # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": + # -> ["@prisma/engines-version@npm" "6" "3" "0-17" "acc0b9dd43eb689cbd20c9470515d719db10d0b0"] + # -> acc0b9dd43eb689cbd20c9470515d719db10d0b0 + version = lib.lists.last ( + splitMultipleAndFilterEmpty [ + "\"" + ":" + "." + ] + versionLine + ); + in + version; + isYarnLockV1 = file: + lib.lists.any (line: lib.strings.trim line == "# yarn lockfile v1") ( + lib.strings.splitString "\n" file + ); + # example line: + # "@prisma/engines-version@6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": + yarnV1LockParser = yarnLockParser1; + # example line: + # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": + yarnBerryLockParsers = { + "8" = yarnLockParser1; + }; + + lockfile = builtins.readFile path; + parse = + if isYarnLockV1 lockfile + then yarnV1LockParser + else let + lockfileVersion = builtins.toString (readYAML path).__metadata.version; + in + yarnBerryLockParsers.${ + lockfileVersion + } or (throw '' + nix-prisma-utils: unknown lockfile version ${lockfileVersion}. + please report this to nix-prisma-utils with your lockfile. + ''); + in (parse lockfile); + parseBunLock = path: let + # HACK: nix doesn't support JSONC parsing, so currently doing + # 1. remove whitespace and newline + # 2. replace ",}" with "}" + # 3. replace ",]" with "]" + # to support JSON with trailing comma. + # Keep in mind that this removes all whitespaces / tab / newline in the key / value + # and doesn't support comments. + fromJSONWithTrailingComma = jsonc: + builtins.fromJSON ( + builtins.replaceStrings + [ + ",}" + ",]" + ] + [ + "}" + "]" + ] + ( + builtins.replaceStrings + [ + " " + "\t" + "\n" + ] + [ + "" + "" + "" + ] + jsonc + ) + ); + bunLockParsers = { + # example: + # nu> open bun.lock | from json | get packages.@prisma/engines-version.0 + # @prisma/engines-version@5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e + "0" = bunLockParsers."1"; + "1" = lock: + afterLastDot ( + 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. + '') + ) + 0 + ); + }; + lockfile = fromJSONWithTrailingComma ( + assert builtins.typeOf path == "path"; + builtins.readFile path + ); + lockfileVersion = builtins.toString lockfile."lockfileVersion"; + parse = + bunLockParsers.${ + lockfileVersion + } or (throw '' + nix-prisma-utils: Unsupported lockfile version: ${lockfileVersion} + nix-prisma-utils currently supports bun.lock version of 0 and 1. + ''); + commit = parse lockfile; + in + commit; +} diff --git a/prisma.nix b/prisma.nix index 3b05641..b09c718 100644 --- a/prisma.nix +++ b/prisma.nix @@ -4,11 +4,20 @@ pkgs ? nixpkgs, opensslVersion ? "3.0.x", # can be 3.0.x, 1.1.x or 1.0.x openssl ? pkgs.openssl, # the openssl package to use + # new fetcher args + hash ? null, + components ? null, # components to fetch + _commit ? null, # because package `commit` exists in nixpkgs + npmLock ? null, + yarnLock ? null, + pnpmLock ? null, + bunLock ? null, + # legacy fetcher args introspection-engine-hash ? null, migration-engine-hash ? null, - prisma-fmt-hash, - query-engine-hash, - libquery-engine-hash, + prisma-fmt-hash ? null, + query-engine-hash ? null, + libquery-engine-hash ? null, schema-engine-hash ? null, binaryTargetBySystem ? { x86_64-linux = "debian"; @@ -16,368 +25,71 @@ x86_64-darwin = "darwin"; aarch64-darwin = "darwin-arm64"; }, -}: -let +}: let inherit (pkgs) lib; - lines = s: lib.strings.splitString "\n" s; - - # example: - # splitMultiple ["|" "," "-"] "a-|b,c-d" - # -> ["a" "" "b" "c" "d"] - splitMultiple = delims: s: _splitMultiple delims [ s ]; - # example: - # _splitMultiple ["|" "," "-"] ["a-|b,c-d"] - # -> ["a" "" "b" "c" "d"] - _splitMultiple = - delims: list: - if builtins.length delims == 0 then - list + parsers = pkgs.callPackage ./lib/parsers.nix {}; + binaryTarget = binaryTargetBySystem.${pkgs.system}; + commitValue = + if _commit != null + then _commit + else if npmLock != null + then fromNpmLock npmLock + else if yarnLock != null + then fromYarnLock yarnLock + else if pnpmLock != null + then fromPnpmLock pnpmLock + else if bunLock != null + then fromBunLock bunLock + else null; + fromCommit = commit: + if builtins.stringLength commit != 40 + then throw "invalid commit: got ${commit}" + else if hash != null + then + pkgs.callPackage ./lib/fetcher.nix { + inherit + commit + openssl + opensslVersion + binaryTarget + hash + components + ; + } + # use new fetcher else - let - splitStr = map (str: lib.strings.splitString (builtins.elemAt delims 0) str) list; - in - _splitMultiple (lib.drop 1 delims) (lib.lists.concatLists splitStr); - splitMultipleAndFilterEmpty = delims: s: builtins.filter (str: str != "") (splitMultiple delims s); - # example: - # a.b123c.d.e12345 - # => e12345 - afterLastDot = text: lib.lists.last (lib.strings.splitString "." text); - - readYAML = pkgs.callPackage ./lib/readYAML.nix { }; - # polyfill: the function in nixpkgs is implemented on Dec 6, 2024. replace this with one from pkgs.lib after 24.11 reaches EOL. - concatMapAttrsStringSep = - let - inherit (pkgs) lib; - in - sep: f: attrs: - lib.concatStringsSep sep (lib.attrValues (lib.mapAttrs f attrs)); - + pkgs.callPackage ./lib/legacyFetcher.nix { + inherit + commit + openssl + opensslVersion + binaryTarget + prisma-fmt-hash + query-engine-hash + libquery-engine-hash + introspection-engine-hash + migration-engine-hash + schema-engine-hash + ; + }; + fromNpmLock = file: fromCommit (parsers.parseNpmLock file); + fromPnpmLock = file: fromCommit (parsers.parsePnpmLock file); + fromYarnLock = file: fromCommit (parsers.parseYarnLock file); + fromBunLock = file: fromCommit (parsers.parseBunLock file); in -pkgs.lib.warnIf (nixpkgs != null) + lib.warnIf (nixpkgs != null) '' `nixpkgs` argument in nix-prisma-utils is deprecated. please replace it with `pkgs`. examples: if your code has `inherit nixpkgs;`, replace it with `pkgs = nixpkgs;`. if your code has `nixpkgs = pkgs;`, replace it with `pkgs = pkgs;` or `inherit pkgs;`. '' - rec { - fromCommit = - commit: - if builtins.stringLength commit != 40 then - throw "nvalid commit: got ${commit}" - else - let - hostname = "binaries.prisma.sh"; - channel = "all_commits"; - binaryTarget = binaryTargetBySystem.${pkgs.system}; - isDarwin = pkgs.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"; - } - { - 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"; - } - ] - ) - ++ ( - 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: - file - // { - file = pkgs.fetchurl { - name = "${baseUrl}/${commit}/${target}/${file.name}.gz"; - url = "${baseUrl}/${commit}/${target}/${file.name}.gz"; - hash = file.hash; - }; - } - ) files; - unzipCommands = builtins.map (file: "gunzip -c ${file.file} > $out/${file.path}") downloadedFiles; - - mkEnv = - package: - builtins.listToAttrs ( - builtins.map (file: { - name = file.variable; - value = "${package}/${file.path}"; - }) files - ); - /** - This function converts attrset to bash export style. - return value contains leading and trailing newlines. - - # Example - ```nix - toExportStyle { foo = "bar"; baz = "abc"; } - => - '' - export foo="bar" - export baz="abc" - '' - ``` - - # Type - toExportStyle :: Attrset -> String - */ - toExportStyle = - attrset: - "\n" + (concatMapAttrsStringSep "\n" (name: value: "export ${name}=\"${value}\"") attrset) + "\n"; - in - rec { - package = pkgs.stdenv.mkDerivation { - pname = "prisma-bin"; - version = commit; - nativeBuildInputs = [ - pkgs.zlib - openssl - pkgs.stdenv.cc.cc.lib - ] ++ pkgs.lib.optionals (!isDarwin) [ pkgs.autoPatchelfHook ]; - phases = [ - "buildPhase" - "postFixupHooks" - ]; - buildPhase = '' - mkdir -p $out/bin - mkdir -p $out/lib - ${pkgs.lib.concatStringsSep "\n" unzipCommands} - chmod +x $out/bin/* - ''; - }; - env = mkEnv package; - shellHook = toExportStyle env; - }; - fromPnpmLock = - path: - let - textAfter = keyword: text: builtins.elemAt (builtins.split keyword text) 1; - textBefore = keyword: text: builtins.elemAt (builtins.split keyword text) 0; - parsePnpmLockVersion = - pnpmLock: - if pkgs.lib.strings.hasPrefix "lockfileVersion: 5" pnpmLock then - "5" - else if pkgs.lib.strings.hasPrefix "lockfileVersion: '6" pnpmLock then - "6" - else - "9"; - pnpmLockParsers = { - # example line: - # /@prisma/engines-version/5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e: - "5" = - pnpmLock: - let - version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split ("@prisma/engines-version/") pnpmLock) 2)) 0; - in - pkgs.lib.lists.last (pkgs.lib.strings.splitString "." version); - - # example line: - # /@prisma/engines-version@5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e: - "6" = - pnpmLock: - let - version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split ("@prisma/engines-version@") pnpmLock) 2)) 0; - in - pkgs.lib.lists.last (pkgs.lib.strings.splitString "." version); - - # exmple line: - # '@prisma/engines-version@5.15.0-29.12e25d8d06f6ea5a0252864dd9a03b1bb51f3022': - "9" = - pnpmLock: - let - version = builtins.elemAt (builtins.split "'" (builtins.elemAt (builtins.split ("@prisma/engines-version@") pnpmLock) 2)) 0; - in - pkgs.lib.lists.last (pkgs.lib.strings.splitString "." version); - }; - pnpmLock = builtins.readFile path; - pnpmLockVersion = parsePnpmLockVersion pnpmLock; - pnpmLockParser = pnpmLockParsers.${pnpmLockVersion}; - commit = pnpmLockParser pnpmLock; - in - fromCommit commit; - fromNpmLock = - path: - let - packageLock = builtins.fromJSON (builtins.readFile path); - version = - if builtins.hasAttr "dependencies" packageLock then - packageLock.dependencies.${"@prisma/engines-version"}.version - else - packageLock.packages.${"node_modules/@prisma/engines-version"}.version; - commit = pkgs.lib.lists.last (pkgs.lib.strings.splitString "." version); - in - fromCommit commit; - fromYarnLock = - path: - let - # find this line from yarn.lock: - # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": - yarnLockParser1 = - file: - let - versionLine = - lib.lists.findFirst - (line: builtins.length (lib.strings.splitString "@prisma/engines-version" line) >= 2) - # else - (throw '' - nix-prisma-utils/yarnLockParser1: package @prisma/engines-version not found in lockfile ${path} . - please make sure you have installed `@prisma/client`. - if you have already installed `@prisma/client` and still see this, please report this to nix-prisma-utils. - '') - (lines file); - # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": - # -> ["@prisma/engines-version@npm" "6" "3" "0-17" "acc0b9dd43eb689cbd20c9470515d719db10d0b0"] - # -> acc0b9dd43eb689cbd20c9470515d719db10d0b0 - version = lib.lists.last ( - splitMultipleAndFilterEmpty [ - "\"" - ":" - "." - ] versionLine - ); - in - version; - isYarnLockV1 = - file: - lib.lists.any (line: lib.strings.trim line == "# yarn lockfile v1") ( - lib.strings.splitString "\n" file - ); - # example line: - # "@prisma/engines-version@6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": - yarnV1LockParser = yarnLockParser1; - # example line: - # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": - yarnBerryLockParsers = { - "8" = yarnLockParser1; - }; - - lockfile = builtins.readFile path; - parse = - if isYarnLockV1 lockfile then - yarnV1LockParser - else - let - lockfileVersion = builtins.toString (readYAML path).__metadata.version; - in - yarnBerryLockParsers.${lockfileVersion} or (throw '' - nix-prisma-utils: unknown lockfile version ${lockfileVersion}. - please report this to nix-prisma-utils with your lockfile. - ''); - in - fromCommit (parse lockfile); - fromBunLock = - path: - let - # HACK: nix doesn't support JSONC parsing, so currently doing - # 1. remove whitespace and newline - # 2. replace ",}" with "}" - # 3. replace ",]" with "]" - # to support JSON with trailing comma. - # Keep in mind that this removes all whitespaces / tab / newline in the key / value - # and doesn't support comments. - fromJSONWithTrailingComma = - jsonc: - builtins.fromJSON ( - builtins.replaceStrings - [ - ",}" - ",]" - ] - [ - "}" - "]" - ] - ( - builtins.replaceStrings - [ - " " - "\t" - "\n" - ] - [ - "" - "" - "" - ] - jsonc - ) - ); - bunLockParsers = { - # example: - # nu> open bun.lock | from json | get packages.@prisma/engines-version.0 - # @prisma/engines-version@5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e - "0" = bunLockParsers."1"; - "1" = - lock: - afterLastDot ( - 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. - '') - ) 0 - ); - }; - lockfile = fromJSONWithTrailingComma ( - assert builtins.typeOf path == "path"; - builtins.readFile path - ); - lockfileVersion = builtins.toString lockfile."lockfileVersion"; - parse = - bunLockParsers.${lockfileVersion} or (throw '' - nix-prisma-utils: Unsupported lockfile version: ${lockfileVersion} - nix-prisma-utils currently supports bun.lock version of 0 and 1. - ''); - commit = parse lockfile; - in - fromCommit commit; - } + ( + if commitValue != null + then # direct fetch + fromCommit commitValue + else { + # builder pattern + inherit fromCommit fromNpmLock fromYarnLock fromPnpmLock fromBunLock; + } + ) diff --git a/readme.md b/readme.md index af7b979..df2c480 100644 --- a/readme.md +++ b/readme.md @@ -20,6 +20,42 @@ With nix-prisma-utils it's the other way around. You can simply install prisma t ## Let's go +```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; + # leave the hash empty, nix will complain and tell you the right hash + hash = ""; + npmLock = ./package-lock.json # <--- path to our package-lock.json file that contains the version of prisma-engines + # if you use another package manager from npm, choose yours from + # yarnLock = ./yarn.lock; + # pnpmLock = ./pnpm-lock.yaml; + # bunLock = ./bun.lock; + }; + 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; + }; + }; +} +``` + +## Legacy fetchers & API + ### Using `npm` ```nix diff --git a/tests.nix b/tests.nix index fa3ff4d..f654bb5 100644 --- a/tests.nix +++ b/tests.nix @@ -2,49 +2,55 @@ pkgs, writeShellApplication, prisma-factory, - + fetcherMode, # legacy or new nodejs, pnpm, yarn-v1, yarn-berry, bun, -}: -let - hashesBySystem = { - x86_64-linux = { - prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; - query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; - libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; - schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; +}: let + hashesBySystem = + if fetcherMode == "new" + then { + x86_64-linux.hash = ""; + aarch64-linux.hash = ""; + x86_64-darwin.hash = ""; + aarch64-darwin.hash = ""; + } + else { + x86_64-linux = { + prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; + query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; + libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; + schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; + }; + aarch64-linux = { + prisma-fmt-hash = "sha256-gqbgN9pZxzZEi6cBicUfH7qqlXWM+z28sGVuW/wKHb8="; + query-engine-hash = "sha256-q1HVbRtWhF3J5ScETrwvGisS8fXA27nryTvqFb+XIuo="; + libquery-engine-hash = "sha256-oalG9QKuxURtdgs5DgJZZtyWMz3ZpywHlov+d1ct2vA="; + schema-engine-hash = "sha256-5bp8iiq6kc9c37G8dNKVHKWJHvaxFaetR4DOR/0/eWs="; + }; + x86_64-darwin = { + prisma-fmt-hash = "sha256-Z0AIuCRW0GEd6QRiyYdVVS1Zb6d1aRH+jUE0JNXFgiQ="; + query-engine-hash = "sha256-TjJp72T9nmJcIrMLUIpnapzNlRyVpGp/jGaSuJ0nUDI="; + libquery-engine-hash = "sha256-cerpi9y9w6Fn1meXuj2VDRdIQz/MZvrQ7LZKa0Z70yM="; + schema-engine-hash = "sha256-tfR5B8s5GfmeE1kFlmYyxS7Kw1ELShBKsf+i5MmS+/o="; + }; + aarch64-darwin = { + prisma-fmt-hash = "sha256-UPig7U2zXOccalIUE0j07xJdmqAUJ7cpXFTo+2Gbsc8="; + query-engine-hash = "sha256-ihP1BEAvXQ+5XXHEXCYAVTnuETpfxmdtsIGRTljKtS0="; + libquery-engine-hash = "sha256-4T63O+OyoEIJ0TLKoOoil06whd+41QxiXXg+0cgpX/8="; + schema-engine-hash = "sha256-+O4IelHbZt4X+6UWol8TpL+BBDTS5JT+0hQR7ELVmZc="; + }; }; - aarch64-linux = { - prisma-fmt-hash = "sha256-gqbgN9pZxzZEi6cBicUfH7qqlXWM+z28sGVuW/wKHb8="; - query-engine-hash = "sha256-q1HVbRtWhF3J5ScETrwvGisS8fXA27nryTvqFb+XIuo="; - libquery-engine-hash = "sha256-oalG9QKuxURtdgs5DgJZZtyWMz3ZpywHlov+d1ct2vA="; - schema-engine-hash = "sha256-5bp8iiq6kc9c37G8dNKVHKWJHvaxFaetR4DOR/0/eWs="; - }; - x86_64-darwin = { - prisma-fmt-hash = "sha256-Z0AIuCRW0GEd6QRiyYdVVS1Zb6d1aRH+jUE0JNXFgiQ="; - query-engine-hash = "sha256-TjJp72T9nmJcIrMLUIpnapzNlRyVpGp/jGaSuJ0nUDI="; - libquery-engine-hash = "sha256-cerpi9y9w6Fn1meXuj2VDRdIQz/MZvrQ7LZKa0Z70yM="; - schema-engine-hash = "sha256-tfR5B8s5GfmeE1kFlmYyxS7Kw1ELShBKsf+i5MmS+/o="; - }; - aarch64-darwin = { - prisma-fmt-hash = "sha256-UPig7U2zXOccalIUE0j07xJdmqAUJ7cpXFTo+2Gbsc8="; - query-engine-hash = "sha256-ihP1BEAvXQ+5XXHEXCYAVTnuETpfxmdtsIGRTljKtS0="; - libquery-engine-hash = "sha256-4T63O+OyoEIJ0TLKoOoil06whd+41QxiXXg+0cgpX/8="; - schema-engine-hash = "sha256-+O4IelHbZt4X+6UWol8TpL+BBDTS5JT+0hQR7ELVmZc="; - }; - }; - test-npm = - let - prisma = - (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromNpmLock - ./npm/package-lock.json; - in + test-npm = let + prisma = + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromNpmLock + ./npm/package-lock.json; + in writeShellApplication { name = "test-npm"; - runtimeInputs = [ nodejs ]; + runtimeInputs = [nodejs]; runtimeEnv = prisma.env; text = '' echo "testing npm" @@ -53,15 +59,14 @@ let ./node_modules/.bin/prisma generate ''; }; - test-pnpm = - let - prisma = - (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromPnpmLock - ./pnpm/pnpm-lock.yaml; - in + test-pnpm = let + prisma = + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromPnpmLock + ./pnpm/pnpm-lock.yaml; + in writeShellApplication { name = "test-pnpm"; - runtimeInputs = [ pnpm ]; + runtimeInputs = [pnpm]; runtimeEnv = prisma.env; text = '' echo "testing pnpm" @@ -70,13 +75,12 @@ let ./node_modules/.bin/prisma generate ''; }; - test-bun = - let - prisma = (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromBunLock ./bun/bun.lock; - in + test-bun = let + prisma = (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromBunLock ./bun/bun.lock; + in writeShellApplication { name = "test-bun"; - runtimeInputs = [ bun ]; + runtimeInputs = [bun]; runtimeEnv = prisma.env; text = '' echo "testing bun" @@ -85,15 +89,14 @@ let bunx prisma generate ''; }; - test-yarn-v1 = - let - prisma = - (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromYarnLock - ./yarn-v1/yarn.lock; - in + test-yarn-v1 = let + prisma = + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromYarnLock + ./yarn-v1/yarn.lock; + in writeShellApplication { name = "test-yarn-v1"; - runtimeInputs = [ yarn-v1 ]; + runtimeInputs = [yarn-v1]; runtimeEnv = prisma.env; text = '' echo "testing yarn v1" @@ -102,15 +105,14 @@ let yarn-v1 prisma generate ''; }; - test-yarn-berry = - let - prisma = - (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromYarnLock - ./yarn-berry/yarn.lock; - in + test-yarn-berry = let + prisma = + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromYarnLock + ./yarn-berry/yarn.lock; + in writeShellApplication { name = "test-yarn-berry"; - runtimeInputs = [ yarn-berry ]; + runtimeInputs = [yarn-berry]; runtimeEnv = prisma.env; text = '' echo "testing yarn berry" @@ -119,13 +121,10 @@ let yarn-berry prisma generate ''; }; -in -{ - inherit - test-npm - test-pnpm - test-bun - test-yarn-v1 - test-yarn-berry - ; +in { + "test-npm-${fetcherMode}" = test-npm; + "test-pnpm-${fetcherMode}" = test-pnpm; + "test-bun-${fetcherMode}" = test-bun; + "test-yarn-v1-${fetcherMode}" = test-yarn-v1; + "test-yarn-berry-${fetcherMode}" = test-yarn-berry; } From 05678f202e3bc85fc692a312c727c047c7d6b6b8 Mon Sep 17 00:00:00 2001 From: aster <137767097+aster-void@users.noreply.github.com> Date: Wed, 29 Oct 2025 14:21:13 +0900 Subject: [PATCH 2/5] update hashes & format files --- flake.nix | 43 +++--- lib/fetcher.nix | 129 ++++++++-------- lib/legacyFetcher.nix | 153 +++++++++---------- lib/parsers.nix | 345 ++++++++++++++++++++++-------------------- prisma.nix | 58 ++++--- tests.nix | 132 ++++++++-------- 6 files changed, 449 insertions(+), 411 deletions(-) diff --git a/flake.nix b/flake.nix index c771029..be11a0f 100644 --- a/flake.nix +++ b/flake.nix @@ -5,35 +5,39 @@ treefmt-nix.url = "github:numtide/treefmt-nix"; treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { - self, - nixpkgs, - flake-utils, - treefmt-nix, - }: let - prisma-factory = import ./prisma.nix; - in + outputs = + { + self, + nixpkgs, + flake-utils, + treefmt-nix, + }: + let + prisma-factory = import ./prisma.nix; + in flake-utils.lib.eachDefaultSystem ( - system: let + system: + let pkgs = nixpkgs.legacyPackages.${system}; yarn-v1 = pkgs.writeShellApplication { name = "yarn-v1"; checkPhase = ""; - runtimeInputs = [pkgs.yarn]; + runtimeInputs = [ pkgs.yarn ]; text = "yarn $@"; }; yarn-berry = pkgs.writeShellApplication { name = "yarn-berry"; checkPhase = ""; - runtimeInputs = [pkgs.yarn-berry]; + runtimeInputs = [ pkgs.yarn-berry ]; text = "yarn $@"; }; treefmt = treefmt-nix.lib.evalModule pkgs { # nixfmt is nixfmt-rfc-style programs.nixfmt.enable = true; }; - in { + in + { formatter = treefmt.config.build.wrapper; checks = (pkgs.callPackages ./tests.nix { @@ -63,13 +67,14 @@ hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; _commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e"; }).package; - devShells.default = let - prisma = prisma-factory { - inherit pkgs; - hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; - _commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e"; - }; - in + devShells.default = + let + prisma = prisma-factory { + inherit pkgs; + hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; + _commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e"; + }; + in pkgs.mkShell { buildInputs = [ pkgs.nodejs-18_x diff --git a/lib/fetcher.nix b/lib/fetcher.nix index 14b96bd..c5dd463 100644 --- a/lib/fetcher.nix +++ b/lib/fetcher.nix @@ -14,73 +14,68 @@ binaryTarget, hash, components, -}: let +}: +let componentsToFetch = - if components != null - then components - else [ - { - url = "prisma-fmt.gz"; - path = "bin/prisma-fmt"; - env = "PRISMA_FMT_BINARY"; - } - { - 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"; - } - { - url = "schema-engine.gz"; - path = "bin/schema-engine"; - env = "PRISMA_SCHEMA_ENGINE_BINARY"; - } - ]; + if components != null then + components + else + [ + { + url = "prisma-fmt.gz"; + path = "bin/prisma-fmt"; + env = "PRISMA_FMT_BINARY"; + } + { + 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"; + } + { + 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}"; + target = if isDarwin then binaryTarget else "${binaryTarget}-openssl-${opensslVersion}"; toUrl = url: "https://binaries.prisma.sh/all_commits/${commit}/${target}/${url}"; deps = - runCommand "prisma-deps-bin" { - nativeBuildInputs = [ - curl - cacert - gzip - ]; - outputHashAlgo = "sha256"; - outputHashMode = "recursive"; - outputHash = hash; - } '' - export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt - export CURL_CA_BUNDLE=$SSL_CERT_FILE - mkdir -p $out $out/lib $out/bin - ${lib.concatLines ( - map (component: '' - curl "${toUrl component.url}" -L | gunzip > $out/${component.path} - '') - componentsToFetch - )} - ''; + runCommand "prisma-deps-bin" + { + nativeBuildInputs = [ + curl + cacert + gzip + ]; + outputHashAlgo = "sha256"; + outputHashMode = "recursive"; + outputHash = hash; + } + '' + export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt + export CURL_CA_BUNDLE=$SSL_CERT_FILE + mkdir -p $out $out/lib $out/bin + ${lib.concatLines ( + map (component: '' + curl "${toUrl component.url}" -L | gunzip > $out/${component.path} + '') componentsToFetch + )} + ''; package = stdenv.mkDerivation { pname = "prisma-bin"; src = deps; version = commit; - nativeBuildInputs = - [ - zlib - openssl - stdenv.cc.cc.lib - ] - ++ lib.optionals (!isDarwin) [autoPatchelfHook]; + nativeBuildInputs = [ + zlib + openssl + stdenv.cc.cc.lib + ] ++ lib.optionals (!isDarwin) [ autoPatchelfHook ]; phases = [ "installPhase" "postFixupHooks" @@ -93,18 +88,22 @@ find $out/bin -type f -exec chmod +x {} + ''; }; - toExportStyle = attrset: - "\n" + (lib.concatMapAttrsStringSep "\n" (name: value: "export ${name}=\"${value}\"") attrset) + "\n"; - mkEnv = package: + toExportStyle = + attrset: + "\n" + + (lib.concatMapAttrsStringSep "\n" (name: value: "export ${name}=\"${value}\"") attrset) + + "\n"; + mkEnv = + package: builtins.listToAttrs ( builtins.map (c: { name = c.env; value = "${package}/${c.path}"; - }) - componentsToFetch + }) componentsToFetch ); env = mkEnv package; -in { +in +{ inherit package env; shellHook = toExportStyle env; } diff --git a/lib/legacyFetcher.nix b/lib/legacyFetcher.nix index 725e2dc..70ea33a 100644 --- a/lib/legacyFetcher.nix +++ b/lib/legacyFetcher.nix @@ -17,14 +17,12 @@ introspection-engine-hash, migration-engine-hash, schema-engine-hash, -}: let +}: +let hostname = "binaries.prisma.sh"; channel = "all_commits"; isDarwin = lib.strings.hasPrefix "darwin" binaryTarget; - target = - if isDarwin - then binaryTarget - else "${binaryTarget}-openssl-${opensslVersion}"; + target = if isDarwin then binaryTarget else "${binaryTarget}-openssl-${opensslVersion}"; baseUrl = "https://${hostname}/${channel}"; files = [ @@ -41,107 +39,106 @@ variable = "PRISMA_QUERY_ENGINE_BINARY"; } { - name = - if isDarwin - then "libquery_engine.dylib.node" - else "libquery_engine.so.node"; + 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 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"; - } - ] + if migration-engine-hash == null then + [ ] + else + [ + { + name = "migration-engine"; + hash = migration-engine-hash; + path = "bin/migration-engine"; + 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"; - } - ] + 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: - file - // { - file = fetchurl { - name = "${baseUrl}/${commit}/${target}/${file.name}.gz"; - url = "${baseUrl}/${commit}/${target}/${file.name}.gz"; - hash = file.hash; - }; - } - ) - files; + downloadedFiles = builtins.map ( + file: + file + // { + file = fetchurl { + name = "${baseUrl}/${commit}/${target}/${file.name}.gz"; + url = "${baseUrl}/${commit}/${target}/${file.name}.gz"; + hash = file.hash; + }; + } + ) files; unzipCommands = builtins.map (file: "gunzip -c ${file.file} > $out/${file.path}") downloadedFiles; - mkEnv = package: + mkEnv = + package: builtins.listToAttrs ( builtins.map (file: { name = file.variable; value = "${package}/${file.path}"; - }) - files + }) files ); # polyfill: the function in nixpkgs is implemented on Dec 6, 2024. replace this with one from pkgs.lib after 24.11 reaches EOL. - concatMapAttrsStringSep = sep: f: attrs: + concatMapAttrsStringSep = + sep: f: attrs: lib.concatStringsSep sep (lib.attrValues (lib.mapAttrs f attrs)); /** - This function converts attrset to bash export style. - return value contains leading and trailing newlines. + This function converts attrset to bash export style. + return value contains leading and trailing newlines. - # Example - ```nix - toExportStyle { foo = "bar"; baz = "abc"; } - => - '' - export foo="bar" - export baz="abc" - '' - ``` + # Example + ```nix + toExportStyle { foo = "bar"; baz = "abc"; } + => + '' + export foo="bar" + export baz="abc" + '' + ``` - # Type - toExportStyle :: Attrset -> String + # Type + toExportStyle :: Attrset -> String */ - toExportStyle = attrset: + toExportStyle = + attrset: "\n" + (concatMapAttrsStringSep "\n" (name: value: "export ${name}=\"${value}\"") attrset) + "\n"; -in rec { +in +rec { package = stdenv.mkDerivation { pname = "prisma-bin"; version = commit; - nativeBuildInputs = - [ - zlib - openssl - stdenv.cc.cc.lib - ] - ++ lib.optionals (!isDarwin) [autoPatchelfHook]; + nativeBuildInputs = [ + zlib + openssl + stdenv.cc.cc.lib + ] ++ lib.optionals (!isDarwin) [ autoPatchelfHook ]; phases = [ "buildPhase" "postFixupHooks" diff --git a/lib/parsers.nix b/lib/parsers.nix index 8c1db36..e5eb4f0 100644 --- a/lib/parsers.nix +++ b/lib/parsers.nix @@ -1,22 +1,25 @@ { lib, callPackage, -}: let +}: +let lines = s: lib.strings.splitString "\n" s; # example: # splitMultiple ["|" "," "-"] "a-|b,c-d" # -> ["a" "" "b" "c" "d"] - splitMultiple = delims: s: _splitMultiple delims [s]; + splitMultiple = delims: s: _splitMultiple delims [ s ]; # example: # _splitMultiple ["|" "," "-"] ["a-|b,c-d"] # -> ["a" "" "b" "c" "d"] - _splitMultiple = delims: list: - if builtins.length delims == 0 - then list - else let - splitStr = map (str: lib.strings.splitString (builtins.elemAt delims 0) str) list; - in + _splitMultiple = + delims: list: + if builtins.length delims == 0 then + list + else + let + splitStr = map (str: lib.strings.splitString (builtins.elemAt delims 0) str) list; + in _splitMultiple (lib.drop 1 delims) (lib.lists.concatLists splitStr); splitMultipleAndFilterEmpty = delims: s: builtins.filter (str: str != "") (splitMultiple delims s); # example: @@ -24,170 +27,188 @@ # => e12345 afterLastDot = text: lib.lists.last (lib.strings.splitString "." text); - readYAML = callPackage ./lib/readYAML.nix {}; - # polyfill: the function in nixis implemented on Dec 6, 2024. replace this with one from lib after 24.11 reaches EOL. -in { - parsePnpmLock = path: let - parsePnpmLockVersion = pnpmLock: - if lib.strings.hasPrefix "lockfileVersion: 5" pnpmLock - then "5" - else if lib.strings.hasPrefix "lockfileVersion: '6" pnpmLock - then "6" - else "9"; - pnpmLockParsers = { - # example line: - # /@prisma/engines-version/5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e: - "5" = pnpmLock: let - version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split "@prisma/engines-version/" pnpmLock) 2)) 0; - in - lib.lists.last (lib.strings.splitString "." version); + 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. +{ + parsePnpmLock = + path: + let + parsePnpmLockVersion = + pnpmLock: + if lib.strings.hasPrefix "lockfileVersion: 5" pnpmLock then + "5" + else if lib.strings.hasPrefix "lockfileVersion: '6" pnpmLock then + "6" + else + "9"; + pnpmLockParsers = { + # example line: + # /@prisma/engines-version/5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e: + "5" = + pnpmLock: + let + version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split "@prisma/engines-version/" pnpmLock) 2)) 0; + in + lib.lists.last (lib.strings.splitString "." version); - # example line: - # /@prisma/engines-version@5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e: - "6" = pnpmLock: let - version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split "@prisma/engines-version@" pnpmLock) 2)) 0; - in - lib.lists.last (lib.strings.splitString "." version); + # example line: + # /@prisma/engines-version@5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e: + "6" = + pnpmLock: + let + version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split "@prisma/engines-version@" pnpmLock) 2)) 0; + in + lib.lists.last (lib.strings.splitString "." version); - # exmple line: - # '@prisma/engines-version@5.15.0-29.12e25d8d06f6ea5a0252864dd9a03b1bb51f3022': - "9" = pnpmLock: let - version = builtins.elemAt (builtins.split "'" (builtins.elemAt (builtins.split "@prisma/engines-version@" pnpmLock) 2)) 0; - in - lib.lists.last (lib.strings.splitString "." version); - }; - pnpmLock = builtins.readFile path; - pnpmLockVersion = parsePnpmLockVersion pnpmLock; - pnpmLockParser = pnpmLockParsers.${pnpmLockVersion}; - commit = pnpmLockParser pnpmLock; - in + # exmple line: + # '@prisma/engines-version@5.15.0-29.12e25d8d06f6ea5a0252864dd9a03b1bb51f3022': + "9" = + pnpmLock: + let + version = builtins.elemAt (builtins.split "'" (builtins.elemAt (builtins.split "@prisma/engines-version@" pnpmLock) 2)) 0; + in + lib.lists.last (lib.strings.splitString "." version); + }; + pnpmLock = builtins.readFile path; + pnpmLockVersion = parsePnpmLockVersion pnpmLock; + pnpmLockParser = pnpmLockParsers.${pnpmLockVersion}; + commit = pnpmLockParser pnpmLock; + in commit; - parseNpmLock = path: let - packageLock = builtins.fromJSON (builtins.readFile path); - version = - 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 + parseNpmLock = + path: + let + packageLock = builtins.fromJSON (builtins.readFile path); + version = + 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; - parseYarnLock = path: let - # find this line from yarn.lock: - # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": - yarnLockParser1 = file: let - versionLine = - lib.lists.findFirst - (line: builtins.length (lib.strings.splitString "@prisma/engines-version" line) >= 2) - # else - (throw '' - nix-prisma-utils/yarnLockParser1: package @prisma/engines-version not found in lockfile ${path} . - please make sure you have installed `@prisma/client`. - if you have already installed `@prisma/client` and still see this, please report this to nix-prisma-utils. - '') - (lines file); + parseYarnLock = + path: + let + # find this line from yarn.lock: # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": - # -> ["@prisma/engines-version@npm" "6" "3" "0-17" "acc0b9dd43eb689cbd20c9470515d719db10d0b0"] - # -> acc0b9dd43eb689cbd20c9470515d719db10d0b0 - version = lib.lists.last ( - splitMultipleAndFilterEmpty [ - "\"" - ":" - "." - ] - versionLine - ); - in - version; - isYarnLockV1 = file: - lib.lists.any (line: lib.strings.trim line == "# yarn lockfile v1") ( - lib.strings.splitString "\n" file - ); - # example line: - # "@prisma/engines-version@6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": - yarnV1LockParser = yarnLockParser1; - # example line: - # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": - yarnBerryLockParsers = { - "8" = yarnLockParser1; - }; + yarnLockParser1 = + file: + let + versionLine = + lib.lists.findFirst + (line: builtins.length (lib.strings.splitString "@prisma/engines-version" line) >= 2) + # else + (throw '' + nix-prisma-utils/yarnLockParser1: package @prisma/engines-version not found in lockfile ${path} . + please make sure you have installed `@prisma/client`. + if you have already installed `@prisma/client` and still see this, please report this to nix-prisma-utils. + '') + (lines file); + # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": + # -> ["@prisma/engines-version@npm" "6" "3" "0-17" "acc0b9dd43eb689cbd20c9470515d719db10d0b0"] + # -> acc0b9dd43eb689cbd20c9470515d719db10d0b0 + version = lib.lists.last ( + splitMultipleAndFilterEmpty [ + "\"" + ":" + "." + ] versionLine + ); + in + version; + isYarnLockV1 = + file: + lib.lists.any (line: lib.strings.trim line == "# yarn lockfile v1") ( + lib.strings.splitString "\n" file + ); + # example line: + # "@prisma/engines-version@6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": + yarnV1LockParser = yarnLockParser1; + # example line: + # "@prisma/engines-version@npm:6.3.0-17.acc0b9dd43eb689cbd20c9470515d719db10d0b0": + yarnBerryLockParsers = { + "8" = yarnLockParser1; + }; - lockfile = builtins.readFile path; - parse = - if isYarnLockV1 lockfile - then yarnV1LockParser - else let - lockfileVersion = builtins.toString (readYAML path).__metadata.version; - in - yarnBerryLockParsers.${ - lockfileVersion - } or (throw '' - nix-prisma-utils: unknown lockfile version ${lockfileVersion}. - please report this to nix-prisma-utils with your lockfile. - ''); - in (parse lockfile); - parseBunLock = path: let - # HACK: nix doesn't support JSONC parsing, so currently doing - # 1. remove whitespace and newline - # 2. replace ",}" with "}" - # 3. replace ",]" with "]" - # to support JSON with trailing comma. - # Keep in mind that this removes all whitespaces / tab / newline in the key / value - # and doesn't support comments. - fromJSONWithTrailingComma = jsonc: - builtins.fromJSON ( - builtins.replaceStrings - [ - ",}" - ",]" - ] - [ - "}" - "]" - ] - ( + lockfile = builtins.readFile path; + parse = + if isYarnLockV1 lockfile then + yarnV1LockParser + else + let + lockfileVersion = builtins.toString (readYAML path).__metadata.version; + in + yarnBerryLockParsers.${lockfileVersion} or (throw '' + nix-prisma-utils: unknown lockfile version ${lockfileVersion}. + please report this to nix-prisma-utils with your lockfile. + ''); + in + (parse lockfile); + parseBunLock = + path: + let + # HACK: nix doesn't support JSONC parsing, so currently doing + # 1. remove whitespace and newline + # 2. replace ",}" with "}" + # 3. replace ",]" with "]" + # to support JSON with trailing comma. + # Keep in mind that this removes all whitespaces / tab / newline in the key / value + # and doesn't support comments. + fromJSONWithTrailingComma = + jsonc: + builtins.fromJSON ( builtins.replaceStrings - [ - " " - "\t" - "\n" - ] - [ - "" - "" - "" - ] - jsonc - ) - ); - bunLockParsers = { - # example: - # nu> open bun.lock | from json | get packages.@prisma/engines-version.0 - # @prisma/engines-version@5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e - "0" = bunLockParsers."1"; - "1" = lock: - afterLastDot ( - builtins.elemAt ( - lock."packages"."@prisma/engines-version" or (throw '' + [ + ",}" + ",]" + ] + [ + "}" + "]" + ] + ( + builtins.replaceStrings + [ + " " + "\t" + "\n" + ] + [ + "" + "" + "" + ] + jsonc + ) + ); + bunLockParsers = { + # example: + # nu> open bun.lock | from json | get packages.@prisma/engines-version.0 + # @prisma/engines-version@5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e + "0" = bunLockParsers."1"; + "1" = + lock: + afterLastDot ( + 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. '') - ) - 0 - ); - }; - lockfile = fromJSONWithTrailingComma ( - assert builtins.typeOf path == "path"; + ) 0 + ); + }; + lockfile = fromJSONWithTrailingComma ( + assert builtins.typeOf path == "path"; builtins.readFile path - ); - lockfileVersion = builtins.toString lockfile."lockfileVersion"; - parse = - bunLockParsers.${ - lockfileVersion - } or (throw '' - nix-prisma-utils: Unsupported lockfile version: ${lockfileVersion} - nix-prisma-utils currently supports bun.lock version of 0 and 1. - ''); - commit = parse lockfile; - in + ); + lockfileVersion = builtins.toString lockfile."lockfileVersion"; + parse = + bunLockParsers.${lockfileVersion} or (throw '' + nix-prisma-utils: Unsupported lockfile version: ${lockfileVersion} + nix-prisma-utils currently supports bun.lock version of 0 and 1. + ''); + commit = parse lockfile; + in commit; } diff --git a/prisma.nix b/prisma.nix index b09c718..b7471aa 100644 --- a/prisma.nix +++ b/prisma.nix @@ -25,27 +25,29 @@ x86_64-darwin = "darwin"; aarch64-darwin = "darwin-arm64"; }, -}: let +}: +let inherit (pkgs) lib; - parsers = pkgs.callPackage ./lib/parsers.nix {}; + parsers = pkgs.callPackage ./lib/parsers.nix { }; binaryTarget = binaryTargetBySystem.${pkgs.system}; commitValue = - if _commit != null - then _commit - else if npmLock != null - then fromNpmLock npmLock - else if yarnLock != null - then fromYarnLock yarnLock - else if pnpmLock != null - then fromPnpmLock pnpmLock - else if bunLock != null - then fromBunLock bunLock - else null; - fromCommit = commit: - if builtins.stringLength commit != 40 - then throw "invalid commit: got ${commit}" - else if hash != null - then + if _commit != null then + _commit + else if npmLock != null then + fromNpmLock npmLock + else if yarnLock != null then + fromYarnLock yarnLock + else if pnpmLock != null then + fromPnpmLock pnpmLock + else if bunLock != null then + fromBunLock bunLock + else + null; + fromCommit = + commit: + if builtins.stringLength commit != 40 then + throw "invalid commit: got ${commit}" + else if hash != null then pkgs.callPackage ./lib/fetcher.nix { inherit commit @@ -77,7 +79,7 @@ fromYarnLock = file: fromCommit (parsers.parseYarnLock file); fromBunLock = file: fromCommit (parsers.parseBunLock file); in - lib.warnIf (nixpkgs != null) +lib.warnIf (nixpkgs != null) '' `nixpkgs` argument in nix-prisma-utils is deprecated. please replace it with `pkgs`. examples: @@ -85,11 +87,17 @@ in if your code has `nixpkgs = pkgs;`, replace it with `pkgs = pkgs;` or `inherit pkgs;`. '' ( - if commitValue != null - then # direct fetch + if commitValue != null then # direct fetch fromCommit commitValue - else { - # builder pattern - inherit fromCommit fromNpmLock fromYarnLock fromPnpmLock fromBunLock; - } + else + { + # builder pattern + inherit + fromCommit + fromNpmLock + fromYarnLock + fromPnpmLock + fromBunLock + ; + } ) diff --git a/tests.nix b/tests.nix index f654bb5..c5686f5 100644 --- a/tests.nix +++ b/tests.nix @@ -8,49 +8,52 @@ yarn-v1, yarn-berry, bun, -}: let +}: +let hashesBySystem = - if fetcherMode == "new" - then { - x86_64-linux.hash = ""; - aarch64-linux.hash = ""; - x86_64-darwin.hash = ""; - aarch64-darwin.hash = ""; - } - else { - x86_64-linux = { - prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; - query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; - libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; - schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; + if fetcherMode == "new" then + { + x86_64-linux.hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; + aarch64-linux.hash = ""; + x86_64-darwin.hash = ""; + aarch64-darwin.hash = ""; + } + else + { + x86_64-linux = { + prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; + query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; + libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; + schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q="; + }; + aarch64-linux = { + prisma-fmt-hash = "sha256-gqbgN9pZxzZEi6cBicUfH7qqlXWM+z28sGVuW/wKHb8="; + query-engine-hash = "sha256-q1HVbRtWhF3J5ScETrwvGisS8fXA27nryTvqFb+XIuo="; + libquery-engine-hash = "sha256-oalG9QKuxURtdgs5DgJZZtyWMz3ZpywHlov+d1ct2vA="; + schema-engine-hash = "sha256-5bp8iiq6kc9c37G8dNKVHKWJHvaxFaetR4DOR/0/eWs="; + }; + x86_64-darwin = { + prisma-fmt-hash = "sha256-Z0AIuCRW0GEd6QRiyYdVVS1Zb6d1aRH+jUE0JNXFgiQ="; + query-engine-hash = "sha256-TjJp72T9nmJcIrMLUIpnapzNlRyVpGp/jGaSuJ0nUDI="; + libquery-engine-hash = "sha256-cerpi9y9w6Fn1meXuj2VDRdIQz/MZvrQ7LZKa0Z70yM="; + schema-engine-hash = "sha256-tfR5B8s5GfmeE1kFlmYyxS7Kw1ELShBKsf+i5MmS+/o="; + }; + aarch64-darwin = { + prisma-fmt-hash = "sha256-UPig7U2zXOccalIUE0j07xJdmqAUJ7cpXFTo+2Gbsc8="; + query-engine-hash = "sha256-ihP1BEAvXQ+5XXHEXCYAVTnuETpfxmdtsIGRTljKtS0="; + libquery-engine-hash = "sha256-4T63O+OyoEIJ0TLKoOoil06whd+41QxiXXg+0cgpX/8="; + schema-engine-hash = "sha256-+O4IelHbZt4X+6UWol8TpL+BBDTS5JT+0hQR7ELVmZc="; + }; }; - aarch64-linux = { - prisma-fmt-hash = "sha256-gqbgN9pZxzZEi6cBicUfH7qqlXWM+z28sGVuW/wKHb8="; - query-engine-hash = "sha256-q1HVbRtWhF3J5ScETrwvGisS8fXA27nryTvqFb+XIuo="; - libquery-engine-hash = "sha256-oalG9QKuxURtdgs5DgJZZtyWMz3ZpywHlov+d1ct2vA="; - schema-engine-hash = "sha256-5bp8iiq6kc9c37G8dNKVHKWJHvaxFaetR4DOR/0/eWs="; - }; - x86_64-darwin = { - prisma-fmt-hash = "sha256-Z0AIuCRW0GEd6QRiyYdVVS1Zb6d1aRH+jUE0JNXFgiQ="; - query-engine-hash = "sha256-TjJp72T9nmJcIrMLUIpnapzNlRyVpGp/jGaSuJ0nUDI="; - libquery-engine-hash = "sha256-cerpi9y9w6Fn1meXuj2VDRdIQz/MZvrQ7LZKa0Z70yM="; - schema-engine-hash = "sha256-tfR5B8s5GfmeE1kFlmYyxS7Kw1ELShBKsf+i5MmS+/o="; - }; - aarch64-darwin = { - prisma-fmt-hash = "sha256-UPig7U2zXOccalIUE0j07xJdmqAUJ7cpXFTo+2Gbsc8="; - query-engine-hash = "sha256-ihP1BEAvXQ+5XXHEXCYAVTnuETpfxmdtsIGRTljKtS0="; - libquery-engine-hash = "sha256-4T63O+OyoEIJ0TLKoOoil06whd+41QxiXXg+0cgpX/8="; - schema-engine-hash = "sha256-+O4IelHbZt4X+6UWol8TpL+BBDTS5JT+0hQR7ELVmZc="; - }; - }; - test-npm = let - prisma = - (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromNpmLock - ./npm/package-lock.json; - in + test-npm = + let + prisma = + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromNpmLock + ./npm/package-lock.json; + in writeShellApplication { name = "test-npm"; - runtimeInputs = [nodejs]; + runtimeInputs = [ nodejs ]; runtimeEnv = prisma.env; text = '' echo "testing npm" @@ -59,14 +62,15 @@ ./node_modules/.bin/prisma generate ''; }; - test-pnpm = let - prisma = - (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromPnpmLock - ./pnpm/pnpm-lock.yaml; - in + test-pnpm = + let + prisma = + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromPnpmLock + ./pnpm/pnpm-lock.yaml; + in writeShellApplication { name = "test-pnpm"; - runtimeInputs = [pnpm]; + runtimeInputs = [ pnpm ]; runtimeEnv = prisma.env; text = '' echo "testing pnpm" @@ -75,12 +79,13 @@ ./node_modules/.bin/prisma generate ''; }; - test-bun = let - prisma = (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromBunLock ./bun/bun.lock; - in + test-bun = + let + prisma = (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromBunLock ./bun/bun.lock; + in writeShellApplication { name = "test-bun"; - runtimeInputs = [bun]; + runtimeInputs = [ bun ]; runtimeEnv = prisma.env; text = '' echo "testing bun" @@ -89,14 +94,15 @@ bunx prisma generate ''; }; - test-yarn-v1 = let - prisma = - (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromYarnLock - ./yarn-v1/yarn.lock; - in + test-yarn-v1 = + let + prisma = + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromYarnLock + ./yarn-v1/yarn.lock; + in writeShellApplication { name = "test-yarn-v1"; - runtimeInputs = [yarn-v1]; + runtimeInputs = [ yarn-v1 ]; runtimeEnv = prisma.env; text = '' echo "testing yarn v1" @@ -105,14 +111,15 @@ yarn-v1 prisma generate ''; }; - test-yarn-berry = let - prisma = - (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromYarnLock - ./yarn-berry/yarn.lock; - in + test-yarn-berry = + let + prisma = + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromYarnLock + ./yarn-berry/yarn.lock; + in writeShellApplication { name = "test-yarn-berry"; - runtimeInputs = [yarn-berry]; + runtimeInputs = [ yarn-berry ]; runtimeEnv = prisma.env; text = '' echo "testing yarn berry" @@ -121,7 +128,8 @@ yarn-berry prisma generate ''; }; -in { +in +{ "test-npm-${fetcherMode}" = test-npm; "test-pnpm-${fetcherMode}" = test-pnpm; "test-bun-${fetcherMode}" = test-bun; From 91023f0abf296c2730be74a31339e8362f4bbe75 Mon Sep 17 00:00:00 2001 From: aster <137767097+aster-void@users.noreply.github.com> Date: Wed, 29 Oct 2025 14:22:59 +0900 Subject: [PATCH 3/5] tests: update hash on ubuntu-aarch --- tests.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.nix b/tests.nix index c5686f5..a9b8c38 100644 --- a/tests.nix +++ b/tests.nix @@ -14,7 +14,7 @@ let if fetcherMode == "new" then { x86_64-linux.hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; - aarch64-linux.hash = ""; + aarch64-linux.hash = "sha256-RvloEj41YTf+SwaHLqBlJ5Rpu00UPENprsQRHam3zic="; x86_64-darwin.hash = ""; aarch64-darwin.hash = ""; } From 4dea635a0dc30cd59fe45eda86103dd3e0c01863 Mon Sep 17 00:00:00 2001 From: aster <137767097+aster-void@users.noreply.github.com> Date: Wed, 29 Oct 2025 14:27:18 +0900 Subject: [PATCH 4/5] tests: set correct hash for aarch64-darwin --- tests.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.nix b/tests.nix index a9b8c38..1df29b3 100644 --- a/tests.nix +++ b/tests.nix @@ -16,7 +16,7 @@ let x86_64-linux.hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; aarch64-linux.hash = "sha256-RvloEj41YTf+SwaHLqBlJ5Rpu00UPENprsQRHam3zic="; x86_64-darwin.hash = ""; - aarch64-darwin.hash = ""; + aarch64-darwin.hash = "sha256-LxpKAAjnRn8eH7h9trOOYKf0WcY+aHGrzzVGW2aViek="; } else { From 0dbbdee2a7d79da007ee5ec15b21a33c6bfa29d5 Mon Sep 17 00:00:00 2001 From: aster <137767097+aster-void@users.noreply.github.com> Date: Wed, 29 Oct 2025 14:32:08 +0900 Subject: [PATCH 5/5] tests: set correct hash for x86_64-darwin --- tests.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests.nix b/tests.nix index 1df29b3..a335ecd 100644 --- a/tests.nix +++ b/tests.nix @@ -15,7 +15,7 @@ let { x86_64-linux.hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA="; aarch64-linux.hash = "sha256-RvloEj41YTf+SwaHLqBlJ5Rpu00UPENprsQRHam3zic="; - x86_64-darwin.hash = ""; + x86_64-darwin.hash = "sha256-z1VypBp/JN4qipqTFDmVPb/H1I+TdQVcUU4EIsIPQJ8="; aarch64-darwin.hash = "sha256-LxpKAAjnRn8eH7h9trOOYKf0WcY+aHGrzzVGW2aViek="; } else