Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Nix flakes and haskell.nix #1570

Merged
merged 56 commits into from
Apr 28, 2023
Merged

Add support for Nix flakes and haskell.nix #1570

merged 56 commits into from
Apr 28, 2023

Conversation

jwiegley
Copy link
Collaborator

@jwiegley jwiegley commented Dec 1, 2022

This PR adds a flake.nix that uses haskell.nix to Nixify the chainweb-node package using the Haskell dependency versions from the cabal.project.freeze file. This PR retains the old Nix infrastructure but it's planned to be removed in a subsequent PR.

@jwiegley jwiegley marked this pull request as ready for review December 5, 2022 21:08
@imalsogreg
Copy link
Contributor

imalsogreg commented Dec 6, 2022

Suddenly I'm getting this error. Fresh checkout of chainweb-node, running on nixos:

$ nix develop .

Error: cabal: Could not resolve dependencies:
[__0] trying: chainweb-2.17.1 (user goal)
[__1] trying: servant-client-core-0.19 (dependency of chainweb)
[__2] next goal: free (dependency of servant-client-core)
[__2] rejecting: free-5.1.9, free-5.1.8, free-5.1.7, free-5.1.6, free-5.1.5,
free-5.1.4, free-5.1.3, free-5.1.2, free-5.1.1, free-5.1, free-5.0.2,
free-5.0.1, free-4.12.4, free-4.12.3, free-4.12.2, free-4.12.1, free-4.12,
free-4.11, free-4.10.0.1, free-4.9, free-4.8.0.1, free-4.8, free-4.7.1,
free-4.7, free-4.6.1, free-4.6, free-4.5, free-4.4, free-4.2, free-4.1,
free-4.0, free-3.4.2, free-3.4.1, free-3.4, free-3.3.1, free-3.3.0.2,
free-3.3.0.1, free-3.3, free-3.2, free-3.1.1, free-3.1, free-3.0, free-2.2,
free-2.1.1.1, free-2.1.1, free-2.1, free-2.0.3, free-2.0.2, free-2.0.1.1,
free-2.0.1, free-2.0, free-1.8.0.4, free-1.8.0.3, free-1.8.0.1, free-1.8.0,
free-0.2.3, free-0.2.2, free-0.2.1, free-0.2.0, free-0.1.1, free-0.1.0, free-5
(constraint from project config /build/tmp.NlxaRfGeTi/cabal.project.freeze
requires ==5.1.10)
[__2] fail (backjumping, conflict set: free, servant-client-core)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: free, servant-client-core, chainweb

@jwiegley
Copy link
Collaborator Author

@enobayram I'm seeing this error when I run nix develop:

Vulcan ~/kadena/work/nix-flake/chainweb-node $ nix develop
error: builder for '/nix/store/7gkpi57ig92nf4l54j0cb5g3vs60jg5d-http2-lib-http2-4.0.0-haddock.drv' failed with exit code 1;
       last 10 log lines:
       >     StreamingChunk (Network/HTTP2/Arch/Types.hs:197)
       >     fillBuilderBodyGetNext (Network/HTTP2/Arch/Sender.hs:320)
       >     fillFileBodyGetNext (Network/HTTP2/Arch/Sender.hs:326)
       >     fillStreamBodyGetNext (Network/HTTP2/Arch/Sender.hs:333)
       >
       > Network/HTTP2/Server/Types.hs:33:5: error: parse error on input ‘}’
       >    |
       > 33 |     }
       >    |     ^
       >
       For full logs, run 'nix log /nix/store/7gkpi57ig92nf4l54j0cb5g3vs60jg5d-http2-lib-http2-4.0.0-haddock.drv'.
error: 1 dependencies of derivation '/nix/store/8bnhs552wrpi8cqpr6sgxs92hf791cl0-hoogle-with-packages.drv' failed to build
error: 1 dependencies of derivation '/nix/store/5nbkhnspr7pz6f1bjklsxglxdwigadcc-ghc-shell-for-packages-ghc-8.10.7-env.drv' failed to build
error (ignored): error: cannot unlink '/private/tmp/nix-build-Cabal-lib-Cabal-3.2.1.0.drv-0/Cabal-3.2.1.0': Directory not empty
error: 1 dependencies of derivation '/nix/store/3m2y0ppzw30z9bzrclxzbs2gh7lxxpnf-ghc-shell-for-packages-env.drv' failed to build

