pkgs#miningcore: init at 50

This commit is contained in:
Timothy DeHerrera 2020-12-12 21:43:09 -07:00
parent 1b7fb9214d
commit 9134e200ab
No known key found for this signature in database
GPG key ID: 8985725DB5B0C122
4 changed files with 1695 additions and 0 deletions

View file

@ -0,0 +1,96 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p dotnet-sdk_3 nixfmt
# Run this script to generate deps.nix
# ./create_deps.sh /path/to/package/source/checkout > deps.nix
# Attribution: this script is shamelessly stolen and barely modified from
# <nixpkgs>/pkgs/applications/blockchains/wasabibackend
URLBASE="https://www.nuget.org/api/v2/package"
DEPS_HEADER="
{ fetchurl }:
let
nugetUrlBase = \"$URLBASE\";
fetchNuGet = { name, version, sha256 }: fetchurl {
inherit sha256;
url = \"\${nugetUrlBase}/\${name}/\${version}\";
};
in ["
DEPS_FOOTER="]"
DEPS_TEMPLATE="
(fetchNuGet {
name = \"%s\";
version = \"%s\";
sha256 = \"%s\";
})"
function generate_restore_log() {
checkout_path=$1
>&2 echo "generating restore log for $checkout_path..."
cd $checkout_path
dotnet nuget locals all --clear
dotnet restore -v normal --no-cache -r linux-x64
cd -
}
function process_restore_log() {
restore_log=$1
>&2 echo "processing restore log..."
while read line; do
if echo $line | grep -q "^[[:space:]]*Installing"; then
l=$(echo $line | xargs)
l=${l#Installing }
l=${l%.}
echo $l
fi
done < $restore_log
}
function prefetch_deps() {
processed_log=$1
>&2 echo "prefetching deps..."
while read line; do
name=$(echo $line | cut -d' ' -f1)
>&2 echo "prefetching '$name' version: $version"
version=$(echo $line | cut -d' ' -f2)
hash=$(nix-prefetch-url "$URLBASE/$name/$version" 2>/dev/null)
echo "$name $version $hash"
done < $processed_log
}
function generate_deps_expression() {
packages=$1
>&2 echo "generating deps nix-expression..."
echo $DEPS_HEADER
while read line; do
name=$(echo $line | cut -d' ' -f1)
version=$(echo $line | cut -d' ' -f2)
hash=$(echo $line | cut -d' ' -f3)
printf "$DEPS_TEMPLATE" $name $version $hash
done < $packages
echo $DEPS_FOOTER
}
function main() {
checkout_path=$1
tmpdir=$(mktemp -d)
generate_restore_log $checkout_path > $tmpdir/restore.log
process_restore_log $tmpdir/restore.log > $tmpdir/processed.log
prefetch_deps $tmpdir/processed.log > $tmpdir/prefetched.log
generate_deps_expression $tmpdir/prefetched.log > $tmpdir/deps.nix
nixfmt $tmpdir/deps.nix
cat $tmpdir/deps.nix
rm -rf $tmpdir
}
if [ ! -d "$1" ]; then
>&2 echo "First argument must be a directory, the path to the package source checkout"
exit 1
fi
main $@

View file

@ -0,0 +1,111 @@
{ stdenv
, fetchFromGitHub
, fetchurl
, makeWrapper
, dotnetPackages
, dotnetCorePackages
, openssl
, boost
, libsodium
, pkgconfig
, icu
, zeromq
}:
let
deps = import ./deps.nix { inherit fetchurl; };
dotnet-sdk = dotnetCorePackages.sdk_3_1;
Nuget = dotnetPackages.Nuget;
nugetSource = stdenv.mkDerivation {
pname = "${pname}-nuget-deps";
inherit version;
dontUnpack = true;
dontInstall = true;
nativeBuildInputs = [ Nuget ];
buildPhase = ''
export HOME=$(mktemp -d)
mkdir -p $out/lib
nuget sources Disable -Name "nuget.org"
for package in ${toString deps}; do
nuget add $package -Source $out/lib
done
'';
};
pname = "miningcore";
version = "50";
projectName = "Miningcore";
projectConfiguration = "Release";
projectRuntime = "linux-x64";
in
stdenv.mkDerivation rec {
inherit pname version;
src = fetchFromGitHub {
owner = "akshaynexus";
repo = "miningcore";
rev = "318c0c26a8f0fd7fd7588fb6845abacf6fc27c79";
hash = "sha256-TZrhNE/5XUxAirAXRnAZax4OBOeWQlwNkiackXuJ7bI=";
};
buildInputs = [
boost
libsodium
openssl
Nuget
dotnet-sdk
makeWrapper
pkgconfig
zeromq
];
buildPhase = ''
export HOME=$(mktemp -d)
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
export DOTNET_ROOT="${dotnet-sdk}/bin"
nuget sources Disable -Name "nuget.org"
dotnet restore \
--source ${nugetSource}/lib \
--runtime ${projectRuntime} \
src/${projectName}
dotnet publish \
--no-restore \
--runtime ${projectRuntime} \
--configuration ${projectConfiguration} \
src/${projectName}
'';
installPhase = ''
mkdir -p $out
cp -r src/${projectName}/bin/${projectConfiguration}/netcoreapp3.1/${projectRuntime}/publish $out/lib
mkdir -p $out/bin
makeWrapper $out/lib/Miningcore $out/bin/${pname} \
--prefix LD_LIBRARY_PATH : ${stdenv.lib.makeLibraryPath [
openssl
icu
zeromq
]} \
--run "cd $out/lib"
'';
# If we don't disable stripping the executable fails to start with segfault
dontStrip = true;
meta = with stdenv.lib; {
description = "A high-performance Mining-Pool Engine";
homepage = "https://github.com/akshaynexus/miningcore";
license = licenses.mit;
maintainers = with maintainers; [ nrdxp ];
platforms = [ "x86_64-linux" ];
};
}

File diff suppressed because it is too large Load diff

View file

@ -8,4 +8,5 @@ final: prev: {
libinih = prev.callPackage ./development/libraries/libinih { }; libinih = prev.callPackage ./development/libraries/libinih { };
steamcompmgr = steamcompmgr =
prev.callPackage ./applications/window-managers/steamcompmgr { }; prev.callPackage ./applications/window-managers/steamcompmgr { };
miningcore = prev.callPackage ./applications/blockchains/miningcore { };
} }