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

3.1.0 flake #947

Draft
wants to merge 22 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 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
79 changes: 79 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
description = "Mantis flake";

inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url =
"github:nixos/nixpkgs?rev=a98302aa9b9628915878a6ea9776c40a0bb02950";
nixpkgs-sbt = {
url = "github:nixos/nixpkgs?rev=e2bb73ce5f786b83e984b80199112f86b8a6cc9d";
flake = false;
};
sbtix = {
url =
"github:input-output-hk/Sbtix?rev=7b969a5641fce10500ca51cbe88af4ea160d7064";
flake = false;
};
};

outputs = { self, nixpkgs, flake-utils, nixpkgs-sbt, ... }@inputs:
let
overlay = final: prev: {
inherit (import nixpkgs-sbt { inherit (final) system; }) sbt;
sbtix = final.callPackage ./sbtix.nix { };
Copy link
Contributor

Choose a reason for hiding this comment

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

I would not use sbtix, but instead sbt-derivation. Mantis is already using it on the develop branch


mantisPkgs = final.callPackage ./nix/pkgs/mantis {
src = builtins.fetchGit {
url = "https://github.com/input-output-hk/mantis";
rev = self.rev or "482340d5e6ab635e5a5047e9b670d59b4ad366c2";
ref = "3.1.0-flake";
submodules = true;
};
};

jdk = prev.openjdk8_headless;
jre = prev.openjdk8_headless.jre;

inherit (final.mantisPkgs) mantis;

kevm = final.callPackage ./nix/pkgs/kevm.nix { };

mantis-entrypoint = final.callPackage ./nix/entrypoint.nix { };
};

pkgsForSystem = system:
(import nixpkgs) {
inherit system;
overlays = [ overlay ];
};

mkHydraUtils = mkPkgs:
let
# nothing in lib should really depend on the system
libPkgs = mkPkgs "x86_64-linux";
# [attrset] -> attrset
recursiveMerge = libPkgs.lib.foldr libPkgs.lib.recursiveUpdate { };
mkHydraJobsForSystem = attrs: system:
recursiveMerge
(map (n: { "${n}"."${system}" = (mkPkgs system)."${n}"; }) attrs);
in {
collectHydraSets = jobSets: { hydraJobs = recursiveMerge jobSets; };
mkHydraSet = attrs: systems:
recursiveMerge (map (mkHydraJobsForSystem attrs) systems);
};

hydraUtils = mkHydraUtils pkgsForSystem;
inherit (hydraUtils) collectHydraSets mkHydraSet;

in flake-utils.lib.eachDefaultSystem (system: rec {
pkgs = pkgsForSystem system;
legacyPackages = pkgs;

defaultPackage = pkgs.mantis;
devShell = pkgs.mkShell { nativeBuildInputs = with pkgs; [ solc sbt ]; };
apps.mantis = flake-utils.lib.mkApp { drv = pkgs.mantis; };
defaultApp = apps.mantis;
}) // (collectHydraSets [
(mkHydraSet [ "mantis" ] [ "x86_64-linux" "x86_64-darwin" ])
(mkHydraSet [ "kevm" ] [ "x86_64-linux" ])
(mkHydraSet [ "mantis-entrypoint" ] [ "x86_64-linux" ])
]);
}
25 changes: 0 additions & 25 deletions nix/default.nix

This file was deleted.

8 changes: 8 additions & 0 deletions nix/entrypoint.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{ lib, writeShellScriptBin, awscli, mantis, coreutils, gnugrep }:
writeShellScriptBin "mantis-entrypoint" ''
set -exuo pipefail

export PATH="${lib.makeBinPath [ coreutils mantis awscli gnugrep ]}"

${builtins.readFile ./entrypoint.sh}
''
33 changes: 33 additions & 0 deletions nix/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash

set -exuo pipefail

mkdir -p /tmp "$NOMAD_TASK_DIR/mantis"
cd "$NOMAD_TASK_DIR"

if [ -n "${DAG_NAME:-}" ]; then
if [ -f "ethash/$DAG_NAME" ]; then
echo "found existing DAG"
sha256sum "ethash/$DAG_NAME"
else
mkdir -p ethash
aws \
--endpoint-url "$MONITORING_ADDR" \
s3 cp \
"s3://mantis-kevm-dag/$DAG_NAME" \
"ethash/$DAG_NAME" \
|| echo "Unable to download DAG, skipping."
fi
fi

set +x
echo "Waiting for $REQUIRED_PEER_COUNT peers to show up in the config"
until [ "$(grep -c enode mantis.conf)" -ge "$REQUIRED_PEER_COUNT" ]; do
sleep 1
done
set -x

ulimit -c unlimited
cp mantis.conf running.conf

exec mantis "-Duser.home=$NOMAD_TASK_DIR" "$@"
9 changes: 0 additions & 9 deletions nix/pkgs/default.nix

This file was deleted.

25 changes: 25 additions & 0 deletions nix/pkgs/kevm.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ lib, stdenv, dockerTools, secp256k1, gmp5, mpfr, zlib }:
let libPath = lib.makeLibraryPath [ secp256k1 gmp5 mpfr zlib ];
in stdenv.mkDerivation {
name = "kevm";

src = dockerTools.pullImage {
imageName = "inputoutput/mantis";
imageDigest =
"sha256:594ed009f1bc1f12b86e11136441602107c3d580476002d9bae58b258a74ac1b";
sha256 = "sha256-JT+FarGQlgYoO392Ne1ofdqmishZLfH+OwV2CXTYwdA=";
};

installPhase = ''
mkdir -p tmp $out/bin
tar --delay-directory-restore -C tmp -xf layer.tar || true

cp tmp/bin/kevm-vm $out/bin
chmod 0755 $out/bin/kevm-vm

patchelf \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
--set-rpath "${libPath}" \
"$out/bin/kevm-vm"
'';
}
6 changes: 2 additions & 4 deletions nix/pkgs/mantis/default.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{ src, mkSrc, lib, gitignoreSource, callPackage, jre }: rec {
{ src, lib, callPackage, jre }: rec {

mantis-source = mkSrc src;

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

mantis = callPackage ./wrapped.nix {
mantis = mantis-unwrapped;
Expand Down
8 changes: 5 additions & 3 deletions nix/pkgs/mantis/wrapped.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{ lib, stdenv, mantis, makeWrapper, jre, gawk }:
{ lib, stdenv, mantis, makeWrapper, jre, gawk, gnused, kevm, coreutils }:
let
inherit (stdenv.lib) optionalString makeLibraryPath;
inherit (stdenv) cc isDarwin;
LD_LIBRARY_PATH = makeLibraryPath [ cc.cc.lib ];
PATH = lib.makeBinPath [ jre gawk ];
PATH = lib.makeBinPath [ jre gawk gnused kevm coreutils ];
in stdenv.mkDerivation {
pname = "mantis";
version = let
Expand All @@ -23,11 +23,13 @@ in stdenv.mkDerivation {

for p in $(find $out/bin/* -executable); do
wrapProgram "$p" \
--prefix PATH : ${PATH} \
--set PATH ${PATH} \
${
optionalString (!isDarwin)
"--prefix LD_LIBRARY_PATH : ${LD_LIBRARY_PATH}"
}
done

ln -s ${kevm}/bin/kevm-vm $out/bin
'';
}
74 changes: 0 additions & 74 deletions nix/sources.json

This file was deleted.

Loading