2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.cgminer;
|
|
|
|
|
|
|
|
convType = with builtins;
|
|
|
|
v: if isBool v then boolToString v else toString v;
|
|
|
|
mergedHwConfig =
|
|
|
|
mapAttrsToList (n: v: ''"${n}": "${(concatStringsSep "," (map convType v))}"'')
|
|
|
|
(foldAttrs (n: a: [n] ++ a) [] cfg.hardware);
|
|
|
|
mergedConfig = with builtins;
|
2023-08-04 22:07:22 +00:00
|
|
|
mapAttrsToList (n: v: ''"${n}": ${if isBool v then convType v else ''"${convType v}"''}'')
|
2020-04-24 23:36:52 +00:00
|
|
|
cfg.config;
|
|
|
|
|
|
|
|
cgminerConfig = pkgs.writeText "cgminer.conf" ''
|
|
|
|
{
|
|
|
|
${concatStringsSep ",\n" mergedHwConfig},
|
|
|
|
${concatStringsSep ",\n" mergedConfig},
|
|
|
|
"pools": [
|
|
|
|
${concatStringsSep ",\n"
|
|
|
|
(map (v: ''{"url": "${v.url}", "user": "${v.user}", "pass": "${v.pass}"}'')
|
|
|
|
cfg.pools)}]
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.cgminer = {
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "cgminer, an ASIC/FPGA/GPU miner for bitcoin and litecoin");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "cgminer" { };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
2021-02-05 17:12:51 +00:00
|
|
|
type = types.str;
|
2020-04-24 23:36:52 +00:00
|
|
|
default = "cgminer";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User account under which cgminer runs";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
pools = mkOption {
|
|
|
|
default = []; # Run benchmark
|
2021-02-05 17:12:51 +00:00
|
|
|
type = types.listOf (types.attrsOf types.str);
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "List of pools where to mine";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = [{
|
|
|
|
url = "http://p2pool.org:9332";
|
|
|
|
username = "17EUZxTvs9uRmPsjPZSYUU3zCz9iwstudk";
|
|
|
|
password="X";
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
hardware = mkOption {
|
|
|
|
default = []; # Run without options
|
2021-02-05 17:12:51 +00:00
|
|
|
type = types.listOf (types.attrsOf (types.either types.str types.int));
|
2022-08-12 12:06:08 +00:00
|
|
|
description= lib.mdDoc "List of config options for every GPU";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = [
|
|
|
|
{
|
|
|
|
intensity = 9;
|
|
|
|
gpu-engine = "0-985";
|
|
|
|
gpu-fan = "0-85";
|
|
|
|
gpu-memclock = 860;
|
|
|
|
gpu-powertune = 20;
|
|
|
|
temp-cutoff = 95;
|
|
|
|
temp-overheat = 85;
|
|
|
|
temp-target = 75;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
intensity = 9;
|
|
|
|
gpu-engine = "0-950";
|
|
|
|
gpu-fan = "0-85";
|
|
|
|
gpu-memclock = 825;
|
|
|
|
gpu-powertune = 20;
|
|
|
|
temp-cutoff = 95;
|
|
|
|
temp-overheat = 85;
|
|
|
|
temp-target = 75;
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
default = {};
|
2021-09-22 15:38:15 +00:00
|
|
|
type = types.attrsOf (types.either types.bool types.int);
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Additional config";
|
2020-04-24 23:36:52 +00:00
|
|
|
example = {
|
|
|
|
auto-fan = true;
|
|
|
|
auto-gpu = true;
|
|
|
|
expiry = 120;
|
|
|
|
failover-only = true;
|
|
|
|
gpu-threads = 2;
|
|
|
|
log = 5;
|
|
|
|
queue = 1;
|
|
|
|
scan-time = 60;
|
|
|
|
temp-histeresys = 3;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.cgminer.enable {
|
|
|
|
|
|
|
|
users.users = optionalAttrs (cfg.user == "cgminer") {
|
|
|
|
cgminer = {
|
2021-09-22 15:38:15 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
group = "cgminer";
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Cgminer user";
|
|
|
|
};
|
|
|
|
};
|
2021-09-22 15:38:15 +00:00
|
|
|
users.groups = optionalAttrs (cfg.user == "cgminer") {
|
|
|
|
cgminer = {};
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
|
|
|
systemd.services.cgminer = {
|
|
|
|
path = [ pkgs.cgminer ];
|
|
|
|
|
|
|
|
after = [ "network.target" "display-manager.service" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
environment = {
|
2021-02-05 17:12:51 +00:00
|
|
|
LD_LIBRARY_PATH = "/run/opengl-driver/lib:/run/opengl-driver-32/lib";
|
2020-04-24 23:36:52 +00:00
|
|
|
DISPLAY = ":${toString config.services.xserver.display}";
|
|
|
|
GPU_MAX_ALLOC_PERCENT = "100";
|
|
|
|
GPU_USE_SYNC_OBJECTS = "1";
|
|
|
|
};
|
|
|
|
|
2020-11-03 02:18:15 +00:00
|
|
|
startLimitIntervalSec = 60; # 1 min
|
2020-04-24 23:36:52 +00:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${pkgs.cgminer}/bin/cgminer --syslog --text-only --config ${cgminerConfig}";
|
|
|
|
User = cfg.user;
|
|
|
|
RestartSec = "30s";
|
|
|
|
Restart = "always";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|