@enobayram
Copy link
Contributor

@jwiegley Ugh, that's ugly. Luckily, I'm getting the same error on Linux, so I should be able to fix it soon.

@chessai
Copy link
Contributor

chessai commented Apr 21, 2023

This also moves us away from haskell4nix (nixpkgs' haskell infrastructure) and over to haskell.nix, so two-in-one. I don't have a problem with that, but I was not expecting that based on the PR title.

@jwiegley jwiegley changed the title Add support for Nix flakes Add support for Nix flakes and haskell.nix Apr 24, 2023
@jwiegley
Copy link
Collaborator Author

Title updated. It didn't make sense to move to flakes without haskell.nix.

@jwiegley
Copy link
Collaborator Author

@enobayram Everything looks good on my end.

default.nix Outdated
, ...
}:
let chainweb-node = pkgs.haskell-nix.project' {
src = ./.;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this gets rid of nix-gitignore.

Flake input:

nix-gitignore.url = github:hercules-ci/gitignore.nix";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably we would want a shared src attribute between both appearances in default.nix, so they have consistent ignores.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out this issue @chessai! I think using hercules-ci/gitignore.nix is a good suggestion, but AFAIK, that only filters out the files that are ignored by git, but it will accept new files that are neither ignored nor tracked by git. I think it's a reasonable thing that it does, but unfortunately that behavior is not the same as how Nix flakes behave. A Nix flake will first be copied to the Nix store and it will get built there. While the Nix flake gets copied, only files that are tracked by git will be copied, but if there are any changes they will be copied with those changes.

Instead of going forward with hercules-ci/gitignore.nix, I've decided to keep default.nix compatible with flake.nix by using src = self.outPath. Here's a demonstration of how this makes default.nix equivalent to flake.nix:

$ nix build --print-out-paths
/nix/store/8q1h87dpbv595ik2r5sw6rz29v836qq0-chainweb-exe-chainweb-node-2.18.1

$ nix-build 
/nix/store/8q1h87dpbv595ik2r5sw6rz29v836qq0-chainweb-exe-chainweb-node-2.18.1

$ touch somenewfile
$ nix-build 
/nix/store/8q1h87dpbv595ik2r5sw6rz29v836qq0-chainweb-exe-chainweb-node-2.18.1
$ nix build --print-out-paths
/nix/store/8q1h87dpbv595ik2r5sw6rz29v836qq0-chainweb-exe-chainweb-node-2.18.1

$ echo changing tracked file >> README.md 
$ nix build --print-out-paths
warning: Git tree '.../chainweb-node' is dirty
/nix/store/rlxyjmwqalljkzg088dzwy0kd8bbaqnl-chainweb-exe-chainweb-node-2.18.1
$ nix-build 
warning: Git tree '.../chainweb-node' is dirty
/nix/store/rlxyjmwqalljkzg088dzwy0kd8bbaqnl-chainweb-exe-chainweb-node-2.18.1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably we would want a shared src attribute between both appearances in default.nix, so they have consistent ignores.

Seems like this comment isn't applicable anymore with my latest changes.

@chessai
Copy link
Contributor

chessai commented Apr 24, 2023

This currently runs into input-output-hk/haskell.nix#1367.

There are workarounds described there.

@enobayram
Copy link
Contributor

I will close and reopen the PR for debugging the new github action

@enobayram enobayram closed this Apr 25, 2023
@larskuhtz
Copy link
Contributor

Are we sure that anybody is using the current docker.nix? I guess that nobody used that in a long time.

@enobayram
Copy link
Contributor

enobayram commented Apr 26, 2023

