Skip to content

Commit 821e35a

Browse files
disassemblermanveru
authored andcommitted
initial nix build
1 parent bb0d7d3 commit 821e35a

20 files changed

+7130
-9
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ project/plugins/project/
1616
*.log
1717
*.log.zip
1818
.evm-runner_history
19+
20+
# Nix
21+
result

build.sbt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
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(
4-
name := "mantis",
9+
name := "mantis-core",
510
version := "3.0",
611
scalaVersion := "2.12.10",
712
testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-l", "EthashMinerSpec") // miner tests disabled by default
@@ -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,
@@ -72,7 +77,8 @@ val Snappy = config("snappy") extend Test
7277

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

75-
val root = project.in(file("."))
80+
val root = {
81+
val root = project.in(file("."))
7682
.configs(Integration, Benchmark, Evm, Ets, Snappy, Rpc)
7783
.settings(commonSettings: _*)
7884
.settings(
@@ -87,6 +93,12 @@ val root = project.in(file("."))
8793
.settings(inConfig(Snappy)(Defaults.testSettings) : _*)
8894
.settings(inConfig(Rpc)(Defaults.testSettings) : _*)
8995

96+
if (!nixBuild)
97+
root
98+
else
99+
root.settings(PB.runProtoc in Compile := (args => Process("protoc", args) !))
100+
}
101+
90102
scalacOptions := Seq(
91103
"-unchecked",
92104
"-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
})

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 = mkSrc 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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# this file originates from SBTix
2+
{ src, stdenv, writeShellScriptBin, bash, protobuf, sbtix
3+
, 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+
installPhase = ''
43+
sbt stage
44+
mkdir -p $out/
45+
cp target/universal/stage/* $out/ -r
46+
mkdir -p $out/share/mantis
47+
mv $out/{LICENSE,RELEASE,mantis_config.txt} $_
48+
'';
49+
50+
dontPatchShebangs = impure;
51+
}

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+
}

nix/sources.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"Sbtix": {
3+
"branch": "master",
4+
"description": "Generates Nix definitions for your SBT builds",
5+
"homepage": null,
6+
"owner": "input-output-hk",
7+
"repo": "Sbtix",
8+
"rev": "7b969a5641fce10500ca51cbe88af4ea160d7064",
9+
"sha256": "19pg7rm36b0v9y3ibq5cwsq38pwj3xw3d8srv78svmpnrzm1dh9g",
10+
"type": "tarball",
11+
"url": "https://github.com/input-output-hk/Sbtix/archive/7b969a5641fce10500ca51cbe88af4ea160d7064.tar.gz",
12+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13+
},
14+
"gitignore": {
15+
"branch": "master",
16+
"description": "Nix function for filtering local git sources",
17+
"homepage": "",
18+
"owner": "hercules-ci",
19+
"repo": "gitignore",
20+
"rev": "ec5dd0536a5e4c3a99c797b86180f7261197c124",
21+
"sha256": "0k2r8y21rn4kr5dmddd3906x0733fs3bb8hzfpabkdav3wcy3klv",
22+
"type": "tarball",
23+
"url": "https://github.com/hercules-ci/gitignore/archive/ec5dd0536a5e4c3a99c797b86180f7261197c124.tar.gz",
24+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
25+
},
26+
"niv": {
27+
"branch": "master",
28+
"description": "Easy dependency management for Nix projects",
29+
"homepage": "https://github.com/nmattia/niv",
30+
"owner": "nmattia",
31+
"repo": "niv",
32+
"rev": "f73bf8d584148677b01859677a63191c31911eae",
33+
"sha256": "0jlmrx633jvqrqlyhlzpvdrnim128gc81q5psz2lpp2af8p8q9qs",
34+
"type": "tarball",
35+
"url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz",
36+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
37+
},
38+
"nixpkgs": {
39+
"branch": "nixos-20.03",
40+
"description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels",
41+
"homepage": null,
42+
"owner": "NixOS",
43+
"repo": "nixpkgs-channels",
44+
"rev": "e2bb73ce5f786b83e984b80199112f86b8a6cc9d",
45+
"sha256": "0mpcdwhippvgsj3kj8vw35dgz94dnzgxgsfqqzcfpmvnzjc23vk7",
46+
"type": "tarball",
47+
"url": "https://github.com/NixOS/nixpkgs-channels/archive/e2bb73ce5f786b83e984b80199112f86b8a6cc9d.tar.gz",
48+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
49+
}
50+
}

0 commit comments

Comments
 (0)