1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.cpuminer-cryptonight;
7
8 json = builtins.toJSON (
9 cfg // {
10 enable = null;
11 threads =
12 if cfg.threads == 0 then null else toString cfg.threads;
13 }
14 );
15
16 confFile = builtins.toFile "cpuminer.json" json;
17in
18{
19
20 options = {
21
22 services.cpuminer-cryptonight = {
23 enable = mkOption {
24 type = types.bool;
25 default = false;
26 description = ''
27 Whether to enable the cpuminer cryptonight miner.
28 '';
29 };
30 url = mkOption {
31 type = types.string;
32 description = "URL of mining server";
33 };
34 user = mkOption {
35 type = types.string;
36 description = "Username for mining server";
37 };
38 pass = mkOption {
39 type = types.string;
40 default = "x";
41 description = "Password for mining server";
42 };
43 threads = mkOption {
44 type = types.int;
45 default = 0;
46 description = "Number of miner threads, defaults to available processors";
47 };
48 };
49
50 };
51
52 config = mkIf config.services.cpuminer-cryptonight.enable {
53
54 systemd.services.cpuminer-cryptonight = {
55 description = "Cryptonight cpuminer";
56 wantedBy = [ "multi-user.target" ];
57 after = [ "network.target" ];
58 serviceConfig = {
59 ExecStart = "${pkgs.cpuminer-multi}/bin/minerd --syslog --config=${confFile}";
60 User = "nobody";
61 };
62 };
63
64 };
65
66}