1 { config, lib, pkgs, ... }:
6 cfg = config.services.cgminer;
8 convType = with builtins;
9 v: if isBool v then boolToString v else toString v;
11 mapAttrsToList (n: v: ''"${n}": "${(concatStringsSep "," (map convType v))}"'')
12 (foldAttrs (n: a: [n] ++ a) [] cfg.hardware);
13 mergedConfig = with builtins;
14 mapAttrsToList (n: v: ''"${n}": ${if isBool v then "" else ''"''}${convType v}${if isBool v then "" else ''"''}'')
17 cgminerConfig = pkgs.writeText "cgminer.conf" ''
19 ${concatStringsSep ",\n" mergedHwConfig},
20 ${concatStringsSep ",\n" mergedConfig},
22 ${concatStringsSep ",\n"
23 (map (v: ''{"url": "${v.url}", "user": "${v.user}", "pass": "${v.pass}"}'')
34 enable = mkEnableOption (lib.mdDoc "cgminer, an ASIC/FPGA/GPU miner for bitcoin and litecoin");
37 default = pkgs.cgminer;
38 defaultText = literalExpression "pkgs.cgminer";
39 description = lib.mdDoc "Which cgminer derivation to use.";
46 description = lib.mdDoc "User account under which cgminer runs";
50 default = []; # Run benchmark
51 type = types.listOf (types.attrsOf types.str);
52 description = lib.mdDoc "List of pools where to mine";
54 url = "http://p2pool.org:9332";
55 username = "17EUZxTvs9uRmPsjPZSYUU3zCz9iwstudk";
61 default = []; # Run without options
62 type = types.listOf (types.attrsOf (types.either types.str types.int));
63 description= lib.mdDoc "List of config options for every GPU";
89 type = types.attrsOf (types.either types.bool types.int);
90 description = lib.mdDoc "Additional config";
107 ###### implementation
109 config = mkIf config.services.cgminer.enable {
111 users.users = optionalAttrs (cfg.user == "cgminer") {
115 description = "Cgminer user";
118 users.groups = optionalAttrs (cfg.user == "cgminer") {
122 environment.systemPackages = [ cfg.package ];
124 systemd.services.cgminer = {
125 path = [ pkgs.cgminer ];
127 after = [ "network.target" "display-manager.service" ];
128 wantedBy = [ "multi-user.target" ];
131 LD_LIBRARY_PATH = "/run/opengl-driver/lib:/run/opengl-driver-32/lib";
132 DISPLAY = ":${toString config.services.xserver.display}";
133 GPU_MAX_ALLOC_PERCENT = "100";
134 GPU_USE_SYNC_OBJECTS = "1";
137 startLimitIntervalSec = 60; # 1 min
139 ExecStart = "${pkgs.cgminer}/bin/cgminer --syslog --text-only --config ${cgminerConfig}";