Skip to content

Commit

Permalink
cargoAudit: use mkCargoDerivation instead of cargoBuild
Browse files Browse the repository at this point in the history
  • Loading branch information
ipetkov committed Oct 9, 2022
1 parent b61434b commit 8c97f06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
`crateNameFromCargoToml`) if they are not specified
* `mkCargoDerivation` now defaults to an empty `checkPhaseCargoCommand` if not
specified
* `cargoAudit` now delegates to `mkCargoDerivation` instead of `cargoBuild`
* `cargoDoc` now delegates to `mkCargoDerivation` instead of `cargoBuild`
* `cargoFmt` now delegates to `mkCargoDerivation` instead of `cargoBuild`

Expand Down
10 changes: 4 additions & 6 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,11 @@ Create a derivation which will run a `cargo audit` invocation in a cargo
workspace.

Except where noted below, all derivation attributes are delegated to
`cargoBuild`, and can be used to influence its behavior.
* `cargoArtifacts` will be set to `null` as they are not needed
* `cargoBuildCommand` will be set to run `cargo audit -n -d ${advisory-db}` in
`mkCargoDerivation`, and can be used to influence its behavior.
* `buildPhaseCargoCommand` will be set to run `cargo audit -n -d ${advisory-db}` in
the workspace.
* `cargoExtraArgs` will have `cargoAuditExtraArgs` appended to it
- Default value: `""`
* `cargoArtifacts` will be set to `null` as they are not needed
* `cargoVendorDir` will be set to `null` as it is not needed
* `doCheck` is disabled
* `doInstallCargoArtifacts` is disabled
* `pnameSuffix` will be set to `"-audit"`
* `src` will be filtered to only keep `Cargo.lock` files
Expand Down Expand Up @@ -233,6 +230,7 @@ The following attributes will be removed before being lowered to
environment variables during the build, you can bring them back via
`.overrideAttrs`.
* `cargoAuditExtraArgs`
* `cargoExtraArgs`

### `lib.cargoBuild`

Expand Down
13 changes: 7 additions & 6 deletions lib/cargoAudit.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ cargo-audit
, cargoBuild
, lib
, mkCargoDerivation
}:

{ advisory-db
Expand All @@ -10,11 +10,13 @@
, ...
}@origArgs:
let
args = builtins.removeAttrs origArgs [ "cargoAuditExtraArgs" ];
args = builtins.removeAttrs origArgs [
"cargoAuditExtraArgs"
"cargoExtraArgs"
];
in
cargoBuild (args // {
cargoBuildCommand = "cargo audit -n -d ${advisory-db}";
cargoExtraArgs = "${cargoExtraArgs} ${cargoAuditExtraArgs}";
mkCargoDerivation (args // {
buildPhaseCargoCommand = "cargo audit ${cargoExtraArgs} -n -d ${advisory-db} ${cargoAuditExtraArgs}";

src = lib.cleanSourceWith {
inherit src;
Expand All @@ -27,7 +29,6 @@ cargoBuild (args // {

cargoArtifacts = null; # Don't need artifacts, just Cargo.lock
cargoVendorDir = null; # Don't need dependencies either
doCheck = false; # We don't need to run tests to benefit from `cargo audit`
doInstallCargoArtifacts = false; # We don't expect to/need to install artifacts
pnameSuffix = "-audit";

Expand Down

0 comments on commit 8c97f06

Please sign in to comment.