aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flake.nix4
-rw-r--r--rust-format-all.nix20
2 files changed, 23 insertions, 1 deletions
diff --git a/flake.nix b/flake.nix
index 332eae4..ee34c17 100644
--- a/flake.nix
+++ b/flake.nix
@@ -68,6 +68,8 @@
{}
guests;
in {
- packages.${system} = hostPackages // guestPackages;
+ packages.${system} = hostPackages // guestPackages // {
+ rust-format-all = callPackage ./rust-format-all.nix { };
+ };
};
}
diff --git a/rust-format-all.nix b/rust-format-all.nix
new file mode 100644
index 0000000..710f1ef
--- /dev/null
+++ b/rust-format-all.nix
@@ -0,0 +1,20 @@
+{ writeShellApplication
+, rustfmt
+,
+}:
+writeShellApplication {
+ name = "rustfmt_all";
+
+ runtimeInputs = [ rustfmt ];
+
+ text = ''
+ # Using rustfmt instead of cargo fmt, because the latter doesn't support proc-macro crates
+ # Additionally, instead of emitting an error, it will "hang", waiting for input
+ while read -r file
+ do
+ rustfmt --edition 2021 -v "$@" "$file" || exit $?
+ done <<EOF
+ $(find . -type f -name "*.rs" -not -path "*target*")
+ EOF
+ '';
+}