Skip to content

Commit

Permalink
nix: use gitignore.nix to clean engines source (#3631)
Browse files Browse the repository at this point in the history
This replaces custom filter functions with gitignore rules. They are
easier to read, more familiar, and we can leverage our existing
.gitignore.

Using this, I observed we could cache (expensive, long) builds of the
prisma-engines packages a lot more often in development.

I also tried nix-gitignore, but it was not producing a stable hash
without changes in the non-gitignored files.
  • Loading branch information
tomhoule authored Jan 27, 2023
1 parent 54716a4 commit 35b907e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
21 changes: 21 additions & 0 deletions flake.lock

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

4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs";
};
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
Expand Down
23 changes: 14 additions & 9 deletions nix/all-engines.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
{ craneLib, pkgs, flakeInputs, ... }:
{ pkgs, flakeInputs, lib, ... }:

let
srcPath = builtins.path { path = ../.; name = "prisma-engines-workspace-root-path"; };
src = pkgs.lib.cleanSourceWith { filter = enginesSourceFilter; src = srcPath; };
srcPath = ../.;
srcFilter = flakeInputs.gitignore.lib.gitignoreFilterWith {
basePath = srcPath;
extraRules = ''
/nix
/flake.*
'';
};
src = lib.cleanSourceWith {
filter = srcFilter;
src = srcPath;
name = "prisma-engines-source";
};
craneLib = flakeInputs.crane.mkLib pkgs;
deps = craneLib.vendorCargoDeps { inherit src; };
libSuffix = if pkgs.stdenv.isDarwin then "dylib" else "so";

enginesSourceFilter = path: type: (builtins.match "\\.pest$" path != null) ||
(builtins.match "\\.README.md$" path != null) ||
(builtins.match "^\\.git/HEAD" path != null) ||
(builtins.match "^\\.git/refs" path != null) ||
(craneLib.filterCargoSources path type != null);
in
{
packages.prisma-engines-deps = deps;
Expand Down

0 comments on commit 35b907e

Please sign in to comment.