2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.ethminer;
|
|
|
|
poolUrl = escapeShellArg "stratum1+tcp://${cfg.wallet}@${cfg.pool}:${toString cfg.stratumPort}/${cfg.rig}/${cfg.registerMail}";
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.ethminer = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Enable ethminer ether mining.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
recheckInterval = mkOption {
|
2022-04-15 01:41:22 +00:00
|
|
|
type = types.ints.unsigned;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 2000;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Interval in milliseconds between farm rechecks.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
toolkit = mkOption {
|
|
|
|
type = types.enum [ "cuda" "opencl" ];
|
|
|
|
default = "cuda";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Cuda or opencl toolkit.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
apiPort = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = -3333;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Ethminer api port. minus sign puts api in read-only mode.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
wallet = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "0x0123456789abcdef0123456789abcdef01234567";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Ethereum wallet address.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
pool = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "eth-us-east1.nanopool.org";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Mining pool address.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
stratumPort = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 9999;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Stratum protocol tcp port.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
rig = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "mining-rig-name";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Mining rig name.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
registerMail = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
example = "email%40example.org";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Url encoded email address to register with pool.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
maxPower = mkOption {
|
2022-04-15 01:41:22 +00:00
|
|
|
type = types.ints.unsigned;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = 113;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Miner max watt usage.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
systemd.services.ethminer = {
|
2022-04-15 01:41:22 +00:00
|
|
|
path = optional (cfg.toolkit == "cuda") [ pkgs.cudaPackages.cudatoolkit ];
|
2020-04-24 23:36:52 +00:00
|
|
|
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";
|
|
|
|
};
|
|
|
|
|
2022-04-15 01:41:22 +00:00
|
|
|
environment = mkIf (cfg.toolkit == "cuda") {
|
2020-04-24 23:36:52 +00:00
|
|
|
LD_LIBRARY_PATH = "${config.boot.kernelPackages.nvidia_x11}/lib";
|
|
|
|
};
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
${pkgs.ethminer}/bin/.ethminer-wrapped \
|
|
|
|
--farm-recheck ${toString cfg.recheckInterval} \
|
|
|
|
--report-hashrate \
|
|
|
|
--${cfg.toolkit} \
|
|
|
|
--api-port ${toString cfg.apiPort} \
|
|
|
|
--pool ${poolUrl}
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|