mimblewimble / grin

Minimal implementation of the Mimblewimble protocol.
https://grin.mw/
Apache License 2.0
5.04k stars 990 forks source link

feat: Add nix/flake support #3743

Closed chives101 closed 1 year ago

chives101 commented 1 year ago

Motivation

This PR enables power users to easily and reliably build the project from source code.

Expectation

A user with the nix package manager installed can build the project with the following command:

nix build github:mimblewimble/grin

and expect the resulting binaries in ./result/bin.

Testing

If flake hasn't been enabled, use nix build --extra-experimental-features 'nix-command flakes' in place of nix build.

A test run for this PR can be achieved using my forked repo with the following command:

nix build github:chives101/grin/flake and expect a binary at ./result/bin/grin.

Or by entering the project folder and do nix build after applying the PR.

Dev notes

This PR is the result of a simple adaptation of the code from this blog post:

https://www.tweag.io/blog/2022-09-22-rust-nix/

phyro commented 1 year ago

@chives101 I seem to have a rather strange encoding issue when I run it with ./result/bin/grin --testnet. It works if I do cargo build and ./target/debug/grin --testnet so it seems it's something with the build.

here

quentinlesceller commented 1 year ago

@phyro iirc this might be something related with libncurses.

chives101 commented 1 year ago

@phyro Is it tested with the latest repo? I did a force push that updated the nixpkgs dependency which was pretty outdated.

I just tested the repo, works fine for me. BTW, you can do a local test by entering the project folder and do nix build after applying the PR.

chives101 commented 1 year ago

@phyro I did a fresh build on debian bullseye, I couldn't reproduce your issue though.

pkariz commented 1 year ago

on nixos 22.11 it worked for me although it's weird that @phyro is getting these characters. I recall having the same problem but i've fixed it by installing newer ncurses or some other package. Will try to reproduce the problem.

chives101 commented 1 year ago

@pkariz It is weird, because flake is supposed to be hermetic. Guess it's not that airtight after all.

phyro commented 1 year ago

@chives101 apologies that I didn't get back to you. I tried it again with the latest changes and I get the same. It seems @pkariz can't test this right now. My suggestion is to take the incremetal improvement appoach and merge it in. The current solution seems to work at least for those that are on nixos and some others (debian above) and this itself is valuable. It's also my observation that quite a few people in the Rust community like Nix so we'll likely get more people to chime in and patch it over time.

I'll wait a bit in case someone disagrees with merging, otherwise I'll go ahead and merge it.

phyro commented 1 year ago

Thanks for your contribution @chives101 ! I'm not around my PC to test the grin-wallet PR again after the changes until next week, but will do that then. :+1:

chives101 commented 1 year ago

@phyro It's fine, it's nothing. I'm pretty sure there's more I can do :D