8 cfg = config.services.cgminer;
10 convType = with builtins; v: if lib.isBool v then lib.boolToString v else toString v;
11 mergedHwConfig = lib.mapAttrsToList (
12 n: v: ''"${n}": "${(lib.concatStringsSep "," (map convType v))}"''
13 ) (lib.foldAttrs (n: a: [ n ] ++ a) [ ] cfg.hardware);
17 n: v: ''"${n}": ${if lib.isBool v then convType v else ''"${convType v}"''}''
20 cgminerConfig = pkgs.writeText "cgminer.conf" ''
22 ${lib.concatStringsSep ",\n" mergedHwConfig},
23 ${lib.concatStringsSep ",\n" mergedConfig},
26 lib.concatStringsSep ",\n" (
27 map (v: ''{"url": "${v.url}", "user": "${v.user}", "pass": "${v.pass}"}'') cfg.pools
39 enable = lib.mkEnableOption "cgminer, an ASIC/FPGA/GPU miner for bitcoin and litecoin";
41 package = lib.mkPackageOption pkgs "cgminer" { };
46 description = "User account under which cgminer runs";
49 pools = lib.mkOption {
50 default = [ ]; # Run benchmark
51 type = lib.types.listOf (lib.types.attrsOf lib.types.str);
52 description = "List of pools where to mine";
55 url = "http://p2pool.org:9332";
56 username = "17EUZxTvs9uRmPsjPZSYUU3zCz9iwstudk";
62 hardware = lib.mkOption {
63 default = [ ]; # Run without options
64 type = lib.types.listOf (lib.types.attrsOf (lib.types.either lib.types.str lib.types.int));
65 description = "List of config options for every GPU";
90 config = lib.mkOption {
92 type = lib.types.attrsOf (lib.types.either lib.types.bool lib.types.int);
93 description = "Additional config";
109 ###### implementation
111 config = lib.mkIf config.services.cgminer.enable {
113 users.users = lib.optionalAttrs (cfg.user == "cgminer") {
117 description = "Cgminer user";
120 users.groups = lib.optionalAttrs (cfg.user == "cgminer") {
124 environment.systemPackages = [ cfg.package ];
126 systemd.services.cgminer = {
127 path = [ pkgs.cgminer ];
131 "display-manager.service"
133 wantedBy = [ "multi-user.target" ];
136 LD_LIBRARY_PATH = "/run/opengl-driver/lib:/run/opengl-driver-32/lib";
137 DISPLAY = ":${toString config.services.xserver.display}";
138 GPU_MAX_ALLOC_PERCENT = "100";
139 GPU_USE_SYNC_OBJECTS = "1";
142 startLimitIntervalSec = 60; # 1 min
144 ExecStart = "${pkgs.cgminer}/bin/cgminer --syslog --text-only --config ${cgminerConfig}";