nixos-config/images/etherminer/ethminer.nix

107 lines
2.4 KiB
Nix
Raw Normal View History

2021-05-06 07:58:41 +02:00
{ 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}
'';
};
};
}