diff options
author | EuAndreh <eu@euandre.org> | 2025-04-18 02:17:12 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-04-18 02:48:42 -0300 |
commit | 020c1e77489b772f854bb3288b9c8d2818a6bf9d (patch) | |
tree | 142aec725a52162a446ea7d947cb4347c9d573c9 /src/content/blog/2020/10/05/cargo2nix.adoc | |
parent | Makefile: Remove security.txt.gz (diff) | |
download | euandre.org-020c1e77489b772f854bb3288b9c8d2818a6bf9d.tar.gz euandre.org-020c1e77489b772f854bb3288b9c8d2818a6bf9d.tar.xz |
git mv src/content/* src/content/en/
Diffstat (limited to 'src/content/blog/2020/10/05/cargo2nix.adoc')
-rw-r--r-- | src/content/blog/2020/10/05/cargo2nix.adoc | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/src/content/blog/2020/10/05/cargo2nix.adoc b/src/content/blog/2020/10/05/cargo2nix.adoc deleted file mode 100644 index a2d478e..0000000 --- a/src/content/blog/2020/10/05/cargo2nix.adoc +++ /dev/null @@ -1,72 +0,0 @@ -= cargo2nix: Dramatically simpler Rust in Nix -:sort: 1 - -:empty: -:swift2nix: link:swift2nix.html -:cargo2nix: link:cargo2nix-demo.tar.gz - -In the same vein of my earlier post on {swift2nix}[swift2nix], I was able to -quickly prototype a Rust and Cargo variation of it: {cargo2nix}[cargo2nix]. - -The initial prototype is even smaller than swift2nix: it has only 37 lines of -code. - -Here's how to use it (snippet taken from the repo's README): - -[source,nix] ----- -let - niv-sources = import ./nix/sources.nix; - mozilla-overlay = import niv-sources.nixpkgs-mozilla; - pkgs = import niv-sources.nixpkgs { overlays = [ mozilla-overlay ]; }; - src = pkgs.nix-gitignore.gitignoreSource [ ] ./.; - cargo2nix = pkgs.callPackage niv-sources.cargo2nix { - lockfile = ./Cargo.lock; - }; -in pkgs.stdenv.mkDerivation { - inherit src; - name = "cargo-test"; - buildInputs = [ pkgs.latest.rustChannels.nightly.rust ]; - phases = [ "unpackPhase" "buildPhase" ]; - buildPhase = '' - # Setup dependencies path to satisfy Cargo - mkdir .cargo/ - ln -s ${cargo2nix.env.cargo-config} .cargo/config - ln -s ${cargo2nix.env.vendor} vendor - - # Run the tests - cargo test - touch $out - ''; -} ----- - -That `cargo test` part on line 20 is what I have been fighting with every -"*2nix" available for Rust out there. I don't want to bash any of them. All I -want is to have full control of what Cargo commands to run, and the "*2nix" tool -should only setup the environment for me. Let me drive Cargo myself, no need to -parameterize how the tool runs it for me, or even replicate its internal -behaviour by calling the Rust compiler directly. - -Sure it doesn't support private registries or Git dependencies, but how much -bigger does it has to be to support them? Also, it doesn't support those *yet*, -there's no reason it can't be extended. I just haven't needed it yet, so I -haven't added. Patches welcome. - -The layout of the `vendor/` directory is more explicit and public then what -swift2nix does: it is whatever the command `cargo vendor` returns. However I -haven't checked if the shape of the `.cargo-checksum.json` is specified, or -internal to Cargo. - -Try out the demo (also taken from the repo's README): - -[source,sh] ----- -pushd "$(mktemp -d)" -wget -O- https://euandre.org/static/attachments/cargo2nix-demo.tar.gz | - tar -xv -cd cargo2nix-demo/ -nix-build ----- - -Report back if you wish. |