Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
prisma-next =
(self.lib.prisma-factory {
pkgs = pkgs;
_commit = "next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513";
versionString = "6.20.0-16.next-0c19ccc313cf9911a90d99d2ac2eb0280c76c513";
hash =
{
x86_64-linux = "sha256-JWX+N/mmp9uJLcv4XFbQ3yg34fFf2BLIUpOLrrfTjEM=";
Expand All @@ -103,15 +103,17 @@
(prisma-factory {
inherit pkgs;
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
_commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e";
versionString = "5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e";
}).package;
devShells.default =
let
prisma = prisma-factory {
inherit pkgs;
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
_commit = "6a3747c37ff169c90047725a05a6ef02e32ac97e";
};
prisma = (
prisma-factory {
inherit pkgs;
hash = "sha256-R9PG286KQTbzF0r/PPcShUkMiYam2prRh/JICjmhCZA=";
versionString = "5.1.1-1.6a3747c37ff169c90047725a05a6ef02e32ac97e";
}
);
in
pkgs.mkShell {
buildInputs = [
Expand Down
147 changes: 147 additions & 0 deletions legacy-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Legacy API
In earlier versions of nix-prisma-utils the API was more like a factory pattern.
This API still works, but is now deprecated and we recommend switching to the new API.
We still try to support the legacy API for backwards compatibility, though.

## Using `npm`

```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
prisma-utils.url = "github:VanCoding/nix-prisma-utils";
};

outputs =
{ nixpkgs, prisma-utils, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
prisma =
(prisma-utils.lib.prisma-factory {
inherit pkgs;
# just copy these hashes for now, and then change them when nix complains about the mismatch
prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s=";
query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw=";
libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc=";
schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q=";
}).fromNpmLock
./package-lock.json; # <--- path to our package-lock.json file that contains the version of prisma-engines
in
{
devShells.${system}.default = pkgs.mkShell {
env = prisma.env;
# or, you can use `shellHook` instead of `env` to load the same environment variables.
# shellHook = prisma.shellHook;
};
};
}

```

## Using `yarn`

both yarn v1 and yarn-berry should work.

```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
prisma-utils.url = "github:VanCoding/nix-prisma-utils";
};

outputs =
{ nixpkgs, prisma-utils, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
prisma =
(prisma-utils.lib.prisma-factory {
inherit pkgs;
# just copy these hashes for now, and then change them when nix complains about the mismatch
prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s=";
query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw=";
libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc=";
schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q=";
}).fromYarnLock
./yarn.lock; # <--- path to our yarn.lock file that contains the version of prisma-engines
in
{
devShells.${system}.default = pkgs.mkShell {
shellHook = prisma.shellHook;
};
};
}
```

## Using `pnpm`

```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
prisma-utils.url = "github:VanCoding/nix-prisma-utils";
};

outputs =
{ nixpkgs, prisma-utils, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
prisma =
(prisma-utils.lib.prisma-factory {
inherit pkgs;
# just copy these hashes for now, and then change them when nix complains about the mismatch
prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s=";
query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw=";
libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc=";
schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q=";
}).fromPnpmLock
./pnpm-lock.yaml; # <--- path to our pnpm-lock.yaml file that contains the version of prisma-engines
in
{
devShells.${system}.default = pkgs.mkShell {
env = prisma.env;
# or, you can use `shellHook` instead of `env` to load the same environment variables.
# shellHook = prisma.shellHook;
};
};
}

```

## Using `bun`

```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
prisma-utils.url = "github:VanCoding/nix-prisma-utils";
};

outputs =
{ nixpkgs, prisma-utils, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
prisma =
(prisma-utils.lib.prisma-factory {
inherit pkgs;
# just copy these hashes for now, and then change them when nix complains about the mismatch
prisma-fmt-hash = "sha256-4zsJv0PW8FkGfiiv/9g0y5xWNjmRWD8Q2l2blSSBY3s=";
query-engine-hash = "sha256-6ILWB6ZmK4ac6SgAtqCkZKHbQANmcqpWO92U8CfkFzw=";
libquery-engine-hash = "sha256-n9IimBruqpDJStlEbCJ8nsk8L9dDW95ug+gz9DHS1Lc=";
schema-engine-hash = "sha256-j38xSXOBwAjIdIpbSTkFJijby6OGWCoAx+xZyms/34Q=";
}).fromBunLock
./bun.lock; # <--- path to our bun.lock file that contains the version of prisma-engines.
# NOTE: does not work with bun.lockb!
in
{
devShells.${system}.default = pkgs.mkShell {
env = prisma.env;
# or, you can use `shellHook` instead of `env` to load the same environment variables.
# shellHook = prisma.shellHook;
};
};
}
```
60 changes: 60 additions & 0 deletions lib/components.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{ lib, ... }:
let
isv7 =
version:
version.majorVersion >= 7
|| (
version.majorVersion == 6
&& version.minorVersion >= 19
&& lib.strings.hasInfix "next" version.preReleaseVersion
);
components = [
{
name = "migration-engine";
getFileName = isDarwin: "migration-engine.gz";
path = "bin/migration-engine";
variable = "PRISMA_MIGRATION_ENGINE_BINARY";
isIncluded = version: false;
}
{
name = "prisma-fmt";
getFileName = isDarwin: "prisma-fmt.gz";
path = "bin/prisma-fmt";
variable = "PRISMA_FMT_BINARY";
isIncluded = version: true;
}
{
name = "schema-engine";
getFileName = isDarwin: "schema-engine.gz";
path = "bin/schema-engine";
variable = "PRISMA_SCHEMA_ENGINE_BINARY";
isIncluded = version: true;
}
{
name = "query-engine";
getFileName = isDarwin: "query-engine.gz";
path = "bin/query-engine";
variable = "PRISMA_QUERY_ENGINE_BINARY";
isIncluded = version: !(isv7 version);
}
{
name = "libquery-engine";
getFileName =
isDarwin: if isDarwin then "libquery_engine.dylib.node.gz" else "libquery_engine.so.node.gz";
path = "lib/libquery_engine.node";
variable = "PRISMA_QUERY_ENGINE_LIBRARY";
isIncluded = version: !(isv7 version);
}
{
name = "introspection-engine";
getFileName = isDarwin: "introspection-engine.gz";
path = "bin/introspection-engine";
variable = "PRISMA_INTROSPECTION_ENGINE_BINARY";
isIncluded = version: false;
}
];
in
{
fromVersion = version: lib.filter (component: component.isIncluded version) components;
fromHashes = hashes: lib.filter (component: ((hashes."${component.name}-hash") != null)) components;
}
44 changes: 8 additions & 36 deletions lib/fetcher.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,18 @@
runCommand,
gzip,
# variables
commit,
openssl,
opensslVersion,
binaryTarget,
hash,
components,
isv7,
version,
callPackage,
}:
let
componentsToFetch =
if components != null then
components
else
[
{
url = "prisma-fmt.gz";
path = "bin/prisma-fmt";
env = "PRISMA_FMT_BINARY";
}
{
url = "schema-engine.gz";
path = "bin/schema-engine";
env = "PRISMA_SCHEMA_ENGINE_BINARY";
}
]
++ lib.optionals (!isv7) [
{
url = "query-engine.gz";
path = "bin/query-engine";
env = "PRISMA_QUERY_ENGINE_BINARY";
}
{
url = if isDarwin then "libquery_engine.dylib.node.gz" else "libquery_engine.so.node.gz";
path = "lib/libquery_engine.node";
env = "PRISMA_QUERY_ENGINE_LIBRARY";
}
];
componentsToFetch = (callPackage ./components.nix { }).fromVersion version;
isDarwin = lib.strings.hasPrefix "darwin" binaryTarget;
target = if isDarwin then binaryTarget else "${binaryTarget}-openssl-${opensslVersion}";
toUrl = url: "https://binaries.prisma.sh/all_commits/${commit}/${target}/${url}";
toUrl = url: "https://binaries.prisma.sh/all_commits/${version.commit}/${target}/${url}";
deps =
runCommand "prisma-deps-bin"
{
Expand All @@ -66,15 +38,15 @@ let
mkdir -p $out $out/lib $out/bin
${lib.concatLines (
map (component: ''
echo '[nix-prisma-utils] fetching ${toUrl component.url} to $out/${component.path}'
curl "${toUrl component.url}" -L | gunzip > $out/${component.path}
echo '[nix-prisma-utils] fetching ${toUrl (component.getFileName isDarwin)} to $out/${component.path}'
curl "${toUrl (component.getFileName isDarwin)}" -L | gunzip > $out/${component.path}
'') componentsToFetch
)}
'';
package = stdenv.mkDerivation {
pname = "prisma-bin";
src = deps;
version = commit;
version = version.commit;
nativeBuildInputs = [
zlib
openssl
Expand All @@ -101,7 +73,7 @@ let
package:
builtins.listToAttrs (
builtins.map (c: {
name = c.env;
name = c.variable;
value = "${package}/${c.path}";
}) componentsToFetch
);
Expand Down
Loading
Loading