2022-12-05 03:19:51 +00:00
|
|
|
{
|
|
|
|
description =
|
|
|
|
"ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz, etc.";
|
|
|
|
|
|
|
|
inputs = {
|
2023-04-24 00:11:56 +00:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs";
|
2022-12-05 03:19:51 +00:00
|
|
|
|
|
|
|
crane = {
|
|
|
|
url = "github:ipetkov/crane";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
|
|
|
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
|
|
|
|
rust-overlay = {
|
|
|
|
url = "github:oxalica/rust-overlay";
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.follows = "nixpkgs";
|
|
|
|
flake-utils.follows = "flake-utils";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
advisory-db = {
|
|
|
|
url = "github:rustsec/advisory-db";
|
|
|
|
flake = false;
|
|
|
|
};
|
|
|
|
|
2023-04-24 00:11:56 +00:00
|
|
|
pre-commit-hooks = {
|
|
|
|
url = "github:cachix/pre-commit-hooks.nix";
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.follows = "nixpkgs";
|
|
|
|
flake-utils.follows = "flake-utils";
|
|
|
|
};
|
|
|
|
};
|
2022-12-05 03:19:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, advisory-db
|
|
|
|
, pre-commit-hooks }:
|
|
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
|
|
let
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = [ (import rust-overlay) ];
|
|
|
|
};
|
|
|
|
|
|
|
|
craneLib = crane.lib.${system};
|
2023-04-24 00:11:26 +00:00
|
|
|
src = pkgs.lib.cleanSourceWith {
|
|
|
|
src = craneLib.path ./.; # original, unfiltered source
|
|
|
|
filter = path: type:
|
|
|
|
(builtins.match ".*jsonc$" path != null) # include JSONC files
|
|
|
|
|| (craneLib.filterCargoSources path type);
|
|
|
|
};
|
2022-12-05 03:19:51 +00:00
|
|
|
|
|
|
|
buildInputs = with pkgs;
|
|
|
|
[ ffmpeg imagemagick pandoc poppler_utils ripgrep tesseract ]
|
2023-04-24 00:13:44 +00:00
|
|
|
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
|
2022-12-05 03:19:51 +00:00
|
|
|
# Additional darwin specific inputs can be set here
|
|
|
|
pkgs.libiconv
|
|
|
|
];
|
|
|
|
|
|
|
|
# Build *just* the cargo dependencies, so we can reuse
|
|
|
|
# all of that work (e.g. via cachix) when running in CI
|
|
|
|
cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; };
|
|
|
|
|
|
|
|
# Build the actual crate itself, reusing the dependency
|
|
|
|
# artifacts from above.
|
|
|
|
rga = craneLib.buildPackage {
|
|
|
|
inherit cargoArtifacts src buildInputs;
|
|
|
|
doCheck = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
pre-commit = pre-commit-hooks.lib."${system}".run;
|
|
|
|
in {
|
2022-12-31 19:59:04 +00:00
|
|
|
# `nix flake check`
|
2022-12-05 03:19:51 +00:00
|
|
|
checks = {
|
|
|
|
# Build the crate as part of `nix flake check` for convenience
|
|
|
|
inherit rga;
|
|
|
|
|
|
|
|
# Run clippy (and deny all warnings) on the crate source,
|
|
|
|
# again, resuing the dependency artifacts from above.
|
|
|
|
#
|
|
|
|
# Note that this is done as a separate derivation so that
|
|
|
|
# we can block the CI if there are issues here, but not
|
|
|
|
# prevent downstream consumers from building our crate by itself.
|
|
|
|
rga-clippy = craneLib.cargoClippy {
|
|
|
|
inherit cargoArtifacts src buildInputs;
|
|
|
|
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
|
|
|
};
|
|
|
|
|
|
|
|
rga-doc = craneLib.cargoDoc { inherit cargoArtifacts src; };
|
|
|
|
|
|
|
|
# Check formatting
|
|
|
|
rga-fmt = craneLib.cargoFmt { inherit src; };
|
|
|
|
|
|
|
|
# Audit dependencies
|
|
|
|
rga-audit = craneLib.cargoAudit { inherit src advisory-db; };
|
|
|
|
|
|
|
|
# Run tests with cargo-nextest.
|
|
|
|
rga-nextest = craneLib.cargoNextest {
|
|
|
|
inherit cargoArtifacts src buildInputs;
|
|
|
|
partitions = 1;
|
|
|
|
partitionType = "count";
|
|
|
|
};
|
|
|
|
|
2022-12-31 19:59:04 +00:00
|
|
|
pre-commit = pre-commit {
|
2022-12-05 03:19:51 +00:00
|
|
|
src = ./.;
|
|
|
|
hooks = {
|
|
|
|
nixfmt.enable = true;
|
|
|
|
rustfmt.enable = true;
|
|
|
|
cargo-check.enable = true;
|
2023-07-02 00:41:59 +00:00
|
|
|
typos = {
|
|
|
|
enable = true;
|
|
|
|
types = [ "text" ];
|
|
|
|
excludes = [ "exampledir/.*" ];
|
|
|
|
};
|
2022-12-05 03:19:51 +00:00
|
|
|
};
|
|
|
|
};
|
2023-04-24 00:13:44 +00:00
|
|
|
} // pkgs.lib.optionalAttrs (system == "x86_64-linux") {
|
2022-12-05 03:19:51 +00:00
|
|
|
# NB: cargo-tarpaulin only supports x86_64 systems
|
|
|
|
# Check code coverage (note: this will not upload coverage anywhere)
|
|
|
|
rga-coverage =
|
|
|
|
craneLib.cargoTarpaulin { inherit cargoArtifacts src; };
|
|
|
|
};
|
|
|
|
|
|
|
|
# `nix build`
|
2023-04-24 00:12:41 +00:00
|
|
|
packages = {
|
|
|
|
inherit rga; # `nix build .#rga`
|
|
|
|
default = rga; # `nix build`
|
|
|
|
};
|
2022-12-05 03:19:51 +00:00
|
|
|
|
|
|
|
# `nix run`
|
|
|
|
apps.default = flake-utils.lib.mkApp { drv = rga; };
|
|
|
|
|
|
|
|
# `nix develop`
|
|
|
|
devShells.default = pkgs.mkShell {
|
2022-12-31 19:59:04 +00:00
|
|
|
inherit (self.checks.${system}.pre-commit) shellHook;
|
2022-12-05 03:19:51 +00:00
|
|
|
inputsFrom = builtins.attrValues self.checks;
|
2022-12-31 19:59:04 +00:00
|
|
|
buildInputs = buildInputs
|
|
|
|
++ (with pkgs; [ cargo nixfmt rustc rustfmt ]);
|
2022-12-05 03:19:51 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|