crane/lib/cargoFmt.nix
Ivan Petkov 90d5ad84c4
cargoFmt: change behavior to install cargo artifacts by default
* This allows potentially chaining `cargoFmt` invocations with other
  derivations
2022-02-10 21:02:48 -08:00

29 lines
643 B
Nix

{ cargoBuild
, rustfmt
}:
{ cargoExtraArgs ? ""
, rustFmtExtraArgs ? ""
, ...
}@origArgs:
let
args = builtins.removeAttrs origArgs [ "rustFmtExtraArgs" ];
in
cargoBuild (args // {
cargoArtifacts = null;
cargoVendorDir = null;
doCheck = false;
doRemapSourcePathPrefix = false;
pnameSuffix = "-fmt";
cargoBuildCommand = "cargo fmt";
cargoExtraArgs = "${cargoExtraArgs} -- --check ${rustFmtExtraArgs}";
nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ rustfmt ];
preInstallPhases = [ "ensureTargetDir" ] ++ (args.preInstallPhases or [ ]);
ensureTargetDir = ''
mkdir -p ''${CARGO_TARGET_DIR:-target}
'';
})