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

[WIP] chore(packaging): use nix flakes for building graphql-engine reproducibly #9160

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

thenonameguy
Copy link

@thenonameguy thenonameguy commented Oct 31, 2022

@SamirTalwar I saw your work on adding the scaffolding for the development environment and decided to add Nix for building aarch64-darwin binaries out of graphql-engine. This project is a WIP branch that does everything without much regard to existing practices/best conventions to do a POC for Nix + Hasura => M1 native gql-engine.

Description

Changelog

Component : build

Type: enhancement

Product: community-edition

Short Changelog

Allow building reproducibly graphql-engine via Nix

Long Changelog

Related Issues

Solution and Design

Steps to test and verify

Limitations, known bugs & workarounds

Server checklist

Catalog upgrade

Does this PR change Hasura Catalog version?

  • No
  • Yes
    • Updated docs with SQL for downgrading the catalog

Metadata

Does this PR add a new Metadata feature?

  • No
  • Yes
    • Does run_sql auto manages the new metadata through schema diffing?
      • Yes
      • Not required
    • Does run_sql auto manages the definitions of metadata on renaming?
      • Yes
      • Not required
    • Does export_metadata/replace_metadata supports the new metadata added?
      • Yes
      • Not required

GraphQL

  • No new GraphQL schema is generated
  • New GraphQL schema is being generated:
    • New types and typenames are correlated

Breaking changes

  • No Breaking changes

  • There are breaking changes:

    1. Metadata API

      Existing query types:

      • Modify args payload which is not backward compatible
      • Behavioural change of the API
      • Change in response JSON schema
      • Change in error code
    2. GraphQL API

      Schema Generation:

      • Change in any NamedType
      • Change in table field names

      Schema Resolve:-

      • Change in treatment of null value for any input fields
    3. Logging

      • Log JSON schema has changed
      • Log type names have changed

@hasura-bot
Copy link
Contributor

Beep boop! 🤖

Hey @thenonameguy, thanks for your PR!

One of my human friends will review this PR and get back to you as soon as possible.

Stay awesome! 😎

@CLAassistant
Copy link

CLAassistant commented Oct 31, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@SamirTalwar SamirTalwar left a comment

Choose a reason for hiding this comment

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

Looks like an awesome start. I've left a few comments. Can I help with anything?

resource-pool = hself.hasura-resource-pool;
})));

# FIXME: for remote repos we have to calculate their default.nix until they get upstreamed/maintained
Copy link
Contributor

Choose a reason for hiding this comment

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

These seem legit. I suggest moving the actual fetches into the inputs in flake.nix though, so they're pinned with flake.lock. (You can still specify the exact commit ref.)

Copy link
Author

Choose a reason for hiding this comment

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

Yup, that's the plan. I need to do this anyway to not use IFDs.

@@ -0,0 +1 @@
2.14.0-beta.2
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't check this in. For some reason, this is missing from the .gitignore file; I am remedying this.

For local development, you can write "12345" to this file.

Copy link
Author

Choose a reason for hiding this comment

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

  1. Flake builds can only use files that are tracked in version control (as the build depends on this not-deterministic file)
  2. I thought the version was used to fetch the CDN FE assets for the Console, is this not correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

Apologies, I thought I'd replied to your comments.

I suggest adding a preConfigure step that writes the file with the contents of the package version then.

