diff options
author | EuAndreh <eu@euandre.org> | 2020-10-05 21:27:57 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2020-10-10 14:31:24 -0300 |
commit | a7c4db7e9215694ef6c50debcc0b4e7402265687 (patch) | |
tree | d45b89f1758b34416e5157cb0e7404276c6fa49a /_articles/2020-10-05-cargo2nix-dramatically-simpler-rust-in-nix.md | |
parent | cargo2nix: Use overlay on example (diff) | |
download | euandre.org-a7c4db7e9215694ef6c50debcc0b4e7402265687.tar.gz euandre.org-a7c4db7e9215694ef6c50debcc0b4e7402265687.tar.xz |
Refactor i18n structure, remove layouts, add slides
Yep, this commit is too big big I didn't want to take the trouble of splitting
it now.
- _config.yml translation keys are now simetrical on the entitiy: articles,
pastebins, tils, slides, etc.;
- _posts were moved to _articles: the _posts collection had special treatment in
Jekyll which I wanted to avoid;
- the filtering of entries for the Atom feed is now done inside the
_includes/feed.atom file instead of every feed file;
- all entities are now dealt with using the pluralized name: articles,
pastebins, tils, slides. No more inconsistencies on the key names, they now
should only make sense as the translation value on the dictionary;
- add base reveal.js infrastruture, with Jekyll generating the listing page and
nothing else.
Diffstat (limited to '_articles/2020-10-05-cargo2nix-dramatically-simpler-rust-in-nix.md')
-rw-r--r-- | _articles/2020-10-05-cargo2nix-dramatically-simpler-rust-in-nix.md | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/_articles/2020-10-05-cargo2nix-dramatically-simpler-rust-in-nix.md b/_articles/2020-10-05-cargo2nix-dramatically-simpler-rust-in-nix.md new file mode 100644 index 0000000..d4b5a41 --- /dev/null +++ b/_articles/2020-10-05-cargo2nix-dramatically-simpler-rust-in-nix.md @@ -0,0 +1,76 @@ +--- +title: "cargo2nix: Dramatically simpler Rust inside Nix" +date: 2020-10-05 +layout: post +lang: en +ref: cargo2nix-dramatically-simpler-rust-in-nix +--- + +In the same vein of my earlier post on +[swift2nix]({% link _articles/2020-10-05-swift2nix-run-swift-inside-nix-builds.md %}), 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][37-lines]. + +[cargo2nix]: https://git.euandreh.xyz/cargo2nix/about/ +[37-lines]: https://git.euandreh.xyz/cargo2nix/tree/default.nix?id=472dde8898296c8b6cffcbd10b3b2c3ba195846d + +Here's how to use it (snippet taken from the repo's README): + +```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): + +```shell +pushd "$(mktemp -d)" +git clone https://git.euandreh.xyz/cargo2nix-demo +cd cargo2nix-demo/ +nix-build +``` + +Report back if you wish. Again, patches welcome. |