diff --git a/README.md b/README.md
index 8ed3139..6a97906 100644
--- a/README.md
+++ b/README.md
@@ -239,6 +239,7 @@ process, rest is passed-through into `mkDerivation`.
| `cargoTestCommands` | The commands to run in the `checkPhase`. Do not forget to set [`doCheck`](https://nixos.org/nixpkgs/manual/#ssec-check-phase). The argument must be a function modifying the default value.
Default: `[ ''cargo $cargo_options test $cargo_test_options'' ]` |
| `cargoTestOptions` | Options passed to cargo test, i.e. `cargo test `. These options can be accessed during the build through the environment variable `cargo_test_options`.
Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces.
The argument must be a function modifying the default value.
Default: `[ "$cargo_release" ''-j "$NIX_BUILD_CORES"'' ]` |
| `cargoClippyOptions` | Options passed to cargo clippy, i.e. `cargo clippy -- `. These options can be accessed during the build through the environment variable `cargo_clippy_options`.
Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces.
The argument must be a function modifying the default value.
Default: `[ "-D warnings" ]` |
+| `cargoFmtOptions` | Options passed to cargo fmt, i.e. `cargo fmt -- `. These options can be accessed during the build through the environment variable `cargo_fmt_options`.
Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces.
The argument must be a function modifying the default value.
Default: `[ "--check" ]` |
| `nativeBuildInputs` | Extra `nativeBuildInputs` to all derivations. Default: `[]` |
| `buildInputs` | Extra `buildInputs` to all derivations. Default: `[]` |
| `cargoOptions` | Options passed to all cargo commands, i.e. `cargo ...`. These options can be accessed during the build through the environment variable `cargo_options`.
Note: these values are not (shell) escaped, meaning that you can use environment variables but must be careful when introducing e.g. spaces.
The argument must be a function modifying the default value.
Default: `[ ]` |
@@ -260,7 +261,7 @@ process, rest is passed-through into `mkDerivation`.
| `copyTarget` | When true, the `target/` directory is copied to `$out`. Default: `false` |
| `postInstall` | Optional hook to run after the compilation is done; inside this script, `$out/bin` contains compiled Rust binaries. Useful if your application needs e.g. custom environment variables, in which case you can simply run `wrapProgram $out/bin/your-app-name` in here. Default: `false` |
| `usePureFromTOML` | Whether to use the `fromTOML` built-in or not. When set to `false` the python package `remarshal` is used instead (in a derivation) and the JSON output is read with `builtins.fromJSON`. This is a workaround for old versions of Nix. May be used safely from Nix 2.3 onwards where all bugs in `builtins.fromTOML` seem to have been fixed. Default: `true` |
-| `mode` | What to do when building the derivation. Either `build`, `check`, `test` or `clippy`.
When set to something other than `build`, no binaries are generated. Default: `"build"` |
+| `mode` | What to do when building the derivation. Either `build`, `check`, `test`, `fmt` or `clippy`.
When set to something other than `build`, no binaries are generated. Default: `"build"` |
## Examples
diff --git a/build.nix b/build.nix
index c74b9db..2c814c1 100644
--- a/build.nix
+++ b/build.nix
@@ -39,6 +39,7 @@
# significantly reducing the Nix closure size.
, removeReferencesToSrcFromDocs
, cargoClippyOptions
+, cargoFmtOptions
, mode ? "build" # `build`, `check`, `test` or `clippy`
, gitDependencies
, pname
@@ -142,6 +143,7 @@ let
cargo_build_options = cargoBuildOptions;
cargo_test_options = cargoTestOptions;
cargo_clippy_options = cargoClippyOptions;
+ cargo_fmt_options = cargoFmtOptions;
cargo_doc_options = cargoDocOptions;
cargo_bins_jq_filter = copyBinsFilter;
cargo_libs_jq_filter = copyLibsFilter;
diff --git a/config.nix b/config.nix
index 3ee2e93..43b5f52 100644
--- a/config.nix
+++ b/config.nix
@@ -82,6 +82,14 @@ let
cargoClippyOptions =
allowFun attrs0 "cargoClippyOptions" [ "-D warnings" ];
+ # Options passed to cargo fmt, i.e. `cargo fmt -- `. These options
+ # can be accessed during the build through the environment variable
+ # `cargo_fmt_options`.
+ # Note: these values are not (shell) escaped, meaning that you can use
+ # environment variables but must be careful when introducing e.g. spaces.
+ cargoFmtOptions =
+ allowFun attrs0 "cargoFmtOptions" [ "--check" ];
+
# Extra `nativeBuildInputs` to all derivations.
nativeBuildInputs = attrs0.nativeBuildInputs or [];
@@ -189,7 +197,7 @@ let
# fixed.
usePureFromTOML = attrs0.usePureFromTOML or true;
- # What to do when building the derivation. Either `build`, `check`, `test` or `clippy`.
+ # What to do when building the derivation. Either `build`, `check`, `test`, `fmt` or `clippy`.
# When set to something other than `build`, no binaries are generated.
mode = attrs0.mode or "build";
};
@@ -257,6 +265,8 @@ let
''cargo $cargo_options test $cargo_test_options >> $cargo_build_output_json''
else if (mode == "clippy") then
''cargo $cargo_options clippy $cargo_build_options -- $cargo_clippy_options >> $cargo_build_output_json''
+ else if (mode == "fmt") then
+ ''cargo $cargo_options fmt -- $cargo_fmt_options''
else throw "Unknown mode ${mode}, allowed modes: build, check, test, clippy";
# config used during build the prebuild and the final build
@@ -284,6 +294,7 @@ let
cargoTestOptions
cargoClippyOptions
+ cargoFmtOptions
doDoc
doDocFail