Skip to content

Commit

Permalink
nix: simplify prisma-fmt-wasm derivation (#3501)
Browse files Browse the repository at this point in the history
Use stdenv.mkDerivation, we gain nothing from using crane.
  • Loading branch information
tomhoule committed Dec 15, 2022
1 parent 31da947 commit 2eeed5b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
3 changes: 2 additions & 1 deletion nix/all-engines.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ craneLib, pkgs, ... }:
{ craneLib, pkgs, inputs, ... }:

let
srcPath = builtins.path { path = ../.; name = "prisma-engines-workspace-root-path"; };
src = pkgs.lib.cleanSourceWith { filter = enginesSourceFilter; src = srcPath; };
craneLib = inputs.crane.mkLib pkgs;
deps = craneLib.vendorCargoDeps { inherit src; };

enginesSourceFilter = path: type: (builtins.match "\\.pest$" path != null) ||
Expand Down
6 changes: 1 addition & 5 deletions nix/args.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
let toolchain = super.rust-bin.stable.latest; in
{ cargo = toolchain.minimal; rustc = toolchain.minimal; rustToolchain = toolchain; })
];

pkgs = import inputs.nixpkgs { inherit system overlays; };

craneLib = inputs.crane.mkLib pkgs;
in
{ inherit craneLib pkgs; };
{ pkgs = import inputs.nixpkgs { inherit system overlays; }; };
}
29 changes: 12 additions & 17 deletions prisma-fmt-wasm/default.nix
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
args@{ pkgs, system, craneLib, ... }:
{ pkgs, system, self', ... }:

let
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = args.craneLib.overrideToolchain toolchain;

inherit (pkgs) jq nodejs coreutils wasm-bindgen-cli;
deps = self'.packages.prisma-engines-deps;
inherit (pkgs) jq nodejs coreutils wasm-bindgen-cli stdenv;
inherit (builtins) readFile replaceStrings;
in
rec {
packages.prisma-fmt-wasm = craneLib.buildPackage {
pname = "prisma-fmt-wasm";
version = "0.1.0";

{
packages.prisma-fmt-wasm = stdenv.mkDerivation {
name = "prisma-fmt-wasm";
src = ../.;
nativeBuildInputs = with pkgs; [ git wasm-bindgen-cli ];
nativeBuildInputs = with pkgs; [ git wasm-bindgen-cli toolchain ];

cargoBuildCommand = "cargo build --release --target=wasm32-unknown-unknown --manifest-path=prisma-fmt-wasm/Cargo.toml";
cargoCheckCommand = "cargo check --target=wasm32-unknown-unknown --manifest-path=prisma-fmt-wasm/Cargo.toml";
cargoArtifacts = null; # do not cache dependencies
doCheck = false; # do not run tests
configurePhase = "mkdir .cargo && ln -s ${deps}/config.toml .cargo/config.toml";
buildPhase = "cargo build --release --target=wasm32-unknown-unknown -p prisma-fmt-build";
installPhase = readFile ./scripts/install.sh;
};

Expand All @@ -33,9 +28,9 @@ rec {
set -euxo pipefail
PACKAGE_DIR=$(mktemp -d)
cp -r --no-target-directory ${packages.prisma-fmt-wasm} "$PACKAGE_DIR"
cp -r --no-target-directory ${self'.packages.prisma-fmt-wasm} "$PACKAGE_DIR"
rm -f "$PACKAGE_DIR/package.json"
jq ".version = \"$1\"" ${packages.prisma-fmt-wasm}/package.json > "$PACKAGE_DIR/package.json"
jq ".version = \"$1\"" ${self'.packages.prisma-fmt-wasm}/package.json > "$PACKAGE_DIR/package.json"
echo "$PACKAGE_DIR"
'';
};
Expand All @@ -48,6 +43,6 @@ rec {
};

checks.prismaFmtWasmE2E = pkgs.runCommand "prismaFmtWasmE2E"
{ PRISMA_FMT_WASM = packages.prisma-fmt-wasm; NODE = "${nodejs}/bin/node"; }
{ PRISMA_FMT_WASM = self'.packages.prisma-fmt-wasm; NODE = "${nodejs}/bin/node"; }
(readFile ./scripts/check.sh);
}

0 comments on commit 2eeed5b

Please sign in to comment.