Skip to content

Commit 3ef9ce2

Browse files
sevanspowelldisassembler
authored andcommitted
initial pure nix build
1 parent e1c81f2 commit 3ef9ce2

20 files changed

+8639
-2
lines changed

build.sbt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
enablePlugins(JDKPackagerPlugin, JavaAppPackaging, SolidityPlugin)
22

3+
import scala.sys.process.Process
4+
5+
// Necessary for the nix build, please do not remove.
6+
val nixBuild = sys.props.isDefinedAt("nix")
7+
38
val commonSettings = Seq(
49
name := "mantis",
510
version := "3.0",
@@ -15,7 +20,7 @@ val dep = {
1520
val akkaHttpVersion = "10.1.1"
1621
val circeVersion = "0.9.3"
1722
val rocksDb = "5.9.2"
18-
23+
1924
Seq(
2025
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
2126
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
@@ -73,7 +78,8 @@ val Snappy = config("snappy") extend Test
7378

7479
val Rpc = config("rpcTest") extend Test
7580

76-
val root = project.in(file("."))
81+
val root = {
82+
val x = project.in(file("."))
7783
.configs(Integration, Benchmark, Evm, Ets, Snappy, Rpc)
7884
.settings(commonSettings: _*)
7985
.settings(
@@ -88,6 +94,12 @@ val root = project.in(file("."))
8894
.settings(inConfig(Snappy)(Defaults.testSettings) : _*)
8995
.settings(inConfig(Rpc)(Defaults.testSettings) : _*)
9096

97+
if (!nixBuild)
98+
x
99+
else
100+
x.settings(PB.runProtoc in Compile := (args => Process("protoc", args) !))
101+
}
102+
91103
scalacOptions := Seq(
92104
"-unchecked",
93105
"-deprecation",

default.nix

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{ system ? builtins.currentSystem, src ? ./.
2+
, pkgs ? (import ./nix { inherit system src; }).pkgs }:
3+
pkgs.mantis

manual-repo.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# this file must still be generated manually.
2+
{
3+
"repos" = {
4+
"nix-public" = "";
5+
"nix-typesafe-ivy-releases" = "[organisation]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]";
6+
};
7+
"artifacts" = {
8+
# dependencies so sbt can build the sbt-compiler-interface (http://www.scala-sbt.org/0.13/docs/Compiler-Interface.html)
9+
"nix-public/org/scala-lang/jline/2.10.6/jline-2.10.6.pom" = {
10+
url = "https://repo1.maven.org/maven2/org/scala-lang/jline/2.10.6/jline-2.10.6.pom";
11+
sha256 = "16mg4b2c1m6gcq901wy6f6jpy8spw2yh909gi826xykq89ja94dg";
12+
};
13+
"nix-public/org/scala-lang/jline/2.10.6/jline-2.10.6.jar" = {
14+
url = "https://repo1.maven.org/maven2/org/scala-lang/jline/2.10.6/jline-2.10.6.jar";
15+
sha256 = "1cfk6whncx2g87grwdfmz6f76bn807saqik91iwcfv099b1jngw1";
16+
};
17+
"nix-public/org/fusesource/jansi/jansi/1.4/jansi-1.4.pom" = {
18+
url = "https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.4/jansi-1.4.pom";
19+
sha256 = "0rgprkbg4ljarf0x79snk2h1b0974glhl2fw1bxkxbw8k3ifda1s";
20+
};
21+
"nix-public/org/fusesource/jansi/jansi/1.4/jansi-1.4.jar" = {
22+
url = "https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.4/jansi-1.4.jar";
23+
sha256 = "183ms545msn02fl0181rwbcifc8qy82rz4l6dglnhv9la8a1bnc2";
24+
};
25+
};
26+
}

nix/default.nix

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{ system ? builtins.currentSystem, sources ? import ./sources.nix, src ? ../. }:
2+
3+
let
4+
overlay = final: prev: {
5+
inherit sources;
6+
inherit (import sources.gitignore { inherit (prev) lib; }) gitignoreSource;
7+
8+
sbtix = prev.callPackage ../sbtix.nix {
9+
jdk = prev.openjdk8_headless;
10+
jre = prev.openjdk8_headless.jre;
11+
};
12+
13+
mantisPkgs = final.callPackage ./pkgs/mantis {
14+
inherit (prev.openjdk8_headless) jre;
15+
inherit src;
16+
};
17+
18+
inherit (final.mantisPkgs) mantis;
19+
20+
inherit (final.mantisPkgs) mantis-unwrapped;
21+
};
22+
in import sources.nixpkgs {
23+
inherit system;
24+
overlays = [ overlay ];
25+
}

nix/pkgs/default.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{ pkgs, lib, newScope, sources, src, impure ? false }:
2+
3+
lib.makeScope newScope (self:
4+
with self;
5+
let callPackages = lib.callPackagesWith (pkgs // self);
6+
in {
7+
inherit sources src impure;
8+
jdk = prev.openjdk8_headless;
9+
libsonic = callPackage ./libsonic.nix { };
10+
libsonic-jnr = callPackage sources.libsonic-jnr { };
11+
netty-native-epoll = callPackage ./netty-native-epoll { };
12+
progpow-cpu-scala = callPackage sources.progpow-cpu-scala { };
13+
})

nix/pkgs/libsonic.nix

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{ rustPlatform, sources }:
2+
3+
rustPlatform.buildRustPackage {
4+
name = "libsonic";
5+
src = sources.libsonic;
6+
doCheck = false;
7+
cargoSha256 = "sha256:0zhbzr3amwmdqbrmj355ryl5fsmmw85h8ksaggcqwp66zmv57aq4";
8+
9+
preConfigure = ''
10+
substituteInPlace libsonic/Cargo.toml \
11+
--replace 'crate-type = ["staticlib"]' 'crate-type = ["cdylib"]'
12+
'';
13+
}

nix/pkgs/mantis/default.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{ src, lib, gitignoreSource, callPackage, jre }: rec {
2+
3+
mkSrc = src:
4+
let
5+
isGit = builtins.pathExists (src + "/.git");
6+
repo = builtins.fetchGit { url = src; submodules = true; };
7+
dirty = repo.revCount == 0;
8+
filterSrc = src:
9+
lib.cleanSourceWith {
10+
inherit src;
11+
filter = path: _: !lib.hasSuffix "nix" path;
12+
};
13+
in if isGit then
14+
if dirty then filterSrc (gitignoreSource src) else repo
15+
else
16+
src;
17+
18+
mantis-source = src;
19+
20+
mantis-unwrapped = callPackage ./unwrapped.nix { src = mantis-source; };
21+
22+
mantis = callPackage ./wrapped.nix {
23+
mantis = mantis-unwrapped;
24+
inherit jre;
25+
};
26+
}

nix/pkgs/mantis/unwrapped.nix

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# this file originates from SBTix
2+
{ src, stdenv, writeShellScriptBin, bash, protobuf, sbtix
3+
, solc, jdk, impure ? false }:
4+
5+
let
6+
inherit (stdenv.lib) optionalString makeLibraryPath;
7+
inherit (stdenv) cc isDarwin;
8+
9+
LD_LIBRARY_PATH = makeLibraryPath [ cc.cc.lib ];
10+
11+
unlessDarwin = optionalString (!stdenv.isDarwin);
12+
13+
# sbt-protoc puts the scala plugin in /tmp/protobridge<some-random-number>.
14+
# it is in fact a shell script with a standard `#!/usr/bin/env sh` shebang
15+
# that makes the Nix sandbox ANGRY and breaks all the things in a cryptic,
16+
# hairpull-inducing way. So we gotta sed it out. Not the prettiest thing
17+
# but it works.
18+
protoc-wrapper = writeShellScriptBin "protoc" ''
19+
set -e
20+
21+
for f in "$@"; do
22+
echo ''${f##*=}
23+
done | grep protocbridge | xargs sed -i "1s|.*|#!${bash}/bin/bash|"
24+
25+
exec ${protobuf}/bin/protoc "$@"
26+
'';
27+
28+
in sbtix.buildSbtProject {
29+
inherit src;
30+
31+
name = "mantis";
32+
sbtOptions = "-Dnix=true";
33+
buildInputs = [ protoc-wrapper ];
34+
sbtixBuildInputs = [];
35+
36+
repo = [
37+
(import ../../../repo.nix)
38+
(import ../../../project/repo.nix)
39+
(import ../../../manual-repo.nix)
40+
];
41+
42+
buildPhase = ''
43+
set -x
44+
pwd && sbt compile
45+
'';
46+
47+
installPhase = ''
48+
sbt stage
49+
mkdir -p $out/
50+
cp wallet-backend/target/universal/stage/* $out/ -r
51+
cp node/target/universal/stage/* $out/ -r
52+
mkdir -p $out/share/mantis
53+
mv $out/{LICENSE,RELEASE,mantis_config.txt} $_
54+
55+
${optionalString (!impure) ''
56+
for p in $(find $out/bin/* -executable); do
57+
wrapProgram "$p" \
58+
--prefix PATH : ${jdk}/bin ${
59+
unlessDarwin "--prefix LD_LIBRARY_PATH : ${LD_LIBRARY_PATH}"
60+
}
61+
done
62+
''}
63+
'';
64+
65+
dontPatchShebangs = impure;
66+
}

nix/pkgs/mantis/wrapped.nix

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{ lib, stdenv, mantis, makeWrapper, jre, gawk }:
2+
let
3+
inherit (stdenv.lib) optionalString makeLibraryPath;
4+
inherit (stdenv) cc isDarwin;
5+
LD_LIBRARY_PATH = makeLibraryPath [ cc.cc.lib ];
6+
PATH = lib.makeBinPath [ jre gawk ];
7+
in stdenv.mkDerivation {
8+
pname = "mantis";
9+
version = let
10+
buildSbt = builtins.readFile ../../../build.sbt;
11+
captures = builtins.match ''.*version := "([^"]+)".*'' buildSbt;
12+
in builtins.elemAt captures 0;
13+
14+
nativeBuildInputs = [ makeWrapper ];
15+
16+
src = mantis;
17+
18+
buildPhase = ":";
19+
20+
installPhase = ''
21+
cp -r $src $out
22+
chmod -R u+rw $out
23+
24+
for p in $(find $out/bin/* -executable); do
25+
wrapProgram "$p" \
26+
--prefix PATH : ${PATH} \
27+
${
28+
optionalString (!isDarwin)
29+
"--prefix LD_LIBRARY_PATH : ${LD_LIBRARY_PATH}"
30+
}
31+
done
32+
'';
33+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# How to bump the netty-transport-epoll version:
2+
# 1. Update the netty niv pin.
3+
# 2. nix-shell, then cd in this dir, then run mvnix-update to update
4+
# the `mavenix.lock` lock file.
5+
6+
{ sources, lib, autoconf, automake, git, gnumake, gnutar, jdk, libaio, libtool
7+
, makeWrapper, maven, mavenix, unzip }:
8+
mavenix.buildMaven {
9+
src = sources.netty;
10+
doCheck = false;
11+
infoFile = ./mavenix.lock;
12+
13+
MAVEN_OPTS = "-DskipTests";
14+
15+
# Adding some build dependencies.
16+
# Netty-transport-epoll requires both the autotool suite and the JDK
17+
buildInputs = [
18+
git
19+
makeWrapper
20+
autoconf
21+
automake
22+
libtool
23+
gnumake
24+
gnutar
25+
libaio
26+
jdk
27+
maven
28+
];
29+
# Attributes are passed to the underlying `stdenv.mkDerivation`, so build
30+
# hooks can be set here also.
31+
#
32+
postInstall = ''
33+
libName="libnetty_transport_native_epoll_x86_64.so"
34+
mkdir -p $out/lib
35+
${unzip}/bin/unzip $out/share/java/netty-transport-native-epoll-*-linux-x86_64.jar META-INF/native/libnetty_transport_native_epoll_x86_64.so -d .
36+
cp META-INF/native/libnetty_transport_native_epoll_x86_64.so $out/lib/$libName
37+
chmod 777 $out/lib/$libName
38+
'';
39+
40+
meta.platforms = lib.platforms.linux;
41+
42+
# Add extra maven dependencies which might not have been picked up
43+
# automatically
44+
#
45+
#deps = [
46+
# { path = "org/group-id/artifactId/version/file.jar"; sha1 = "0123456789abcdef"; }
47+
# { path = "org/group-id/artifactId/version/file.pom"; sha1 = "123456789abcdef0"; }
48+
#];
49+
50+
# Add dependencies on other mavenix derivations
51+
#
52+
#drvs = [ (import ../other/mavenix/derivation {}) ];
53+
54+
# Override which maven package to build with
55+
#
56+
#maven = maven.overrideAttrs (_: { jdk = pkgs.oraclejdk10; });
57+
58+
# Override remote repository URLs and settings.xml
59+
#
60+
#remotes = { central = "https://repo.maven.apache.org/maven2"; };
61+
#settings = ./settings.xml;
62+
}

0 commit comments

Comments
 (0)