Skip to content

Commit

Permalink
Fix and modernize nix builds to flake.nix + haskell.nix (#29)
Browse files Browse the repository at this point in the history
This PR updates the nix build infrastructure to use flakes and haskell.nix through our new `hs-nix-infra` flake and converts default.nix to be a wrapper around the new `flake.nix`.

* Add a flake.nix that builds with haskell.nix

* Add sha256 to deeproute  source-repository-package

* Fix compiler-nix-name

* Set uppoer bound on aeson

Otherwise the build fails with:

[ 1 of 16] Compiling JsonRpc          ( src/JsonRpc.hs, dist/build/chainweb-mining-client/chainweb-mining-client-tmp/JsonRpc.o, dist/build/chainweb-mining-client/chainweb-mining-client-tmp/JsonRpc.dyn_o )

src/JsonRpc.hs:162:22: error:
    • Expecting one more argument to ‘A.KeyValue kv’
      Expected a constraint,
        but ‘A.KeyValue kv’ has kind ‘* -> Constraint’
    • In the type signature:
        requestProperties :: A.KeyValue kv =>
                             A.ToJSON a => T.Text -> a -> Maybe MsgId -> [kv]
    |
162 | requestProperties :: A.KeyValue kv => A.ToJSON a => T.Text -> a -> Maybe MsgId -> [kv]
    |                      ^^^^^^^^^^^^^

* Convert default.nix as legacy wrapper for flake.nix

* Switch to hs-nix-infra for pinning Haskell toolchain

* Add Nix build and cache action

* Add a recursive output

* Build recursive.allDerivations in CI

* Update setup-nix-with-cache

* Configure Nix with recursive-nix

* Switch back to hs-nix-infra/main

* Bump hs-nix-infra

* Turn default.nix into a function

In order to maintain backwards compatibility with old consumers
  • Loading branch information
enobayram authored Nov 17, 2023
1 parent ffa1266 commit bdd2c73
Show file tree
Hide file tree
Showing 6 changed files with 421 additions and 49 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/nix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build and cache with Nix

on:
workflow_dispatch:
push:
paths:
- '**'
- '!.github/**'
- '.github/workflows/nix.yml'

jobs:
build-and-cache:
runs-on: ${{ matrix.os }}
timeout-minutes: 740
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, macos-m1]
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Nix with caching
uses: kadena-io/setup-nix-with-cache/[email protected]
with:
cache_url: s3://nixcache.chainweb.com?region=us-east-1
signing_private_key: ${{ secrets.NIX_CACHE_PRIVATE_KEY }}
additional_experimental_features: recursive-nix

- name: Set up AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.NIX_CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.NIX_CACHE_AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Give root user AWS credentials
uses: kadena-io/setup-nix-with-cache/[email protected]

- name: Build and cache artifacts
run: |
echo Building the project and its devShell
nix build --log-lines 500 --show-trace
echo Build the recursive output
nix build .#recursive.allDerivations --accept-flake-config --log-lines 500 --show-trace
3 changes: 2 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ allow-newer:
source-repository-package
type: git
location: https://github.com/kadena-io/deeproute.git
tag: 856be917bf162a769d9082c26700af4bdbb87d49
tag: 856be917bf162a769d9082c26700af4bdbb87d49
--sha256: sha256-FHLl0gkwr+rtu42XBdVRD9k3bnhYl01GZAE0lz0V8wI=
2 changes: 1 addition & 1 deletion chainweb-mining-client.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ executable chainweb-mining-client
attoparsec >=0.14
, base >=4.10 && <5
, base16-bytestring >=1.0
, aeson >=1.5
, aeson >=1.5 && <2
, async >=2.2
, bytes >=0.17
, bytestring >=0.10
Expand Down
56 changes: 9 additions & 47 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,48 +1,10 @@
{ compiler ? "ghc8107"
, rev ? "7a94fcdda304d143f9a40006c033d7e190311b54"
, sha256 ? "0d643wp3l77hv2pmg2fi7vyxn4rwy0iyr8djcw1h5x72315ck9ik"
, pkgs ?
import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
inherit sha256; }) {
config.allowBroken = false; # autodocodec
config.allowUnfree = true;
}
, mkDerivation ? null
{
... # Maintain backwards compatibility with old consumers
}:
let gitignoreSrc = import (pkgs.fetchFromGitHub {
owner = "hercules-ci";
repo = "gitignore";
rev = "9e80c4d83026fa6548bc53b1a6fab8549a6991f6";
sha256 = "04n9chlpbifgc5pa3zx6ff3rji9am6msrbn1z3x1iinjz2xjfp4p";
}) {};
in
pkgs.haskell.packages.${compiler}.developPackage {
name = builtins.baseNameOf ./.;
root = gitignoreSrc.gitignoreSource ./.;

overrides = self: super: with pkgs.haskell.lib; {
configuration-tools = self.callHackageDirect {
pkg = "configuration-tools";
ver = "0.6.1";
sha256 = "0vrml1gj6bb5f6x79m80k9wqn5qvjjzz8c6gf36mqwdqv30irxdv";
} {};

streaming-events = doJailbreak (self.callHackageDirect {
pkg = "streaming-events";
ver = "1.0.1";
sha256 = "11v9rrhvlxlq43m5pw63hdfn6n0fkqryphvplild1y920db96wk9";
} {});

autodocodec = markUnbroken super.autodocodec;
validity-aeson = markUnbroken super.validity-aeson;
};
source-overrides = {
};
modifier = drv: pkgs.haskell.lib.overrideCabal drv (attrs: {
buildTools = (attrs.buildTools or []) ++ [
pkgs.haskell.packages.${compiler}.cabal-install
pkgs.haskell.packages.${compiler}.ghcid
];
});
}
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/12c64ca55c1014cdc1b16ed5a804aa8576601ff2.tar.gz";
sha256 = "0jm6nzb83wa6ai17ly9fzpqc40wg1viib8klq8lby54agpl213w5"; }
) {
src = ./.;
}).defaultNix.packages.${builtins.currentSystem}.default
Loading

0 comments on commit bdd2c73

Please sign in to comment.