Skip to content

[Chore] Add nix build #661

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

Merged
merged 8 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ project/plugins/project/
*.log
*.log.zip
.evm-runner_history

# Nix
result
41 changes: 26 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
enablePlugins(JDKPackagerPlugin, JavaAppPackaging, SolidityPlugin)

import scala.sys.process.Process

// Necessary for the nix build, please do not remove.
val nixBuild = sys.props.isDefinedAt("nix")

val commonSettings = Seq(
name := "mantis",
name := "mantis-core",
version := "3.0",
scalaVersion := "2.12.12",
testOptions in Test += Tests
Expand Down Expand Up @@ -77,20 +82,26 @@ val Snappy = config("snappy") extend Test

val Rpc = config("rpcTest") extend Test

val root = project
.in(file("."))
.configs(Integration, Benchmark, Evm, Ets, Snappy, Rpc)
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= dep,
executableScriptName := name.value
)
.settings(inConfig(Integration)(Defaults.testSettings): _*)
.settings(inConfig(Benchmark)(Defaults.testSettings): _*)
.settings(inConfig(Evm)(Defaults.testSettings): _*)
.settings(inConfig(Ets)(Defaults.testSettings): _*)
.settings(inConfig(Snappy)(Defaults.testSettings): _*)
.settings(inConfig(Rpc)(Defaults.testSettings): _*)
val root = {
val root = project.in(file("."))
.configs(Integration, Benchmark, Evm, Ets, Snappy, Rpc)
.settings(commonSettings: _*)
.settings(
libraryDependencies ++= dep,
executableScriptName := name.value
)
.settings(inConfig(Integration)(Defaults.testSettings) : _*)
.settings(inConfig(Benchmark)(Defaults.testSettings) : _*)
.settings(inConfig(Evm)(Defaults.testSettings) : _*)
.settings(inConfig(Ets)(Defaults.testSettings) : _*)
.settings(inConfig(Snappy)(Defaults.testSettings) : _*)
.settings(inConfig(Rpc)(Defaults.testSettings) : _*)

if (!nixBuild)
root
else
root.settings(PB.runProtoc in Compile := (args => Process("protoc", args) !))
}

scalacOptions := Seq(
"-unchecked",
Expand Down
3 changes: 3 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{ system ? builtins.currentSystem, src ? ./.
, pkgs ? (import ./nix { inherit system src; }).pkgs }:
pkgs.mantis
26 changes: 26 additions & 0 deletions manual-repo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# this file must still be generated manually.
{
"repos" = {
"nix-public" = "";
"nix-typesafe-ivy-releases" = "[organisation]/[module]/(scala_[scalaVersion]/)(sbt_[sbtVersion]/)[revision]/[type]s/[artifact](-[classifier]).[ext]";
};
"artifacts" = {
# dependencies so sbt can build the sbt-compiler-interface (http://www.scala-sbt.org/0.13/docs/Compiler-Interface.html)
"nix-public/org/scala-lang/jline/2.10.6/jline-2.10.6.pom" = {
url = "https://repo1.maven.org/maven2/org/scala-lang/jline/2.10.6/jline-2.10.6.pom";
sha256 = "16mg4b2c1m6gcq901wy6f6jpy8spw2yh909gi826xykq89ja94dg";
};
"nix-public/org/scala-lang/jline/2.10.6/jline-2.10.6.jar" = {
url = "https://repo1.maven.org/maven2/org/scala-lang/jline/2.10.6/jline-2.10.6.jar";
sha256 = "1cfk6whncx2g87grwdfmz6f76bn807saqik91iwcfv099b1jngw1";
};
"nix-public/org/fusesource/jansi/jansi/1.4/jansi-1.4.pom" = {
url = "https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.4/jansi-1.4.pom";
sha256 = "0rgprkbg4ljarf0x79snk2h1b0974glhl2fw1bxkxbw8k3ifda1s";
};
"nix-public/org/fusesource/jansi/jansi/1.4/jansi-1.4.jar" = {
url = "https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/1.4/jansi-1.4.jar";
sha256 = "183ms545msn02fl0181rwbcifc8qy82rz4l6dglnhv9la8a1bnc2";
};
};
}
25 changes: 25 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ system ? builtins.currentSystem, sources ? import ./sources.nix, src ? ../. }:

let
overlay = final: prev: {
inherit sources;
inherit (import sources.gitignore { inherit (prev) lib; }) gitignoreSource;

sbtix = prev.callPackage ../sbtix.nix {
jdk = prev.openjdk8_headless;
jre = prev.openjdk8_headless.jre;
};

mantisPkgs = final.callPackage ./pkgs/mantis {
inherit (prev.openjdk8_headless) jre;
inherit src;
};

inherit (final.mantisPkgs) mantis;

inherit (final.mantisPkgs) mantis-unwrapped;
};
in import sources.nixpkgs {
inherit system;
overlays = [ overlay ];
}
9 changes: 9 additions & 0 deletions nix/pkgs/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ pkgs, lib, newScope, sources, src, impure ? false }:

