1 { config, lib, pkgs, ... }:
3 cfg = config.services.cgminer;
5 convType = with builtins;
6 v: if lib.isBool v then lib.boolToString v else toString v;
8 lib.mapAttrsToList (n: v: ''"${n}": "${(lib.concatStringsSep "," (map convType v))}"'')
9 (lib.foldAttrs (n: a: [n] ++ a) [] cfg.hardware);
10 mergedConfig = with builtins;
11 lib.mapAttrsToList (n: v: ''"${n}": ${if lib.isBool v then convType v else ''"${convType v}"''}'')
14 cgminerConfig = pkgs.writeText "cgminer.conf" ''
16 ${lib.concatStringsSep ",\n" mergedHwConfig},
17 ${lib.concatStringsSep ",\n" mergedConfig},
19 ${lib.concatStringsSep ",\n"
20 (map (v: ''{"url": "${v.url}", "user": "${v.user}", "pass": "${v.pass}"}'')
31 enable = lib.mkEnableOption "cgminer, an ASIC/FPGA/GPU miner for bitcoin and litecoin";
33 package = lib.mkPackageOption pkgs "cgminer" { };
38 description = "User account under which cgminer runs";
41 pools = lib.mkOption {
42 default = []; # Run benchmark
43 type = lib.types.listOf (lib.types.attrsOf lib.types.str);
44 description = "List of pools where to mine";
46 url = "http://p2pool.org:9332";
47 username = "17EUZxTvs9uRmPsjPZSYUU3zCz9iwstudk";
52 hardware = lib.mkOption {
53 default = []; # Run without options
54 type = lib.types.listOf (lib.types.attrsOf (lib.types.either lib.types.str lib.types.int));
55 description= "List of config options for every GPU";
79 config = lib.mkOption {
81 type = lib.types.attrsOf (lib.types.either lib.types.bool lib.types.int);
82 description = "Additional config";
101 config = lib.mkIf config.services.cgminer.enable {
103 users.users = lib.optionalAttrs (cfg.user == "cgminer") {
107 description = "Cgminer user";
110 users.groups = lib.optionalAttrs (cfg.user == "cgminer") {
114 environment.systemPackages = [ cfg.package ];
116 systemd.services.cgminer = {
117 path = [ pkgs.cgminer ];
119 after = [ "network.target" "display-manager.service" ];
120 wantedBy = [ "multi-user.target" ];
123 LD_LIBRARY_PATH = "/run/opengl-driver/lib:/run/opengl-driver-32/lib";
124 DISPLAY = ":${toString config.services.xserver.display}";
125 GPU_MAX_ALLOC_PERCENT = "100";
126 GPU_USE_SYNC_OBJECTS = "1";
129 startLimitIntervalSec = 60; # 1 min
131 ExecStart = "${pkgs.cgminer}/bin/cgminer --syslog --text-only --config ${cgminerConfig}";