Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
VanCoding committed Aug 18, 2023
0 parents commit 8b492c2
Show file tree
Hide file tree
Showing 14 changed files with 469 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
61 changes: 61 additions & 0 deletions flake.lock

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

30 changes: 30 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
inputs.pkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
outputs = {pkgs, flake-utils, ...}: flake-utils.lib.eachDefaultSystem (system: let
prisma-factory = import ./prisma.nix;
nixpkgs = import pkgs {inherit system;};
in {
lib = { inherit prisma-factory; };
packages = import ./tests.nix {
inherit prisma-factory nixpkgs;
};
devShells.default = let
prisma = ((prisma-factory {
inherit nixpkgs;
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 nixpkgs.mkShell {
buildInputs = [
nixpkgs.nodejs-18_x
nixpkgs.nodePackages.pnpm
nixpkgs.stdenv.cc.cc.lib
prisma.package
];
shellHook = prisma.shellHook;
};
});
}
63 changes: 63 additions & 0 deletions npm/package-lock.json

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

15 changes: 15 additions & 0 deletions npm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "npm-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "^5.1.1",
"prisma": "^5.1.1"
}
}
18 changes: 18 additions & 0 deletions npm/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}

model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
email String @unique
name String?
}
3 changes: 3 additions & 0 deletions pnpm/.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/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "pnpm",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "5.1.1",
"prisma": "^5.1.1"
}
}
47 changes: 47 additions & 0 deletions pnpm/pnpm-lock.yaml

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

18 changes: 18 additions & 0 deletions pnpm/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}

model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
email String @unique
name String?
}
73 changes: 73 additions & 0 deletions prisma.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
nixpkgs,
openssl3 ? true,
openssl ? nixpkgs.openssl,
introspection-engine-hash?null,
migration-engine-hash?null,
prisma-fmt-hash,
query-engine-hash,
libquery-engine-hash,
schema-engine-hash?null
} : rec {
fromCommit = commit : let
hostname = "binaries.prisma.sh";
channel = "all_commits";
target = "debian-openssl-${if openssl3 then "3.0.x" else "1.1.x"}";
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 = "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 = 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;
exportCommands = package: builtins.map (file: "export ${file.variable}=${package}/${file.path}") files;
in rec {
package = nixpkgs.stdenv.mkDerivation {
pname = "prisma-bin";
version = commit;
nativeBuildInputs = [
nixpkgs.autoPatchelfHook
nixpkgs.zlib
openssl
nixpkgs.stdenv.cc.cc.lib
];
phases = ["buildPhase" "postFixupHooks" ];
buildPhase = ''
mkdir -p $out/bin
mkdir -p $out/lib
${nixpkgs.lib.concatStringsSep "\n" unzipCommands}
chmod +x $out/bin/*
'';
};
shellHook = nixpkgs.lib.concatStringsSep "\n" (exportCommands package);
};
fromPnpmLock = path: let
pnpmLock = builtins.readFile path;
version = builtins.elemAt (builtins.split ":" (builtins.elemAt (builtins.split "engines-version/" pnpmLock) 2)) 0;
commit = nixpkgs.lib.lists.last (nixpkgs.lib.strings.splitString "." version);
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 builtins.trace commit (fromCommit commit);
}
Loading

0 comments on commit 8b492c2

Please sign in to comment.