From 92a1044b2ab446eebe701061438457b39258e207 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Thu, 6 May 2021 07:58:41 +0200 Subject: [PATCH] add ethminer --- configs/workhorse/mining.nix | 1 - images/etherminer/.gitignore | 2 + images/etherminer/README.md | 16 ++++ images/etherminer/configuration.nix | 52 ++++++++++++ images/etherminer/ethminer-pkg.nix | 64 ++++++++++++++ images/etherminer/ethminer.nix | 106 ++++++++++++++++++++++++ images/etherminer/parameters.nix.sample | 5 ++ 7 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 images/etherminer/.gitignore create mode 100644 images/etherminer/README.md create mode 100644 images/etherminer/configuration.nix create mode 100644 images/etherminer/ethminer-pkg.nix create mode 100644 images/etherminer/ethminer.nix create mode 100644 images/etherminer/parameters.nix.sample diff --git a/configs/workhorse/mining.nix b/configs/workhorse/mining.nix index ddedbc2..0f27d61 100644 --- a/configs/workhorse/mining.nix +++ b/configs/workhorse/mining.nix @@ -31,7 +31,6 @@ in { }; #nixpkgs.config.allowBroken = true; - hardware.opengl = { enable = true; extraPackages = with pkgs; [ diff --git a/images/etherminer/.gitignore b/images/etherminer/.gitignore new file mode 100644 index 0000000..0dac9f3 --- /dev/null +++ b/images/etherminer/.gitignore @@ -0,0 +1,2 @@ +parameters.nix +*.iso \ No newline at end of file diff --git a/images/etherminer/README.md b/images/etherminer/README.md new file mode 100644 index 0000000..b288e7b --- /dev/null +++ b/images/etherminer/README.md @@ -0,0 +1,16 @@ +# How to build + +`cp parameters.nix.sample parameters.nix` and set file up. + +``` +nixos-generate \ + -f iso \ + -c configuration.nix \ + -o image.iso \ +``` + +# How to create USB-Stick + +``` +dd if=./image.iso of=/dev/sdXY bs=4096 +``` diff --git a/images/etherminer/configuration.nix b/images/etherminer/configuration.nix new file mode 100644 index 0000000..80bfcd2 --- /dev/null +++ b/images/etherminer/configuration.nix @@ -0,0 +1,52 @@ +# $ nixos-generator -f iso -c configuration.nix -o image.iso +{ pkgs, lib, ... }: +let + parameters = import ./parameters.nix; +in +{ + + imports = [ + ./ethminer.nix + ]; + + nixpkgs.overlays = [ + (self: super: { + ethminer = super.lib.callPackageWith super ./ethminer-pkg.nix { + cudaSupport = true; + }; + }) + ]; + + # allow un-free + # ------------- + nixpkgs.config.allowUnfree = true; + environment.variables.NIXPKGS_ALLOW_UNFREE = "1"; + + time.timeZone = lib.mkDefault "Europe/Berlin"; + + networking.wireless = { + enable = true; + networks."${parameters.ssid}".psk = parameters.password; + }; + + # configure ethminer + own.services.ethminer = { + enable = true; + pool = "eu1.ethermine.org"; + wallet = parameters.wallet; + rig = "usb-stick"; + }; + + hardware.opengl = { + enable = true; + #extraPackages = with pkgs; []; + driSupport = true; + driSupport32Bit = true; + }; + + environment.systemPackages = with pkgs; [ + go-ethereum + i7z # check temperature + ]; + +} diff --git a/images/etherminer/ethminer-pkg.nix b/images/etherminer/ethminer-pkg.nix new file mode 100644 index 0000000..7db924c --- /dev/null +++ b/images/etherminer/ethminer-pkg.nix @@ -0,0 +1,64 @@ +{ lib, stdenv, clangStdenv, fetchFromGitHub, opencl-headers, cmake, jsoncpp +, boost, makeWrapper, cudatoolkit, cudaSupport, mesa, ethash, opencl-info +, ocl-icd, openssl, pkg-config, cli11 }@args: + +# Note that this requires clang < 9.0 to build, and currently +# clangStdenv provides clang 7.1 which satisfies the requirement. +let stdenv = if cudaSupport then clangStdenv else args.stdenv; + +in stdenv.mkDerivation rec { + pname = "ethminer"; + version = "0.19.0"; + + src = fetchFromGitHub { + owner = "ethereum-mining"; + repo = "ethminer"; + rev = "v${version}"; + sha256 = "1kyff3vx2r4hjpqah9qk99z6dwz7nsnbnhhl6a76mdhjmgp1q646"; + fetchSubmodules = true; + }; + + # NOTE: dbus is broken + cmakeFlags = [ + "-DHUNTER_ENABLED=OFF" + "-DETHASHCUDA=ON" + "-DAPICORE=ON" + "-DETHDBUS=OFF" + "-DCMAKE_BUILD_TYPE=Release" + ] ++ lib.optionals (!cudaSupport) [ + "-DETHASHCUDA=OFF" # on by default + ]; + + nativeBuildInputs = [ cmake pkg-config makeWrapper ]; + + buildInputs = [ + cli11 + boost + opencl-headers + mesa + ethash + opencl-info + ocl-icd + openssl + jsoncpp + ] ++ lib.optionals cudaSupport [ cudatoolkit ]; + + preConfigure = '' + sed -i 's/_lib_static//' libpoolprotocols/CMakeLists.txt + ''; + + postInstall = '' + wrapProgram $out/bin/ethminer --prefix LD_LIBRARY_PATH : /run/opengl-driver/lib + ''; + + meta = with lib; { + description = "Ethereum miner with OpenCL${ + lib.optionalString cudaSupport ", CUDA" + } and stratum support"; + homepage = "https://github.com/ethereum-mining/ethminer"; + platforms = [ "x86_64-linux" ]; + maintainers = with maintainers; [ nand0p atemu ]; + license = licenses.gpl3Only; + #broken = cudaSupport; + }; +} diff --git a/images/etherminer/ethminer.nix b/images/etherminer/ethminer.nix new file mode 100644 index 0000000..7adc821 --- /dev/null +++ b/images/etherminer/ethminer.nix @@ -0,0 +1,106 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.own.services.ethminer; + poolUrl = "stratum1+tcp://${cfg.wallet}.${cfg.rig}@${cfg.pool}:${ + toString cfg.stratumPort + }"; + +in { + + ###### interface + + options = { + + own.services.ethminer = { + + enable = mkOption { + type = types.bool; + default = false; + description = "Enable ethminer ether mining."; + }; + + recheckInterval = mkOption { + type = types.int; + default = 2000; + description = "Interval in milliseconds between farm rechecks."; + }; + + toolkit = mkOption { + type = types.enum [ "cuda" "opencl" ]; + default = "cuda"; + description = "Cuda or opencl toolkit."; + }; + + wallet = mkOption { + type = types.str; + example = "0x0123456789abcdef0123456789abcdef01234567"; + description = "Ethereum wallet address."; + }; + + pool = mkOption { + type = types.str; + example = "eth-us-east1.nanopool.org"; + description = "Mining pool address."; + }; + + stratumPort = mkOption { + type = types.port; + default = 4444; + description = "Stratum protocol tcp port."; + }; + + rig = mkOption { + type = types.str; + default = "rig01"; + description = "Mining rig name."; + }; + + maxPower = mkOption { + type = types.int; + default = 113; + description = "Miner max watt usage."; + }; + + }; + + }; + + ###### implementation + + config = mkIf cfg.enable { + + systemd.services.ethminer = { + path = [ pkgs.cudatoolkit ]; + description = "ethminer ethereum mining service"; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + + serviceConfig = { + DynamicUser = true; + ExecStartPre = "${pkgs.ethminer}/bin/.ethminer-wrapped --list-devices"; + ExecStartPost = optional (cfg.toolkit == "cuda") "+${ + getBin config.boot.kernelPackages.nvidia_x11 + }/bin/nvidia-smi -pl ${toString cfg.maxPower}"; + Restart = "always"; + }; + + environment = { + LD_LIBRARY_PATH = "${config.boot.kernelPackages.nvidia_x11}/lib"; + }; + + script = '' + ${pkgs.ethminer}/bin/.ethminer-wrapped \ + --farm-recheck ${toString cfg.recheckInterval} \ + --report-hashrate \ + --${cfg.toolkit} \ + --pool ${poolUrl} + ''; + + }; + + }; + +} diff --git a/images/etherminer/parameters.nix.sample b/images/etherminer/parameters.nix.sample new file mode 100644 index 0000000..b3d9a47 --- /dev/null +++ b/images/etherminer/parameters.nix.sample @@ -0,0 +1,5 @@ +{ + ssid = "Your SSID"; + password = "Your Password"; + wallet = "Your ETH Wallet Address"; +}