lib.makeScope newScope (self:
with self;
let callPackages = lib.callPackagesWith (pkgs // self);
in {
inherit sources src impure;
jdk = prev.openjdk8_headless;
})
26 changes: 26 additions & 0 deletions nix/pkgs/mantis/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{ src, lib, gitignoreSource, callPackage, jre }: rec {

mkSrc = src:
let
isGit = builtins.pathExists (src + "/.git");
repo = builtins.fetchGit { url = src; submodules = true; };
dirty = repo.revCount == 0;
filterSrc = src:
lib.cleanSourceWith {
inherit src;
filter = path: _: !lib.hasSuffix "nix" path;
};
in if isGit then
if dirty then filterSrc (gitignoreSource src) else repo
else
src;

mantis-source = mkSrc src;

mantis-unwrapped = callPackage ./unwrapped.nix { src = mantis-source; };

mantis = callPackage ./wrapped.nix {
mantis = mantis-unwrapped;
inherit jre;
};
}
51 changes: 51 additions & 0 deletions nix/pkgs/mantis/unwrapped.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# this file originates from SBTix
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we improve the comment, i mean, this file is originates from SBTix but as far as i know we also added some stuff.

{ src, stdenv, writeShellScriptBin, bash, protobuf, sbtix
, jdk, impure ? false }:

let
inherit (stdenv.lib) optionalString makeLibraryPath;
inherit (stdenv) cc isDarwin;

LD_LIBRARY_PATH = makeLibraryPath [ cc.cc.lib ];

unlessDarwin = optionalString (!stdenv.isDarwin);

# sbt-protoc puts the scala plugin in /tmp/protobridge<some-random-number>.
# it is in fact a shell script with a standard `#!/usr/bin/env sh` shebang
# that makes the Nix sandbox ANGRY and breaks all the things in a cryptic,
# hairpull-inducing way. So we gotta sed it out. Not the prettiest thing
# but it works.
protoc-wrapper = writeShellScriptBin "protoc" ''
set -e

for f in "$@"; do
echo ''${f##*=}
done | grep protocbridge | xargs sed -i "1s|.*|#!${bash}/bin/bash|"

exec ${protobuf}/bin/protoc "$@"
'';

in sbtix.buildSbtProject {
inherit src;

name = "mantis";
sbtOptions = "-Dnix=true";
buildInputs = [ protoc-wrapper ];
sbtixBuildInputs = [];

repo = [
(import ../../../repo.nix)
(import ../../../project/repo.nix)
(import ../../../manual-repo.nix)
];

installPhase = ''
sbt stage
mkdir -p $out/
cp target/universal/stage/* $out/ -r
mkdir -p $out/share/mantis
mv $out/{LICENSE,RELEASE,mantis_config.txt} $_
'';

dontPatchShebangs = impure;
}
33 changes: 33 additions & 0 deletions nix/pkgs/mantis/wrapped.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{ lib, stdenv, mantis, makeWrapper, jre, gawk }:
let
inherit (stdenv.lib) optionalString makeLibraryPath;
inherit (stdenv) cc isDarwin;
LD_LIBRARY_PATH = makeLibraryPath [ cc.cc.lib ];
PATH = lib.makeBinPath [ jre gawk ];
in stdenv.mkDerivation {
pname = "mantis";
version = let
buildSbt = builtins.readFile ../../../build.sbt;
captures = builtins.match ''.*version := "([^"]+)".*'' buildSbt;
in builtins.elemAt captures 0;

nativeBuildInputs = [ makeWrapper ];

src = mantis;

buildPhase = ":";

installPhase = ''
cp -r $src $out
chmod -R u+rw $out

for p in $(find $out/bin/* -executable); do
wrapProgram "$p" \
--prefix PATH : ${PATH} \
${
optionalString (!isDarwin)
"--prefix LD_LIBRARY_PATH : ${LD_LIBRARY_PATH}"
}
done
'';
}
50 changes: 50 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"Sbtix": {
"branch": "master",
"description": "Generates Nix definitions for your SBT builds",
"homepage": null,
"owner": "input-output-hk",
"repo": "Sbtix",
"rev": "7b969a5641fce10500ca51cbe88af4ea160d7064",
"sha256": "19pg7rm36b0v9y3ibq5cwsq38pwj3xw3d8srv78svmpnrzm1dh9g",
"type": "tarball",
"url": "https://github.com/input-output-hk/Sbtix/archive/7b969a5641fce10500ca51cbe88af4ea160d7064.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"gitignore": {
"branch": "master",
"description": "Nix function for filtering local git sources",
"homepage": "",
"owner": "hercules-ci",
"repo": "gitignore",
"rev": "ec5dd0536a5e4c3a99c797b86180f7261197c124",
"sha256": "0k2r8y21rn4kr5dmddd3906x0733fs3bb8hzfpabkdav3wcy3klv",
"type": "tarball",
"url": "https://github.com/hercules-ci/gitignore/archive/ec5dd0536a5e4c3a99c797b86180f7261197c124.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"niv": {
"branch": "master",
"description": "Easy dependency management for Nix projects",
"homepage": "https://github.com/nmattia/niv",
"owner": "nmattia",
"repo": "niv",
"rev": "f73bf8d584148677b01859677a63191c31911eae",
"sha256": "0jlmrx633jvqrqlyhlzpvdrnim128gc81q5psz2lpp2af8p8q9qs",
"type": "tarball",
"url": "https://github.com/nmattia/niv/archive/f73bf8d584148677b01859677a63191c31911eae.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs": {
"branch": "nixos-20.03",
"description": "Nixpkgs/NixOS branches that track the Nixpkgs/NixOS channels",
"homepage": null,
"owner": "NixOS",
"repo": "nixpkgs-channels",
"rev": "e2bb73ce5f786b83e984b80199112f86b8a6cc9d",
"sha256": "0mpcdwhippvgsj3kj8vw35dgz94dnzgxgsfqqzcfpmvnzjc23vk7",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs-channels/archive/e2bb73ce5f786b83e984b80199112f86b8a6cc9d.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
}
Loading