ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.81k stars 889 forks source link

Add Simple Nix Flake #7656

Open JosephGoulden opened 1 week ago

JosephGoulden commented 1 week ago

This is new PR to add a simple flake.nix to this project. It will allow downstream projects to easily import CLN into their system. They will be able to get new releases as soon as they are available instead of having to wait for nixpkgs to be updated. And they will be able to more easily test any changes being made in CLN.

There is an existing PR #6650 but progress has stalled with getting the Python dependencies working. I think it is best to leave that for a later date and focus on a minimal working and useful flake which I have created in this PR.

The default package is called cln, it has been copied from the one currently in nixpkgs. The derivation calls the Makefile and builds the binaries (lightningd, lightning-cli, lightning-hsmtool, reckless).

The use of git submodules makes the UX a little awkward but still works as expected with the right commands. e.g;

I've added a new .version file to source control. Having the version is source control is required in order to make a pure nix flake (fully deterministic, reproducible builds without dependencies on external environment). I understand this may not be ideal (from what I understand the version is usually derived from the git tags). But I can also see that the current version is already specified in multiple python files that must be updated each release. So the new .version file is one more place to update (perhaps it can become the only place to update). The version could also be put straight into default.nix if .version is not wanted.

I've added a new target to the CI workflow that checks the nix package builds successfully.

chrisguida commented 4 days ago

Hmm, for some reason it's not working for me on Ubuntu

$ nix develop
error:
       … while updating the lock file of flake 'git+file:///home/cguida/work/lightning/elementsproject?ref=refs/heads/pr7656&rev=0fc6bdf6d11a8a2a33567e480f0f7207a0172edc'

       error: unsupported tarball input attribute 'lastModified'
(cln-meta-project-py3.12) 2024-09-16 12:45:22 cguida@cg-acer:~/work/lightning/elementsproject$ nix --version
nix (Nix) 2.17.0

got any ideas?

chrisguida commented 4 days ago

ok i ran sudo -i nix upgrade-nix which upgraded my nix


$ sudo -i nix upgrade-nix
[sudo] password for cguida: 
replacing old 'nix-2.17.0'
installing 'nix-2.18.5'
building '/nix/store/yrgxb0lilsz84d1m8sllqq7pf6mxn5vr-user-environment.drv'...

Now it works!!

New problem though, the Rust build is failing with a giant pile of errors:

image

Any ideas on that?

JosephGoulden commented 4 days ago

All those errors stem from the "corrupt metadata" of lazy_static. I've not seen that before, can you try deleting your .cargo/registry, or at least that crate. And run cargo clean as well.

chrisguida commented 3 days ago

I ran rm -rf ~/.cargo/registry and now it builds!

$ lightningd/lightningd --version
v24.08-11-g0fc6bdf-modded

Seems like maybe the dev shell should handle this though, don't you think?

chrisguida commented 3 days ago

nix build .?submodules=1 works too!! not sure if this would have worked if I hadn't deleted the cargo registry though.

vincenzopalazzo commented 2 days ago

I ran rm -rf ~/.cargo/registry and now it builds!

This does not sounds right? the all point of nix is to have a sandbox, so ~/ should not be your home