Giter Club home page Giter Club logo

nix-prisma-example's Introduction

Prisma project with Nix

First what you want is nix-direnv with flakes support. You can go without flakes, but I can't provide you help how to get the right channels, and flakes are awesome so read the docs in this repo how to enable them for your setup.

When running direnv allow in the project directory, it will install prisma cli and the engines to your dev environment. After the whole thing is finished, check the installed prisma version:

❯ prisma --version
Environment variables loaded from .env
Warning Precompiled binaries are not available for nixos.
prisma                  : 3.1.1
@prisma/client          : 3.1.1
Current platform        : linux-nixos
Query Engine (Node-API) : libquery-engine  (at ../../../../nix/store/12i1q096cjjnqay4ayl9m27l4qsw3c2h-prisma-engines-3.1.1/lib/libquery_engine.node, resolved by PRISMA_QUERY_ENGINE_LIBRARY)
Migration Engine        : migration-engine-cli  (at ../../../../nix/store/12i1q096cjjnqay4ayl9m27l4qsw3c2h-prisma-engines-3.1.1/bin/migration-engine, resolved by PRISMA_MIGRATION_ENGINE_BINARY)
Introspection Engine    : introspection-core  (at ../../../../nix/store/12i1q096cjjnqay4ayl9m27l4qsw3c2h-prisma-engines-3.1.1/bin/introspection-engine, resolved by PRISMA_INTROSPECTION_ENGINE_BINARY)
Format Binary           : prisma-fmt  (at ../../../../nix/store/12i1q096cjjnqay4ayl9m27l4qsw3c2h-prisma-engines-3.1.1/bin/prisma-fmt, resolved by PRISMA_FMT_BINARY)
Default Engines Hash    : c22652b7e418506fab23052d569b85d3aec4883f
Studio                  : 0.423.0

As written in the output, the cli uses the binaries and node-api library described in the flake.nix env vars. Always check the prisma version installed through the flake is exactly the same as the @prisma/client version in the package.json.

When upgrading, running nix flake update should be enough to get the latest engines/cli. Remember to commit the flake.lock file to the version control. After that, update the @prisma/client in the package.json.

If working with others who do not use nix, you can modify the .envrc file so it will not try running nix commands if not using nix:

if command -v nix-shell &> /dev/null
then
    use flake
fi

If I'm having a vacation or get hit by a bus, and you need to update prisma in the nix monorepo, there's two things to update: the cli npm package and the rust engines. See an example pull request.

Updating

If the repository the flake.nix has a new version of Prisma, to get the same version to your project requires a few steps.

First make your flake to point to the latest commit in the repository:

> nix flake update

After that, direnv should catch the changed files, and install the latest Prisma to your environment. Check the version:

❯ prisma --version
Environment variables loaded from .env
Warning Precompiled binaries are not available for nixos.
prisma                  : 3.2.0
@prisma/client          : 3.1.1
Current platform        : linux-nixos
Query Engine (Node-API) : libquery-engine  (at ../../../../../nix/store/vckf62m16nxk9wyh5js2psmdsypl4lq1-prisma-engines-3.2.0/lib/libquery_engine.node, resolved by PRISMA_QUERY_ENGINE_LIBRARY)
Migration Engine        : migration-engine-cli  (at ../../../../../nix/store/vckf62m16nxk9wyh5js2psmdsypl4lq1-prisma-engines-3.2.0/bin/migration-engine, resolved by PRISMA_MIGRATION_ENGINE_BINARY)
Introspection Engine    : introspection-core  (at ../../../../../nix/store/vckf62m16nxk9wyh5js2psmdsypl4lq1-prisma-engines-3.2.0/bin/introspection-engine, resolved by PRISMA_INTROSPECTION_ENGINE_BINARY)
Format Binary           : prisma-fmt  (at ../../../../../nix/store/vckf62m16nxk9wyh5js2psmdsypl4lq1-prisma-engines-3.2.0/bin/prisma-fmt, resolved by PRISMA_FMT_BINARY)
Default Engines Hash    : afdab2f10860244038c4e32458134112852d4dad
Studio                  : 0.435.0

Now we see the @prisma/client is using an older version, so change the versioning accordingly in the package.json file. It might be required to delete the node_modules directory before running prisma generate. After a successful update the version output should list the same version for prisma and @prisma/client:

❯ prisma --version
Environment variables loaded from .env
Warning Precompiled binaries are not available for nixos.
prisma                  : 3.2.0
@prisma/client          : 3.2.0

If the nixpkgs master doesn't yet have the latest version, point to the repository that has the update by changing the nixpkgs url in the flake:

inputs.nixpkgs.url = "github:NixOS/nixpkgs/master";

changes to

inputs.nixpkgs.url = "github:pimeys/nixpkgs/prisma-3_2_0";

By just entering the directory, direnv should catch the changes and install the new derivation. After this is done, handle the update process as written above.

nix-prisma-example's People

Contributors

eviefp avatar

Stargazers

