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: nix derivation #53

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
006dbd3
WIP: nix derivation
alexfmpe Aug 8, 2019
cfa3d6d
Expose overrides for compatibility with older nixpkgs/ghc
alexfmpe Aug 14, 2019
9632a93
Update gitignore
alexfmpe Aug 14, 2019
d244ffd
Expose all overrides
alexfmpe Aug 19, 2019
ba14e4a
Merge branch 'master' into nix-derivation
alexfmpe Aug 26, 2019
592de92
Merge branch 'master' into nix-derivation
alexfmpe Oct 10, 2019
035e22a
Specify hpack version
alexfmpe Oct 20, 2019
081ae25
Use upstream 'callHackageDirect'
alexfmpe Oct 20, 2019
f28509b
Fix indentation
alexfmpe Oct 21, 2019
2e408cc
Merge branch 'master' into nix-derivation
alexfmpe Nov 9, 2019
ec5ccb6
Bump nixpkgs
alexfmpe Nov 9, 2019
fb78557
Fix attribute
alexfmpe Nov 9, 2019
7e26dc9
Fix build
alexfmpe Nov 9, 2019
1148631
Merge branch 'master' into nix-derivation
alexfmpe Mar 27, 2020
7a1358e
Update
alexfmpe Apr 4, 2020
c126a21
Make things a bit less fragile
alexfmpe Apr 4, 2020
a0f0d48
Expose nixpkgs overlay
alexfmpe Apr 4, 2020
3140057
Cleanup
alexfmpe Apr 4, 2020
fa0a058
Don't ignore other overlays
alexfmpe Apr 4, 2020
d042c3a
Add iavl and tendermint to overlay
alexfmpe Apr 4, 2020
ba5500b
Add 'nix' directory
alexfmpe Apr 17, 2020
002a02c
Fix stack's nix integration
alexfmpe Apr 17, 2020
2a25c61
Rename file
alexfmpe Apr 17, 2020
d9cba01
Add nix dev shell
alexfmpe Apr 17, 2020
53c61d9
Hide gitignored files from nix
alexfmpe Apr 17, 2020
c72f169
Disable tests on darwin
alexfmpe May 10, 2020
e4960ae
Merge branch 'master' into nix-derivation
alexfmpe Jul 29, 2020
66ea593
Fix github fields
alexfmpe Jul 29, 2020
cd29735
Fix build
alexfmpe Aug 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ stack.yaml.lock
*~
.ci-bins/
*.dump-hi

# cabal
dist-newstyle

