Skip to content
Open
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
33 changes: 27 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@
flake-utils.url = "github:numtide/flake-utils";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
};
outputs =
{
self,
nixpkgs,
flake-utils,
treefmt-nix,
rust-overlay,
}:
let
prisma-factory = import ./prisma.nix;
prisma-factory =
{ pkgs, ... }@args:
(import ./prisma.nix) (
args
// {
rust-bin = rust-overlay.lib.mkRustBin { } pkgs.pkgsBuildBuild;
}
);
in
flake-utils.lib.eachDefaultSystem (
system:
Expand Down Expand Up @@ -58,6 +68,15 @@
yarn-berry
;
})
// (pkgs.callPackages ./tests.nix {
fetcherMode = "fromPkgs";
inherit
pkgs
prisma-factory
yarn-v1
yarn-berry
;
})
// {
format = treefmt.config.build.check self;
fetcher-assert-npm =
Expand Down Expand Up @@ -117,7 +136,7 @@
in
pkgs.mkShell {
buildInputs = [
pkgs.nodejs-18_x
pkgs.nodejs_24
pkgs.pnpm
pkgs.bun
pkgs.stdenv.cc.cc.lib
Expand Down
17 changes: 17 additions & 0 deletions lib/env.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ lib, componentsToFetch, ... }:

{
toExportStyle =
attrset:
"\n"
+ (lib.concatMapAttrsStringSep "\n" (name: value: "export ${name}=\"${value}\"") attrset)
+ "\n";
mkEnv =
package:
builtins.listToAttrs (
builtins.map (c: {
name = c.variable;
value = "${package}/${c.path}";
}) componentsToFetch
);
}
21 changes: 7 additions & 14 deletions lib/fetcher.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ let
isDarwin = lib.strings.hasPrefix "darwin" binaryTarget;
target = if isDarwin then binaryTarget else "${binaryTarget}-openssl-${opensslVersion}";
toUrl = url: "https://binaries.prisma.sh/all_commits/${version.commit}/${target}/${url}";
envFuncs = callPackage ./env.nix {
inherit componentsToFetch;
};
inherit (envFuncs) toExportStyle mkEnv;
deps =
runCommand "prisma-deps-bin"
{
Expand Down Expand Up @@ -51,7 +55,8 @@ let
zlib
openssl
stdenv.cc.cc.lib
] ++ lib.optionals (!isDarwin) [ autoPatchelfHook ];
]
++ lib.optionals (!isDarwin) [ autoPatchelfHook ];
phases = [
"installPhase"
"postFixupHooks"
Expand All @@ -64,19 +69,7 @@ let
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.variable;
value = "${package}/${c.path}";
}) componentsToFetch
);

env = mkEnv package;
in
{
Expand Down
3 changes: 2 additions & 1 deletion lib/legacyFetcher.nix
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ rec {
zlib
openssl
stdenv.cc.cc.lib
] ++ lib.optionals (!isDarwin) [ autoPatchelfHook ];
]
++ lib.optionals (!isDarwin) [ autoPatchelfHook ];
phases = [
"buildPhase"
"postFixupHooks"
Expand Down
67 changes: 67 additions & 0 deletions lib/prismaFromPkgs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
lib,
callPackage,
fetchFromGitHub,
prisma-engines_6,
rust-bin,
makeRustPlatform,
# variables
version,
binaryTarget,
prismaEnginesGitHubHash,
prismaEnginesCargoHash,
}:

let
componentsToFetch = (callPackage ./components.nix { }).fromVersion version;
isDarwin = lib.strings.hasPrefix "darwin" binaryTarget;
envFuncs = callPackage ./env.nix {
inherit componentsToFetch;
};
inherit (envFuncs) toExportStyle mkEnv;

pkgsPrismaEngines =
if version.majorVersion == 6 then
prisma-engines_6
else
throw "Version ${toString version.majorVersion} of prisma-engines is not supported,"
+ " only version 6 is supported at the moment when building from source"
+ " using nixpkgs.";

package = pkgsPrismaEngines.overrideAttrs (
finalAttrs: oldAttrs:
let
rustToolchainPath = finalAttrs.src + "/rust-toolchain.toml";
rust-toolchain =
if builtins.pathExists rustToolchainPath then
rust-bin.fromRustupToolchainFile rustToolchainPath
else
rust-bin.stable.latest.default;
rustPlatform = makeRustPlatform {
rustc = rust-toolchain;
cargo = rust-toolchain;
};
_version = version; # avoid name clash
in
rec {
src = fetchFromGitHub {
owner = "prisma";
repo = "prisma-engines";
rev = _version.commit;
hash = prismaEnginesGitHubHash;
};
pname = "prisma-engines_${toString _version.majorVersion}";
version = _version.commit;

cargoDeps = rustPlatform.fetchCargoVendor {
inherit src;
hash = prismaEnginesCargoHash;
};
}
);
env = mkEnv package;
in
rec {
inherit package env;
shellHook = toExportStyle env;
}
3 changes: 3 additions & 0 deletions pnpm-prisma-6/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
# Keep environment variables out of version control
.env
16 changes: 16 additions & 0 deletions pnpm-prisma-6/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "pnpm_prisma_6",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "6.18.0",
"prisma": "6.18.0"
}
}
Loading