add ethminer

This commit is contained in:
Ingolf Wagner 2021-05-06 07:58:41 +02:00
parent 08ec3c079d
commit 92a1044b2a
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
7 changed files with 245 additions and 1 deletions

View file

@ -31,7 +31,6 @@ in {
};
#nixpkgs.config.allowBroken = true;
hardware.opengl = {
enable = true;
extraPackages = with pkgs; [

2
images/etherminer/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
parameters.nix
*.iso

View file

@ -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
```

View file

@ -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
];
}

View file

@ -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;
};
}

View file

@ -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}
'';
};
};
}

View file

@ -0,0 +1,5 @@
{
ssid = "Your SSID";
password = "Your Password";
wallet = "Your ETH Wallet Address";
}