diff --git a/flake.lock b/flake.lock index a5be10d..3665d48 100644 --- a/flake.lock +++ b/flake.lock @@ -18,13 +18,13 @@ "type": "github" } }, - "pkgs": { + "nixpkgs": { "locked": { - "lastModified": 1738172511, - "narHash": "sha256-v/8yB8LIy/KsySZYN6rO/f4kCEkj+fTLkzR0TaNMB+w=", + "lastModified": 1738703096, + "narHash": "sha256-1MABVDwNpAUrUDvyM6PlHlAB1eTWAX0eNYCzdsZ54NI=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "762a398892576efcc76fb233befbd58c2cef59e0", + "rev": "f7384aacd0ecd28681a99269ac0dff2c3a805d63", "type": "github" }, "original": { @@ -37,7 +37,7 @@ "root": { "inputs": { "flake-utils": "flake-utils", - "pkgs": "pkgs", + "nixpkgs": "nixpkgs", "treefmt-nix": "treefmt-nix" } }, @@ -59,7 +59,7 @@ "treefmt-nix": { "inputs": { "nixpkgs": [ - "pkgs" + "nixpkgs" ] }, "locked": { diff --git a/flake.nix b/flake.nix index f94b482..3f0e607 100644 --- a/flake.nix +++ b/flake.nix @@ -1,12 +1,14 @@ { - inputs.pkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - inputs.flake-utils.url = "github:numtide/flake-utils"; - inputs.treefmt-nix.url = "github:numtide/treefmt-nix"; - inputs.treefmt-nix.inputs.nixpkgs.follows = "pkgs"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; + }; outputs = { self, - pkgs, + nixpkgs, flake-utils, treefmt-nix, }: @@ -16,20 +18,21 @@ flake-utils.lib.eachDefaultSystem ( system: let - nixpkgs = import pkgs { inherit system; }; - yarn-v1 = nixpkgs.writeShellApplication { + pkgs = nixpkgs.legacyPackages.${system}; + + yarn-v1 = pkgs.writeShellApplication { name = "yarn-v1"; checkPhase = ""; - runtimeInputs = [ nixpkgs.yarn ]; + runtimeInputs = [ pkgs.yarn ]; text = "yarn $@"; }; - yarn-berry = nixpkgs.writeShellApplication { + yarn-berry = pkgs.writeShellApplication { name = "yarn-berry"; checkPhase = ""; - runtimeInputs = [ nixpkgs.yarn-berry ]; + runtimeInputs = [ pkgs.yarn-berry ]; text = "yarn $@"; }; - treefmt = treefmt-nix.lib.evalModule nixpkgs { + treefmt = treefmt-nix.lib.evalModule pkgs { # nixfmt is nixfmt-rfc-style programs.nixfmt.enable = true; }; @@ -37,10 +40,10 @@ { formatter = treefmt.config.build.wrapper; checks = - (nixpkgs.callPackages ./tests.nix { + (pkgs.callPackages ./tests.nix { inherit + pkgs prisma-factory - nixpkgs yarn-v1 yarn-berry ; @@ -52,7 +55,7 @@ let prisma = ( (prisma-factory { - inherit nixpkgs; + inherit pkgs; prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw="; libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc="; @@ -61,14 +64,14 @@ "6a3747c37ff169c90047725a05a6ef02e32ac97e" ); in - nixpkgs.mkShell { + pkgs.mkShell { buildInputs = [ - nixpkgs.nodejs-18_x - nixpkgs.pnpm - nixpkgs.bun - nixpkgs.stdenv.cc.cc.lib + pkgs.nodejs-18_x + pkgs.pnpm + pkgs.bun + pkgs.stdenv.cc.cc.lib prisma.package - nixpkgs.nixfmt-rfc-style + pkgs.nixfmt-rfc-style yarn-v1 yarn-berry ]; diff --git a/prisma.nix b/prisma.nix index 19b8d78..3b05641 100644 --- a/prisma.nix +++ b/prisma.nix @@ -1,7 +1,9 @@ { - nixpkgs, + nixpkgs ? null, + # if both are set, prefer pkgs over nixpkgs + pkgs ? nixpkgs, opensslVersion ? "3.0.x", # can be 3.0.x, 1.1.x or 1.0.x - openssl ? nixpkgs.openssl, # the openssl package to use + openssl ? pkgs.openssl, # the openssl package to use introspection-engine-hash ? null, migration-engine-hash ? null, prisma-fmt-hash, @@ -16,7 +18,6 @@ }, }: let - pkgs = nixpkgs; # remove this after renaming nixpkg -> pkgs inherit (pkgs) lib; lines = s: lib.strings.splitString "\n" s; @@ -37,339 +38,346 @@ let in _splitMultiple (lib.drop 1 delims) (lib.lists.concatLists splitStr); splitMultipleAndFilterEmpty = delims: s: builtins.filter (str: str != "") (splitMultiple delims s); - afterLastDot = text: nixpkgs.lib.lists.last (nixpkgs.lib.strings.splitString "." text); + # 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 (nixpkgs) lib; + inherit (pkgs) lib; in sep: f: attrs: lib.concatStringsSep sep (lib.attrValues (lib.mapAttrs f attrs)); in -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.${nixpkgs.system}; - isDarwin = nixpkgs.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"; +pkgs.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; + }; } - ] - ++ ( - 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 = nixpkgs.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; + ) 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. + 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" - '' - ``` + # 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 = nixpkgs.stdenv.mkDerivation { - pname = "prisma-bin"; - version = commit; - nativeBuildInputs = [ - nixpkgs.zlib - openssl - nixpkgs.stdenv.cc.cc.lib - ] ++ nixpkgs.lib.optionals (!isDarwin) [ nixpkgs.autoPatchelfHook ]; - phases = [ - "buildPhase" - "postFixupHooks" - ]; - buildPhase = '' - mkdir -p $out/bin - mkdir -p $out/lib - ${nixpkgs.lib.concatStringsSep "\n" unzipCommands} - chmod +x $out/bin/* - ''; + # 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; }; - env = mkEnv package; - shellHook = toExportStyle env; - }; - # example: - # a.b123c.d.e12345 - # => e12345 - 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 nixpkgs.lib.strings.hasPrefix "lockfileVersion: 5" pnpmLock then - "5" - else if nixpkgs.lib.strings.hasPrefix "lockfileVersion: '6" pnpmLock then - "6" - else - "9"; - pnpmLockParsers = { - # example line: - # /@prisma/engines-version/5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e: - "5" = + 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: - let - version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split ("@prisma/engines-version/") pnpmLock) 2)) 0; - in - nixpkgs.lib.lists.last (nixpkgs.lib.strings.splitString "." version); + 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 - nixpkgs.lib.lists.last (nixpkgs.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: + # 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 - version = builtins.elemAt (builtins.split "'" (builtins.elemAt (builtins.split ("@prisma/engines-version@") pnpmLock) 2)) 0; + 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 - nixpkgs.lib.lists.last (nixpkgs.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 = nixpkgs.lib.lists.last (nixpkgs.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 + version; + isYarnLockV1 = + file: + lib.lists.any (line: lib.strings.trim line == "# yarn lockfile v1") ( + lib.strings.splitString "\n" file ); - 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; - }; + # 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 = 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 + ) ); - }; - 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; -} + 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; + } diff --git a/readme.md b/readme.md index 9c81985..af7b979 100644 --- a/readme.md +++ b/readme.md @@ -24,17 +24,21 @@ With nix-prisma-utils it's the other way around. You can simply install prisma t ```nix { - inputs.pkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - inputs.prisma-utils.url = "github:VanCoding/nix-prisma-utils"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + prisma-utils.url = "github:VanCoding/nix-prisma-utils"; + }; outputs = - { pkgs, prisma-utils, ... }: + { nixpkgs, prisma-utils, ... }: let - nixpkgs = import pkgs { system = "x86_64-linux"; }; + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; prisma = (prisma-utils.lib.prisma-factory { - inherit nixpkgs; - prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; # just copy these hashes for now, and then change them when nix complains about the mismatch + 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="; @@ -42,7 +46,7 @@ With nix-prisma-utils it's the other way around. You can simply install prisma t ./package-lock.json; # <--- path to our package-lock.json file that contains the version of prisma-engines in { - devShells.x86_64-linux.default = nixpkgs.mkShell { + 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; @@ -58,27 +62,29 @@ both yarn v1 and yarn-berry should work. ```nix { - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - inputs.prisma-utils.url = "github:VanCoding/nix-prisma-utils"; + 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"; - nixpkgs = nixpkgs.legacyPackages.${system}; + pkgs = nixpkgs.legacyPackages.${system}; prisma = (prisma-utils.lib.prisma-factory { - inherit nixpkgs; + 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 package-lock.json file that contains the version of prisma-engines + ./yarn.lock; # <--- path to our yarn.lock file that contains the version of prisma-engines in { - devShells.${system}.default = nixpkgs.mkShell { + devShells.${system}.default = pkgs.mkShell { shellHook = prisma.shellHook; }; }; @@ -89,17 +95,21 @@ both yarn v1 and yarn-berry should work. ```nix { - inputs.pkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - inputs.prisma-utils.url = "github:VanCoding/nix-prisma-utils"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + prisma-utils.url = "github:VanCoding/nix-prisma-utils"; + }; outputs = - { pkgs, prisma-utils, ... }: + { nixpkgs, prisma-utils, ... }: let - nixpkgs = import pkgs { system = "x86_64-linux"; }; + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; prisma = (prisma-utils.lib.prisma-factory { - inherit nixpkgs; - prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; # just copy these hashes for now, and then change them when nix complains about the mismatch + 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="; @@ -107,7 +117,7 @@ both yarn v1 and yarn-berry should work. ./pnpm-lock.yaml; # <--- path to our pnpm-lock.yaml file that contains the version of prisma-engines in { - devShells.x86_64-linux.default = nixpkgs.mkShell { + 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; @@ -121,17 +131,21 @@ both yarn v1 and yarn-berry should work. ```nix { - inputs.pkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - inputs.prisma-utils.url = "github:VanCoding/nix-prisma-utils"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + prisma-utils.url = "github:VanCoding/nix-prisma-utils"; + }; outputs = - { pkgs, prisma-utils, ... }: + { nixpkgs, prisma-utils, ... }: let - nixpkgs = import pkgs { system = "x86_64-linux"; }; + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; prisma = (prisma-utils.lib.prisma-factory { - inherit nixpkgs; - prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s="; # just copy these hashes for now, and then change them when nix complains about the mismatch + 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="; @@ -140,7 +154,7 @@ both yarn v1 and yarn-berry should work. # NOTE: does not work with bun.lockb! in { - devShells.x86_64-linux.default = nixpkgs.mkShell { + 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/tests.nix b/tests.nix index fcb62d4..7392342 100644 --- a/tests.nix +++ b/tests.nix @@ -1,5 +1,5 @@ { - nixpkgs, + pkgs, writeShellApplication, prisma-factory, @@ -33,7 +33,7 @@ let test-npm = let prisma = - (prisma-factory ({ inherit nixpkgs; } // hashesBySystem.${nixpkgs.system})).fromNpmLock + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromNpmLock ./npm/package-lock.json; in writeShellApplication { @@ -50,7 +50,7 @@ let test-pnpm = let prisma = - (prisma-factory ({ inherit nixpkgs; } // hashesBySystem.${nixpkgs.system})).fromPnpmLock + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromPnpmLock ./pnpm/pnpm-lock.yaml; in writeShellApplication { @@ -66,9 +66,7 @@ let }; test-bun = let - prisma = - (prisma-factory ({ inherit nixpkgs; } // hashesBySystem.${nixpkgs.system})).fromBunLock - ./bun/bun.lock; + prisma = (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromBunLock ./bun/bun.lock; in writeShellApplication { name = "test-bun"; @@ -84,7 +82,7 @@ let test-yarn-v1 = let prisma = - (prisma-factory ({ inherit nixpkgs; } // hashesBySystem.${nixpkgs.system})).fromYarnLock + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromYarnLock ./yarn-v1/yarn.lock; in writeShellApplication { @@ -101,7 +99,7 @@ let test-yarn-berry = let prisma = - (prisma-factory ({ inherit nixpkgs; } // hashesBySystem.${nixpkgs.system})).fromYarnLock + (pkgs.callPackage prisma-factory hashesBySystem.${pkgs.system}).fromYarnLock ./yarn-berry/yarn.lock; in writeShellApplication {