Upon John's advice, I've just pushed a few commits that rename the new default.nix to default-flake.nix and restore the old default.nix. So docker.nix should work as before. So I think this PR is ready to merge as it is, but I'd like to leave to the chainweb team the decision to enable the Mac builds in the CI and unleash the 10-hour first-time builds on the Mac runners.

@jwiegley
Copy link
Collaborator Author

Are we good to go here?

Copy link
Contributor

@larskuhtz larskuhtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this PR replace the previous nix infrastructure? If that's the case, would it be possible to delete the old files?

If the old files are still required, would it be possible to bundle those in a single subdirectory. I don't know which files are actually needed and which ones are just left overs from old setups. In particular, I am not aware that anybody ever used a nix generated docker file for chain web-node -- but I may just not be know about it.

(Ideally, all nix files would go into a ./nix subdirectory, to make it easier to identify which files belong to it. But not sure if that's possible.)

@@ -55,26 +55,31 @@ source-repository-package
type: git
location: https://github.com/kadena-io/pact.git
tag: 842fbc4256b3cbbde337dbeaa393b649a26f1574
--sha256: sha256-jD4Y2NOSYT0EQHs5BRSVvu8asfvRwt5XLDuZwbcG4mk=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are those pins determined when updating the source tag for a package? Is that somewhere documented?

In the past we would just wait for the zeus nix build to fail and copy and paste from the failure message? That wasn't ideal (because of the extra CI roundtrip) but worked. Will that method still work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any mechanism that guarantees that the source version represented by the --sha value matches the sources of the source tag?

In the past (with the old nix infra) we ran into issues where nix pins didn't exactly match the sources of the respective Hackage version and there was no easy way to detected that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command to determine the sha locally is:

nix-prefetch-git --url https://github.com/kadena-io/pact.git --rev <SHA>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add that as a comment to the cabal.project file? So when people update that file they find that info?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we include an action in the CI workflow that runs that command to double checks that the nix --sha actually matches the source tag?

(You may take a look at cabal CI workflows; there are examples for actions that check that the git tree is still clean after performing some action or test.)

Copy link
Contributor

@enobayram enobayram Apr 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larskuhtz Earlier today, I've added a step to check the hashes during the github action build, but then later I realized that the check was redundant, because it doesn't seem to be possible to start the build with a wrong sha256 anyway. I've tried multiple ways to fool it, like changing the source-repository-package commit hash without updating the sha256, but the nix build step always failed quickly, telling the correct sha256. As an example, check out this run: https://github.com/kadena-io/chainweb-node/actions/runs/4831581150/jobs/8609217888

The build took 2 minutes to fail and the error message tells you how you need to update the hash:

error: hash mismatch in fixed-output derivation '/nix/store/h9wwd3i3g0shagpc50i5kkms0mbbm5lc-pact-baac04e.drv':
         specified: sha256-jD4Y2NOSYT0EQHs5BRSVvu8asfvRwt5XLDuZwbcG4mk=
            got:    sha256-PmvS1kNvnOErMpfQPhGp4oOxuZLa34MEXt/Q1p09EKI=

In the past (with the old nix infra) we ran into issues where nix pins didn't exactly match the sources of the respective Hackage version and there was no easy way to detected that.

I can imagine how the old nix infra running on Zeus could perform misleading builds, picking the old source folder from the nix store due to the outdated hash, but I don't think that kind of inconsistency is possible with this new setup.

That's why I've removed the separate cabal.project checks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admittedly, the error message you get from the Nix build is not ideal because it doesn't tell you what exactly you need to do. So if somebody encounters this message out of the blue, it could be frustrating to try to debug it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a hint about how to read this error to the comment that describes how to compute the sha.

@jwiegley
Copy link
Collaborator Author

@larskuhtz This is intended to replace the previous infrastructure, yes. I'd like to remove the old files soon, but I will do that after giving this new stuff some time to settle in and get plugged into CI.

@enobayram enobayram merged commit 4443f71 into master Apr 28, 2023
@larskuhtz larskuhtz deleted the johnw/nix-flake branch April 28, 2023 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants