I am trying to do a baremetal deployment to a NixOS server. But when running the yarn rw deploy baremetal production --first-run
my CI pipeline fails at the database migration step with the following error:
Deploy failed!
Error while running command `yarn rw prisma migrate deploy`:
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ 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. │
│ Warning Precompiled engine files are not available for nixos. │
│ Error: Env var PRISMA_QUERY_ENGINE_LIBRARY is provided but provided path engines/lib/libquery_engine.node can't be resolved. │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
By adding these steps in the deploy.toml
I can see that the user is correct, but the $PRISMA_QUERY_ENGINE_LIBRARY
is indeed wrong.
before.install = "echo $PRISMA_QUERY_ENGINE_LIBRARY > prisma_engine.txt"
after.install = "whoami > user.txt"
Now this is a headscretcher, since I have indeed set these variables in my
configuration.nix
along with the prisma-engines
. When I do a normal ssh
connection to my server and echo the variable it also shows a correct location to the nix store.
environment.systemPackages = with pkgs; [
# required for rw
git
yarn
nodejs-18_x
nodePackages.prisma
prisma-engines
];
environment.variables = with pkgs; {
PRISMA_MIGRATION_ENGINE_BINARY = "${prisma-engines}/bin/migration-engine";
PRISMA_QUERY_ENGINE_BINARY = "${prisma-engines}/bin/query-engine";
PRISMA_QUERY_ENGINE_LIBRARY = "${prisma-engines}/lib/libquery_engine.node";
PRISMA_INTROSPECTION_ENGINE_BINARY =
"${prisma-engines}/bin/introspection-engine";
PRISMA_FMT_BINARY = "${prisma-engines}/bin/prisma-fmt";
};
When developing locally I use the shell.nix
as follows:
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
mkShell {
nativeBuildInputs = with pkgs; [ bashInteractive ];
buildInputs = with pkgs; [ nodejs-18_x nodePackages.prisma prisma-engines ];
shellHook = with pkgs; ''
export BROWSER=none
export PRISMA_MIGRATION_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"
'';
}
But I don’t know how to deploy redwood with this…
Anyway, my feeling is that the env variable for prisma is not picked up by some weird reason. However I don’t know how to “look into” the deployment, what is being done, or how I could use the variable. The difficulty is to pass the dynamic location to the nix store - and I think this can only be done in a .nix
file.
What I tried
- I tried to “hardcode” the PRISMA_QUERY_ENGINE_LIBRARY in my .env, but that didn’t work.
- I tried to use the
shell.nix
before migration with:
before.install = "nix-shell shell.nix"
… but that didn’t work either.