about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2022-12-22T14·44+0100
committerflokli <flokli@flokli.de>2022-12-22T15·26+0000
commit40a17acdc11a7bbd45cde834e41c42ba04f4628d (patch)
treee65db739f9d1d7580de1fc1be42f59ad4771d359 /tvix
parent2e04f68df8c69034151cce5b56ceedb0653687cd (diff)
feat(tvix): add crate2nixGenerate target r/5472
`mg run //tvix:crate2nixGenerate --` runs crate2nix generate and
depotfmt's it afterwards.

This removes a frequent point of friction, because the Cargo.nix emitted
by crate2nix needs another formatter.

Change-Id: I649495980718cd3847d4cff77c9d4bfcb599387c
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7612
Tested-by: BuildkiteCI
Reviewed-by: grfn <grfn@gws.fyi>
Diffstat (limited to 'tvix')
-rw-r--r--tvix/README.md11
-rw-r--r--tvix/default.nix9
2 files changed, 11 insertions, 9 deletions
diff --git a/tvix/README.md b/tvix/README.md
index 2a482097042e..e06b59bef9e7 100644
--- a/tvix/README.md
+++ b/tvix/README.md
@@ -14,14 +14,9 @@ single Rust workspace in `//tvix` to maintain the Nix build
 configuration.
 
 When making changes to Cargo dependency configuration in any of the
-Rust projects under `//tvix`, be sure to run `crate2nix generate` in
-`//tvix` itself and commit the changes to the generated `Cargo.nix`
-file.
-
-`crate2nix` is available via `direnv` inside of depot, or can be built
-from the `third_party.nixpkgs.crate2nix` attribute of depot. Make sure
-to build it from depot to avoid generating files with a different
-version that might have different output.
+Rust projects under `//tvix`, be sure to run
+`mg run //tvix:crate2nixGenerate --` in `//tvix` itself and commit the changes
+to the generated `Cargo.nix` file.
 
 ## License structure
 
diff --git a/tvix/default.nix b/tvix/default.nix
index 23ce0592ceb6..8708222a603d 100644
--- a/tvix/default.nix
+++ b/tvix/default.nix
@@ -1,5 +1,5 @@
 # Nix helpers for projects under //tvix
-{ pkgs, ... }:
+{ pkgs, depot, ... }:
 
 {
   # Load the crate2nix crate tree.
@@ -8,6 +8,13 @@
     nixpkgs = pkgs.path;
   };
 
+  # Run crate2nix generate in the current working directory, then
+  # format the generated file with depotfmt.
+  crate2nixGenerate = pkgs.writeShellScriptBin "crate2nix-generate" ''
+    ${pkgs.crate2nix}/bin/crate2nix generate
+    ${depot.tools.depotfmt}/bin/depotfmt Cargo.nix
+  '';
+
   # Provide a shell for the combined dependencies of all Tvix Rust
   # projects. Note that as this is manually maintained it may be
   # lacking something, but it is required for some people's workflows.