@@ -0,0 +1,112 @@
{ mkDerivation, aeson, aeson-casing, aeson-ordered, aeson-pretty
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to use callCabal2nix for these?

If it's just for the version, you can override that later. I think this will work:

(callCabal2nix "graphql-engine" ./server {}).overrideAttrs(oldAttrs: {
  version = builtins.readFile ./server/CURRENT_VERSION;
})

Copy link
Author

Choose a reason for hiding this comment

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

callCabal2nix is an anti-pattern in the flake/nixpkgs world, as it creates evaluations at runtime.
The computation of these files, while being more convenient, are done at eval time.
https://github.com/input-output-hk/haskell.nix uses this approach extensively, I tried using that on a different branch in the past days and the IFD-less version of this branch is way more snappier to eval/build with.
IMO for now it's worth to do this outside of Nix evalution, maybe automate it with a Makefile/CI script.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Very helpful, thank you!

We'd need to add some CI to make sure this stays in sync with however it's generated, as well as include instructions on how to redo it.

Copy link

@srid srid Oct 25, 2023

Choose a reason for hiding this comment

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

We'd need to add some CI to make sure this stays in sync with however it's generated, as well as include instructions on how to redo it.

You can include a pre-commit hook that runs cabal2nix.

Note that devs don't have to install the hooks themselves, but only have to run pre-commit run after staging the changes. Else, nix flake check should be expected to fail.

cf. srid/haskell-flake#144 (comment)

@@ -158,7 +158,8 @@ flag ghci-load-test-with-lib
common common-all
ghc-options:
-foptimal-applicative-do
-Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints
-Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns
-- -Wredundant-constraints
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you have to remove this? Did you get extra warnings?

Copy link
Author

Choose a reason for hiding this comment

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

Yes, got a lot of compilation errors for redundant-constrains and typed holes, which I found strange. Temporary fix to get a build.

@@ -293,6 +294,7 @@ common lib-depends
, some
, split
, template-haskell
, ghc-heap-view
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this change is just for testing.

Copy link
Author

Choose a reason for hiding this comment

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

your CPP module was essentially upstreamed into the latest ghc-heap-view version. The surrounding code failed to compile until these changes were made. Of course the runtime dependency for this should be made optional, but Nix did not seem to find it using the conditional profiling include.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jberryman: Do you think we can upgrade ghc-heap-view to take advantage of this?

@thenonameguy
Copy link
Author

thenonameguy commented Oct 31, 2022

Looks like an awesome start. I've left a few comments. Can I help with anything?

Thanks! Currently:

For my personal purposes getting the aarch64-darwin building would be an end-goal for now.
Then we could work backwards, removing the need for IFDs, removing compilation errors from the Nix build, that don't happen in the shell cabal build scenarios, and get this mainlined if the Hasura team agrees.

@SamirTalwar
Copy link
Contributor

We saw those same linking issues trying to build Ormolu with Nix, which was fixed by disabling the Template Haskell.

My guess is that it's similar here; the Template Haskell is causing serious problems somewhere. I'm not sure what to do about it, unfortunately. It definitely feels like an upstream bug, but I don't even know where. Is it with the version of ld shipped with nixpkgs on macOS/aarch64, or somewhere else?

What do you propose we do about it?

@domenkozar
Copy link

This would be so nice to have, I'd like to support Hasura in devenv.sh: cachix/devenv#308

@SamirTalwar
Copy link
Contributor

@domenkozar, I take it your main motivation is Linux support, not macOS?

If we were to reorient this PR to just care about Linux, it might be easier to get it in.

@domenkozar
Copy link

Linux and macOS, I'm happy to help here if I can understand what are the blockers.

@SamirTalwar
Copy link
Contributor

The main macOS blocker is that ld chokes on HGE. The error is the same as NixOS/nixpkgs#149692.

We would also need to clean this PR up a bit, but it's mostly small things; @thenonameguy has done a wonderful job.

@thenonameguy
Copy link
Author

Cheers, FYI at my company have been using this branch + Cachix binary cache for our local Hasura development ever since without hiccups. I propose you take over the necessary bits and pieces over to a new branch as I do not have the time for foreseeable future to improve this further.

Super stoked to see this initiative going forward!

@SamirTalwar
Copy link
Contributor

Thanks @thenonameguy, glad it's working well at your end. We'll do our best to incorporate it.

@john-rodewald
Copy link

john-rodewald commented Jun 13, 2023

I picked up where @thenonameguy left off, transformed my fork into a monstrosity of patches that I don't really want anyone to see, and eventually managed to build on aarch64-darwin with Nix. That means I can ditch Docker now. I'm not sure when or if I'll have time to clean it up, but it runs and may be helpful to someone looking into this PR.

https://github.com/john-rodewald/graphql-engine/tree/master-nix

aeson base graphql-parser hashable hspec text unordered-containers
vector
];
homepage = "https://github.com/hasura/github-engine#readme";

Choose a reason for hiding this comment

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

s/github-engine/graphql-engine/ ?

@the-sun-will-rise-tomorrow

@john-rodewald FYI, nix run github:john-rodewald/graphql-engine/master-nix now fails with error: Package ‘openapi3-3.2.3’ in /nix/store/qmyflblrsa4qikr5q54cfk0hxqx2a5p6-source/pkgs/development/haskell-modules/hackage-packages.nix:213450 is marked as broken, refusing to evaluate..

@the-sun-will-rise-tomorrow

The main macOS blocker is that ld chokes on HGE. The error is the same as NixOS/nixpkgs#149692.

It looks like that problem may have been fixed since then.

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.

8 participants