-
Notifications
You must be signed in to change notification settings - Fork 95
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
Migrate to hs-nix-infra for the Nix setup #1778
Conversation
This commit exposes the pact input of chainweb at the Nix layer: * Allows the pact input to be overriden as a flake input * Exposes the pact package (with the CLI) of the Haskell package set
The customizable nix-conf features are now in it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat, build times reduced (within and downstream from this repo). Workflow changes are documented.
flake.nix
Outdated
haskellNix = { | ||
url = "github:input-output-hk/haskell.nix"; | ||
hs-nix-infra = { | ||
url = "github:kadena-io/hs-nix-infra/enis/metadata-experiments"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We intend to follow the main
branch at this repo, yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jwiegley, that's correct, I'm just experimenting with a few approaches for now.
Trying to expose the `src` of the pact input by caching it as a nix store path proved to be fragile. It's possible to output such paths from recursive-nix derivations, but those paths will be very tricky to access by downstream Nix expressions. This commit instead uses pure metadata to reconstruct the pact src definition at the recursive layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great, thanks!
This PR does the following:
Unify the GHC derivation used across Kadena projects
Instead of depending on
nixpkgs
andhaskellNix
directly, this flake now depends on our newhs-nix-infra
flake and uses thenixpkgs
andhaskellNix
revisions provided by it. The hash of thenixpkgs
andhaskellNix
flakes used for defining thehaskell.nix
project
determines the hash of the GHC package that gets used to compile the Haskell modules.When multiple projects depend on
nixpkgs
andhaskellNix
independently, it's very hard (and not really well supported by nix CLI) to make sure that they don't deviate from each others'nixpkgs
andhaskellNix
pins arbitrarily. I.e. updating two projects'flake.lock
files at slightly different times is likely to cause one of the pins to be on a different revision, even though the difference doesn't matter functionally.These unnecessarily different GHC packages put a lot of pressure on our CI infrastructure, taking hours to build functionally equivalent GHC packages and bloating the cache (with binaries from all the architectures we build and cache for). That also bloats the
/nix/store
of anychainweb
user that wants tonix build
an uncachedchainweb
version.The new workflow for updating Haskell-Nix toolchain
After this PR, the new workflow for managing our Haskell dependencies used by Nix will involve the following steps:
hackage
pin so that we can build with newly released Haskell packages, we can justnix flake lock --update-input hackage
similar to how we've been doing so far, because this PR keeps declaringhackage
as an input to thechainweb-node
flake. This means thehackage
flake pin can deviate between multiple projects, but that's relatively OK, since thehackage
pin doesn't influence the GHC package. The only bloat caused by such deviation is the need to download thehackage
repository, which is inconvenient, but worthwhile in exchange for the convenience of easily bumping the hackage pin.nixpkgs
version or if we need to bump ourhaskellNix
pin for any reason, then unlike the status quo, we need to follow a two-step process:hs-nix-infra
has a newer version, bump it in this repo and see if that fixes the build.hs-nix-infra
version isn't good enough, then open a PR tohs-nix-infra
to bumpnixpkgs
andhaskellNix
. The PR would preferably bump both of them to the latest version.Hopefully, this new workflow will reduce the number of
nixpkgs
+haskellNix
versions we depend on across our Haskell projects.Add a
recursive
alternative to thedefault
packageAs part of the CI automation for this repo, we're building and caching the Nix binaries for
chainweb
, which makes it convenient for any user tonix build
chainweb from any commit/branch since all the dependencies will come from our binary cache. However, even without building anything locally, evaluating thedefault
package of this flake takes a significant amount of time and involves downloading ~2 GB of Nix dependencies. This is due to the complexity of whathaskellNix
does for us at Nix evaluation time.This PR introduces a
recursive
package to this flake's output, which usesrecursive-nix
to push the Nix evaluation of thedefault
package into the build of a derivation. This means, any user that tries tonix build .#recursive
will fetch the chainweb binary from our cache without having to perform any complex Nix evaluation locally or downloading the Nix dependencies of any such evaluation as long as therecursive
derivation they're building is already in our binary cache. If not, therecursive-nix
derivation will be built locally (in which case make sure your local Nix setup hasrecursive-nix
enabled), which is essentially as much work as buildingdefault
itself. This might still be worthwhile however, since subsequent builds of the samerecursive
derivation will complete immediately, without having to evaluate thedefault
derivation again.Expose
pact
as an attribute of output derivationThe
default
package and therecursive
package now both have apact
attribute containing the version of thepact
that gets compiled in as well as itssrc
. This allows downstream consumers of these packages to access the version and the source of thepact
package embedded into thechainweb
binary they're building.Allow overriding the pact source
This PR adds a
pact
input to the flake, which defaults to anempty
flake, standing in for anull
, meaning that thepact
source pinned from thecabal.project
should be used. When thepact
input is overridden, via--override-input
or as part of a downstream flake,chainweb
will be built by the providedpact
version. This overriding mechanism is also exposed via the functions in thelib
output for cases when the choice ofpact
source is made outside the resolution of flake inputs.