The sound distributed version control system

#552 Alternative nix build with naersk

Opened by Anderssorby on October 16, 2021 Reviewing
Anderssorby on October 16, 2021

I’m experimenting with building pijul with naersk and a custom rust setup.

Anderssorby added a change on October 16, 2021
ZATP6MF2F6XB2VRVR2GEQ2Y6XXRES6C7QQYM2XJRAJJI3HYB7VFQC
Anderssorby added a change on October 16, 2021
Fix nix build and use naersk to build by HZVQFtjbhnRsZNcTqNkbgkDT47NMwiGoHjvCqCkuekqp,
6P7J7X7W2RBPODVMZWMW24IJLRT2DOFIZYDPEY323FH3EEQNSCEAC
Anderssorby added a change on October 16, 2021
Fix nix build and use naersk to build by HZVQFtjbhnRsZNcTqNkbgkDT47NMwiGoHjvCqCkuekqp,
OMTLDKD3B36US3ET4GRJDOUDVMQBIWHR7UHPIO57NSHLZJCJUPDAC
Anderssorby added a change on October 18, 2021
Update nix flake layout by HZVQFtjbhnRsZNcTqNkbgkDT47NMwiGoHjvCqCkuekqp,
2IDNT6MOJ6YUKHMRE65IPBJYPH7R43T56CW6LOX3GTW7INZJKE3AC
pmeunier on November 27, 2021

(edited) there was a bug in the Nest, now fixed.

pmeunier on December 6, 2021

Why is naersk better than buildRustCrate?

Anderssorby on December 6, 2021

The main reason is that it reads Cargo.lock and Cargo.toml directly and downloads dependencies directly. So you don’t need to generate a Cargo.nix and can always be compatible with cargo build. So it is zero config essentially. Naersk also has a lot of options to control how the build is done, but it could be improved too. Now this is probably not the best setup and it uses naersk via my repo at yatima-inc/nix-utils to load the rust compiler. I did this mostly to test.

pmeunier on December 6, 2021

This could indeed be an advantage, how does Naersk deal with features?

pmeunier added tag Reviewing on December 7, 2021
Anderssorby on December 7, 2021

I’ve recently become a maintainer of naersk https://github.com/nix-community/naersk The documentation is minimal, usually I read the source to figure things out. To deal with features you simply need to add an argument to buildRustPackage like

pijul-git = pijul.override { cargoBuildOptions = d: d ++ [ "--features git" ]; };

You can override any argument and setting really although this is not very well documented at this point.

Anderssorby closed this discussion on December 7, 2021
Anderssorby on December 7, 2021

Didn’t mean to close the discussion.

Anderssorby reopened this discussion on December 7, 2021
pmeunier on December 7, 2021

My question was how are features propagated? I don’t know how Naersk works, but I wrote the initial version of buildRustCrate in nixpkgs, and I like how features are dealt with using the Nix language itself.

Also, I’ve never managed to use Naersk to build and deploy things in production (this website, for example). I think an extra file to build with Naersk would be ok, but I’m not too favourable to replacing the current system with it.

Anderssorby added a change on December 7, 2021
Update cargo and nix flake by HZVQFtjbhnRsZNcTqNkbgkDT47NMwiGoHjvCqCkuekqp,
DTZBX5FVU7ZRMLFPUKOR2PGWSC2M75WA2TPZHN5MJTN6RYL5TGJAC
Anderssorby on December 7, 2021

Naersk just gives a simple interface to build crates with cargo. It provides functions to for example load dependencies and read from Cargo.toml. I guess it could be made into a separate file. Naersk works out of the box mostly, but I’m using my lib yatima-inc/nix-utils to load rust nightly. Naersk is nice for deploying things really. You can control which files are copied to the output directory. We use it for everything in Yatima Inc although we don’t have any active deployments.

pmeunier on December 7, 2021

Your patch contains lots of unrelated changes, I believe you could reset before recording. Also, are these against the latest main?

Anderssorby on December 7, 2021

I should probably fix that yeah. I’ve had some problems using pijul itself. They are against an older main.