VanCoding / nix-prisma-utils

A nix library to make [prisma](https://www.prisma.io/) work in your nix shell
21 stars 5 forks source link

Flake fails with error: attribute 'stdenv' missing #6

Open jordan-bravo opened 4 months ago

jordan-bravo commented 4 months ago

I have a development flake for a project using prisma. I tried adding nix-prisma-utils following the README, and the flake fails to evaluate with the error:

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nix-shell'
         whose name attribute is located at /nix/store/0mh3vks8cyvqq94dhqjpx9hmx8k537gl-source/pkgs/stdenv/generic/make-derivation.nix:331:7

       … while evaluating attribute 'shellHook' of derivation 'nix-shell'

         at /nix/store/0mh3vks8cyvqq94dhqjpx9hmx8k537gl-source/pkgs/build-support/mkshell/default.nix:45:3:

           44|
           45|   shellHook = lib.concatStringsSep "\n" (lib.catAttrs "shellHook"
             |   ^
           46|     (lib.reverseList inputsFrom ++ [ attrs ]));

       error: attribute 'stdenv' missing

       at /nix/store/q2472qvc5yj9681i20fyivsarbf36z05-source/prisma.nix:103:17:

          102|     rec {
          103|       package = nixpkgs.stdenv.mkDerivation {
             |                 ^
          104|         pname = "prisma-bin";

Here is what the flake looks like:

{
  description = "This Nix flake creates a development shell for the Customer API that provides the
  required versions of dependencies such as NodeJS 18 and npm 10";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  inputs.prisma-utils.url = "github:VanCoding/nix-prisma-utils";

  outputs = { nixpkgs, flake-utils, prisma-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system: let
      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
          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.default = pkgs.mkShell {
        buildInputs = with pkgs; [
          nodejs_18
          infisical
          # nodePackages.prisma
          openssl
          # prisma-engines
        ];
        shellHook = prisma.shellHook;
      };
    });
}
spost-kojo commented 3 months ago

Hey Jordan, I ran into the same thing and fixed it by replacing inherit nixpkgs; with nixpkgs = nixpkgs.legacyPackages.${system};. The example usage is not set up to work with flake-utils' eachDefaultSystem, and so inherits the wrong nixpkgs when used in that context.

jordan-bravo commented 3 months ago

I followed your suggestion and replaced inherit nixpkgs; with nixpkgs = nixpkgs.legacyPackages.${system};

Nix successfully evaluates the flake, but then when it tries to download from the prisma server, it gets a 404 error. Any suggestions?

error: builder for '/nix/store/iyr3n3hr1ii17nwh518cr61mpxncn3h6-https-binaries.prisma.sh-all_commits-4bc8b6e1b66cb932731fb1bdbbc550d1e010de81-debian-openssl-3.0.x-schema-engine.gz.drv' failed with exit code 1;
       last 7 log lines:
       >
       > trying https://binaries.prisma.sh/all_commits/4bc8b6e1b66cb932731fb1bdbbc550d1e010de81/debian-openssl-3.0.x/schema-engine.gz
       >   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
       >                                  Dload  Upload   Total   Spent    Left  Speed
       >   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
       > curl: (56) The requested URL returned error: 404
       > error: cannot download https-binaries.prisma.sh-all_commits-4bc8b6e1b66cb932731fb1bdbbc550d1e010de81-debian-openssl-3.0.x-schema-engine.gz from any mirror
       For full logs, run 'nix log /nix/store/iyr3n3hr1ii17nwh518cr61mpxncn3h6-https-binaries.prisma.sh-all_commits-4bc8b6e1b66cb932731fb1bdbbc550d1e010de81-debian-openssl-3.0.x-schema-engine.gz.drv'.
error: 1 dependencies of derivation '/nix/store/8rp3sbqwc9rhp7s15dfdkqsybpbg4ccj-prisma-bin-4bc8b6e1b66cb932731fb1bdbbc550d1e010de81.drv' failed to build
error: 1 dependencies of derivation '/nix/store/62zclpa8gdf339rv24090105vnbqnp8v-nix-shell-env.drv' failed to build
VanCoding commented 3 months ago

@jordan-bravo Which prisma version are you using? Older versions of prisma might not have binaries for openssl3, similarly, schema-engine might not be available for that version and instead migration-engine and introspection-engine might be needed.

jordan-bravo commented 3 months ago

If I try to list the prisma version, it throws a similar 404 Not Found error:

❯ prisma --version
Warning Precompiled engine files are not available for nixos.
> Downloading Prisma engines for Node-API for linux-nixos [ ] 0%
Error: Failed to fetch sha256 checksum at https://binaries.prisma.sh/all_commits/4bc8b6e1b66cb932731fb1bdbbc550d1e010de81/linux-nixos/migration-engine.gz.sha256. 404 Not Found

If you need to ignore this error (e.g. in an offline environment), set the 
PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING environment variable to a truthy value.
Example: PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING=1

If I follow the suggestion and set PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING=1, it still has the same problem:

❯ PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING=1 prisma --version
Warning Precompiled engine files are not available for nixos.
> Downloading Prisma engines for Node-API for linux-nixos [  ] 0%
Error: Not Found https://binaries.prisma.sh/all_commits/4bc8b6e1b66cb932731fb1bdbbc550d1e010de81/linux-nixos/migration-engine.gz
VanCoding commented 3 months ago

@jordan-bravo No, I mean what's the version of your prisma package in the package.json?

jordan-bravo commented 3 months ago

Oh, it's 4.16.2

jordan-bravo commented 3 months ago

I was able to get prisma working on NixOS without using nix-prisma-utils by pinning nixpkgs with the same major version of prisma (4.x.y) as listed in the package.json.

My question is, how can I do this with nix-prisma-utils? Here is my flake that is currently working properly without nix-prisma-utils:

{
  description = "This Nix flake creates a development shell for the Customer API that provides the
  required versions of dependencies such as NodeJS 18 and Prisma 4";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    nixpkgs-prisma-4.url = "github:NixOS/nixpkgs/29bcead8405cfe4c00085843eb372cc43837bb9d";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs = { nixpkgs, nixpkgs-prisma-4, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system: let
      pkgs = nixpkgs.legacyPackages.${system};
      pkgs-prisma-4 = nixpkgs-prisma-4.legacyPackages.${system};
    in {
      devShells.default = pkgs.mkShell {
        nativeBuildInputs = [ pkgs.bashInteractive ];
        buildInputs = [
          pkgs.nodejs_18
          pkgs-prisma-4.nodePackages.prisma
          pkgs-prisma-4.prisma-engines
        ];
        shellHook = with pkgs-prisma-4; ''
          export PRISMA_MIGRATION_ENGINE_BINARY="${prisma-engines}/bin/migration-engine"
          export PRISMA_SCHEMA_ENGINE_BINARY="${prisma-engines}/bin/schema-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"
          export PATH="$PWD/node_modules/.bin:$PATH"
        '';
      };
    });
}