# nix
result*
result-*
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages:
*/*
2 changes: 1 addition & 1 deletion hs-abci-docs/nameservice/package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: nameservice
version: 0.1.0.0
github: "f-o-a-m/kepler/hs-abci-docs/nameservice"
# github: "f-o-a-m/kepler/hs-abci-docs/nameservice"
license: Apache
author: "Martin Allen"
maintainer: "martin@foam.space"
Expand Down
2 changes: 1 addition & 1 deletion hs-abci-docs/simple-storage/package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: simple-storage
version: 0.1.0.0
github: "f-o-a-m/kepler/hs-abci-docs/simple-storage"
# github: "f-o-a-m/kepler/hs-abci-docs/simple-storage"
license: Apache
author: Martin Allen
maintainer: "martin@foam.space"
Expand Down
2 changes: 1 addition & 1 deletion hs-abci-extra/package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: hs-abci-extra
version: 0.1.0.0
github: "https://github.com/f-o-a-m/kepler/hs-abci-server"
github: "f-o-a-m/kepler/hs-abci-extra"
license: Apache
author: "Martin Allen"
maintainer: "martin@foam.space"
Expand Down
2 changes: 1 addition & 1 deletion hs-abci-types/package.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: hs-abci-types
version: 0.1.0.0
github: "f-o-a-m/kepler//hs-abci-types"
github: "f-o-a-m/kepler/hs-abci-types"
license: Apache
author: "Martin Allen"
maintainer: "martin@foam.space"
Expand Down
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}: (import ./project.nix {}).keplerPackages
15 changes: 15 additions & 0 deletions nix/iavl.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ stdenv, fetchFromGitHub, buildGoModule }:

buildGoModule rec {
pname = "iavl";
version = "0.12.4";

src = fetchFromGitHub {
owner = "tendermint";
repo = pname;
rev = "de73d47fa87401bd935dffe3eca93ddaf0e3e105";
sha256 = "1phf9jacgh30n4vgm5grncmk1yn80x32l7gpnlbscimmizyhrdl5";
};

vendorSha256 = "1ra1v9x53f1rc9zsz42x0x5gqf7z5qccg71xp8prpjjzkzwh4cy1";
}
194 changes: 194 additions & 0 deletions nix/project.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
{ }:
let
pkgs = import (builtins.fetchTarball {
name = "master";
url = https://github.com/nixos/nixpkgs/archive/7fd5059f58dd5c50975579e2e87ca1294bbc845a.tar.gz;
sha256 = "0b4q30vrzmh40w3k37yzdiyl9fmh40qfjfa922mv9lfv1rmcbdrv";
}) { inherit overlays; };

gitignore = pkgs.fetchFromGitHub {
owner = "hercules-ci";
repo = "gitignore";
rev = "f9e996052b5af4032fe6150bba4a6fe4f7b9d698";
sha256 = "0jrh5ghisaqdd0vldbywags20m2cxpkbbk5jjjmwaw0gr8nhsafv";
};
gitignoreSource = (import gitignore {}).gitignoreSource;

iavl = pkgs.callPackage ./iavl.nix {};
tendermint = pkgs.callPackage ./tendermint.nix {};

root = ../.;

packages = {
hs-abci-extra = root + /hs-abci-extra;
hs-abci-sdk = root + /hs-abci-sdk;
hs-abci-server = root + /hs-abci-server;
hs-abci-test-utils = root + /hs-abci-test-utils;
hs-abci-types = root + /hs-abci-types;
hs-iavl-client = root + /hs-iavl-client;
hs-tendermint-client = root + /hs-tendermint-client;
nameservice = root + /hs-abci-docs/nameservice;
simple-storage = root + /hs-abci-docs/simple-storage;
};

repos = {
avl-auth = pkgs.fetchFromGitHub {
owner = "oscoin";
repo = "avl-auth";
rev = "dfc468845a82cdd7d759943b20853999bc026505";
sha256 = "005j98hmzzh9ybd8wb073i47nwvv1hfh844vv4kflba3m8d75d80";
};
http2-grpc-haskell = pkgs.fetchFromGitHub {
owner = "haskell-grpc-native";
repo = "http2-grpc-haskell";
rev = "496e92bc967eff02ac3698ba12ba2dfe38bc8b74";
sha256 = "199nz6dpqlzg9jyc0kq1har0l2zididpi2wkriai6cn91s7fc3my";
};
proto3-suite = pkgs.fetchFromGitHub {
owner = "awakesecurity";
repo = "proto3-suite";
rev = "45950a3860cbcb3f3177e9725dbdf460d6da9d45";
sha256 = "1fm0a5i9q9p393c9if6n6nz0q7di0p1fjx262fyj7j20nnl3f9i3";
};
proto3-wire = pkgs.fetchFromGitHub {
owner = "awakesecurity";
repo = "proto3-wire";
rev = "5df56fe1ad26a18b1dfbb2a5b8d35b4c1ad63f53";
sha256 = "1d2ir9ds4vawrn6lkxqgyw9zg8h2l4d6m8ihhy6znjllh12fmjyp";
};
};

repoPackages = {
inherit (repos) avl-auth proto3-suite proto3-wire;
};

extra-build-inputs = with pkgs; {
hs-abci-sdk = [protobuf];
hs-abci-types = [protobuf];
hs-iavl-client = [protobuf];
simple-storage = [protobuf];
};

addBuildInputs = inputs: { buildInputs ? [], ... }: { buildInputs = inputs ++ buildInputs; };

hackageOverrides = self: super: {
ghc-tcplugins-extra = self.callHackage "ghc-tcplugins-extra" "0.3.2" {};

http2-client = pkgs.haskell.lib.doJailbreak super.http2-client;
http2-client-grpc = self.callCabal2nix "http2-client-grpc" (repos.http2-grpc-haskell + /http2-client-grpc) {};
http2-grpc-proto-lens = self.callCabal2nix "http2-grpc-proto-lens" (repos.http2-grpc-haskell + /http2-grpc-proto-lens) {};

polysemy = self.callHackage "polysemy" "1.3.0.0" {};
polysemy-plugin = self.callHackage "polysemy-plugin" "0.2.5.0" {};
polysemy-zoo = self.callHackage "polysemy-zoo" "0.7.0.0" {};

prometheus = self.callHackageDirect {
pkg = "prometheus";
ver = "2.1.3";
sha256 = "04w3cm6r6dh284mg1lpzj4sl6d30ap3idkkdjzck3vcy5p788554";
} {};
};

localOverrides = self: super:
builtins.mapAttrs (name: path: (self.callCabal2nix name (gitignoreSource path) {})) packages;

repoOverrides = self: super:
builtins.mapAttrs (name: path: (self.callCabal2nix name path {})) repoPackages;

overrides = self: super:
let allOverrides =
hackageOverrides self super
// repoOverrides self super
// localOverrides self super;
in
builtins.mapAttrs (name: pkg: pkg.overrideAttrs (addBuildInputs (extra-build-inputs.${name} or []))) allOverrides;

# TODO: figure out why running tests on mac causes builds to hang _after_ running the tests
keplerTests = pkg: args: if pkgs.stdenv.isDarwin then pkgs.haskell.lib.dontCheck pkg else keplerTests' pkg args;

keplerTests' = pkg: { runIavl ? false, runABCI ? null, runTendermint ? null }: pkgs.lib.overrideDerivation pkg (drv:
let
iavlScript = ''
${iavl}/bin/iavlserver -db-name "test" -datadir "." -grpc-endpoint "0.0.0.0:8090" -gateway-endpoint "0.0.0.0:8091" &
sleep 3
'';
abciScript = ''
${runABCI} &
sleep 3
'';
tendermintScript = ''
${tendermint}/bin/tendermint init --home $TMPDIR
${tendermint}/bin/tendermint node --home $TMPDIR --proxy_app=${runTendermint} &
sleep 3
'';
in {
checkPhase = pkgs.lib.concatStrings [
(pkgs.lib.optionalString runIavl iavlScript)
(pkgs.lib.optionalString (runABCI != null) abciScript)
(pkgs.lib.optionalString (runTendermint != null) tendermintScript)
drv.checkPhase
];
});

overlay = self: super: {
inherit iavl tendermint;

haskellPackages =
super.haskellPackages.override (old: {
overrides = pkgs.lib.foldr pkgs.lib.composeExtensions (old.overrides or (_: _: {})) [
overrides
(self: super: with pkgs.haskell.lib; {
http2-client = unmarkBroken super.http2-client;
parameterized = dontCheck (unmarkBroken super.parameterized);

# https://github.com/NixOS/nixpkgs/pull/82562
secp256k1 = null;
secp256k1-haskell = addPkgconfigDepend (self.callHackage "secp256k1-haskell" "0.1.8" {}) pkgs.secp256k1;

avl-auth = dontCheck super.avl-auth; # https://github.com/haskell-haskey/xxhash-ffi/issues/2
bloodhound = doJailbreak (unmarkBroken super.bloodhound); # tight bounds
katip-elasticsearch = dontCheck (unmarkBroken super.katip-elasticsearch); # needs elastic-search for tests
proto3-suite = dontCheck super.proto3-suite; # needs old 'tasty'

hs-tendermint-client = dontCheck super.hs-tendermint-client; # last test fails frequently
hs-iavl-client = keplerTests super.hs-iavl-client { runIavl = true; };
hs-abci-sdk = keplerTests super.hs-abci-sdk { runIavl = true; };

simple-storage = keplerTests super.simple-storage {
runIavl = true;
runABCI = "IAVL_HOST=localhost IAVL_PORT=8090 dist/build/simple-storage/simple-storage";
runTendermint= "tcp://localhost:26658";
};

nameservice = dontCheck super.nameservice;
}
)
];
});
};

overlays = [overlay];

in rec {
inherit pkgs overlays;

buildInputs = {
inherit (pkgs) iavl protobuf tendermint;
inherit (pkgs.haskellPackages) cabal-install ghcid hlint stack stylish-haskell weeder;
};

keplerPackages = keplerPackages' pkgs.haskellPackages;
keplerPackages' = p: with p; {
inherit
hs-abci-extra
hs-abci-sdk
hs-abci-server
hs-abci-test-utils
hs-abci-types
hs-iavl-client
hs-tendermint-client
nameservice
simple-storage
;
};
}
7 changes: 7 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{}:
let project = (import ./project.nix {});
in project.pkgs.haskellPackages.shellFor {
withHoogle = true;
packages = p: builtins.attrValues (project.keplerPackages' p);
nativeBuildInputs = builtins.attrValues project.buildInputs;
}
7 changes: 7 additions & 0 deletions nix/stack.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ ghc }:
let project = import ./project.nix {};
in with project.pkgs; haskell.lib.buildStackProject {
inherit ghc;
name = "kepler";
buildInputs = [ git secp256k1 zlib ] ++ builtins.attrValues project.buildInputs;
}
15 changes: 15 additions & 0 deletions nix/tendermint.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ stdenv, fetchFromGitHub, buildGoModule }:

buildGoModule rec {
pname = "tendermint";
version = "0.32.8";

src = fetchFromGitHub {
owner = "tendermint";
repo = pname;
rev = "v${version}";
sha256 = "1bk9hb8whvlvxn8ijrp7rg6m83wxj4ipp5v36yr47ibqirbngh5s";
};

vendorSha256 = "1vhd3s6yxfhirgipxcy0rh8sk55cdzirr8n8r31sijgyak92mq0l";
}
14 changes: 0 additions & 14 deletions shell-stack.nix

This file was deleted.

2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resolver: lts-15.10

nix:
#enabled: bool # defaults to true on nixos, false everywhere else
shell-file: shell-stack.nix
shell-file: nix/stack.nix

packages:
- ./hs-abci-types
Expand Down