nam avatar Jeremy Kennedy avatar Naser Aleisa avatar Gustavo Porto avatar  avatar David Asabina avatar Cat, Yuzuki avatar Berkut Karlibay avatar Midka avatar  avatar Linus Sehn avatar Yslan Ramos avatar Akira Komamura avatar Yiyi Wang avatar SnO₂WMaN avatar Fukuda Yuma avatar Vieko Franetovic avatar Gabriel Pereira avatar Fernando Canteruccio avatar Victor avatar João Victor avatar Nikita avatar Johannes Schickling avatar Julius de Bruijn avatar Narcis-Ionuț B. avatar Harshit Pant avatar

Watchers

Julius de Bruijn avatar  avatar

nix-prisma-example's Issues

error: flake does not provide attribute 'packages.x86_64-linux.default' or 'defaultPackage.x86_64-linux'

I'm trying to get Prisma running in NixOS and I tried to follow this example. I think I might be missing something since I'm quite new to NixOS.

When I clone this repo and run direnv allow, I get no output (I haven't used direnv before and yes, nix-direnv is installed as suggested in the readme). Since I didn't get any output, I tried to manually run the flake using nix run and got this error

error: flake 'git+file:///home/user/Desktop/Projects/TypeScript/2023/Misc/nix-prisma-example' does not provide attribute 'packages.x86_64-linux.default' or 'defaultPackage.x86_64-linux'

Temporary workaround

As I have a couple of urgent deadlines, I did this:

  • make shell.nix in the root of the project
# shell.nix
{ pkgs ? import <nixpkgs> { } }:
pkgs.mkShell {
  nativeBuildInputs = [ pkgs.bashInteractive ];
  buildInputs = with pkgs; [
    nodePackages.prisma
  ];
  shellHook = with pkgs; ''
    export PRISMA_SCHEMA_ENGINE_BINARY="${prisma-engines}/bin/migration-engine"
    export PRISMA_QUERY_ENGINE_BINARY="${prisma-engines}/bin/query-engine"
    export PRISMA_QUERY_ENGINE_LIBRARY="${prisma-engines}/lib/libquery_engine.node"
    export PRISMA_INTROSPECTION_ENGINE_BINARY="${prisma-engines}/bin/introspection-engine"
    export PRISMA_FMT_BINARY="${prisma-engines}/bin/prisma-fmt"
  '';
}
  • run nix-shell
    This copied everything to the right place and gave access to prisma command.

I also got these warnings for prisma --version

prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".
Please manually install OpenSSL and try installing Prisma again.
prisma:warn Both PRISMA_SCHEMA_ENGINE_BINARY and PRISMA_MIGRATION_ENGINE_BINARY are specified, PRISMA_SCHEMA_ENGINE_BINARY takes precedence. PRISMA_MIGRATION_ENGINE_BINARY is deprecated.
prisma:warn Both PRISMA_SCHEMA_ENGINE_BINARY and PRISMA_MIGRATION_ENGINE_BINARY are specified, PRISMA_SCHEMA_ENGINE_BINARY takes precedence. PRISMA_MIGRATION_ENGINE_BINARY is deprecated.
prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".
Please manually install OpenSSL and try installing Prisma again.
prisma:warn Both PRISMA_SCHEMA_ENGINE_BINARY and PRISMA_MIGRATION_ENGINE_BINARY are specified, PRISMA_SCHEMA_ENGINE_BINARY takes precedence. PRISMA_MIGRATION_ENGINE_BINARY is deprecated.

and I replaced PRISMA_MIGRATION_ENGINE_BINARY with PRISMA_SCHEMA_ENGINE_BINARY in the shell.nix so now I only get this:

prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".
Please manually install OpenSSL and try installing Prisma again.
prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".
Please manually install OpenSSL and try installing Prisma again.
prisma                  : 5.4.1
@prisma/client          : 3.12.0
Current platform        : linux-nixos
Query Engine (Node-API) : libquery-engine  (at ../../../../../../../../nix/store/a44mv2s47a8r4xjbp9zbry47sxsa5r4a-prisma-engines-5.4.1/lib/libquery_engine.node, resolved by PRISMA_QUERY_ENGINE_LIBRARY)
Schema Engine           : schema-engine-cli  (at ../../../../../../../../nix/store/a44mv2s47a8r4xjbp9zbry47sxsa5r4a-prisma-engines-5.4.1/bin/schema-engine, resolved by PRISMA_SCHEMA_ENGINE_BINARY)
Schema Wasm             : @prisma/prisma-schema-wasm 5.3.1-2.61e140623197a131c2a6189271ffee05a7aa9a59
Default Engines Hash    : aebc046ce8b88ebbcb45efe31cbe7d06fd6abc0a
Studio                  : 0.494.0
┌─────────────────────────────────────────────────────────┐
│  Update available 5.4.1 -> 5.7.1                        │
│  Run the following to update                            │
│    npm i --save-dev prisma@latest                       │
│    npm i @prisma/client@latest                          │
└─────────────────────────────────────────────────────────┘

I guess I can work with 5.4.1 but I would like to know how I can manually update it. I know I'll have to make a .nix file with the right source of prisma library like given here, but I am not that familiar with nix and NixOS yet.

I also want to know if theres a way to declaratively set up prisma with home-manager or in configuration.nix file so that I don't have to use nix-shell to run the project.

Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.