1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7let
8 cfg = config.services.xmrig;
9 json = pkgs.formats.json { };
10 configFile = json.generate "config.json" cfg.settings;
11in
12{
13 options = {
14 services.xmrig = {
15 enable = lib.mkEnableOption "XMRig Mining Software";
16
17 package = lib.mkPackageOption pkgs "xmrig" {
18 example = "xmrig-mo";
19 };
20
21 settings = lib.mkOption {
22 default = { };
23 type = json.type;
24 example = lib.literalExpression ''
25 {
26 autosave = true;
27 cpu = true;
28 opencl = false;
29 cuda = false;
30 pools = [
31 {
32 url = "pool.supportxmr.com:443";
33 user = "your-wallet";
34 keepalive = true;
35 tls = true;
36 }
37 ]
38 }
39 '';
40 description = ''
41 XMRig configuration. Refer to
42 <https://xmrig.com/docs/miner/config>
43 for details on supported values.
44 '';
45 };
46 };
47 };
48
49 config = lib.mkIf cfg.enable {
50 hardware.cpu.x86.msr.enable = true;
51
52 systemd.services.xmrig = {
53 wantedBy = [ "multi-user.target" ];
54 after = [ "network.target" ];
55 description = "XMRig Mining Software Service";
56 serviceConfig = {
57 ExecStartPre = "${lib.getExe cfg.package} --config=${configFile} --dry-run";
58 ExecStart = "${lib.getExe cfg.package} --config=${configFile}";
59 # https://xmrig.com/docs/miner/randomx-optimization-guide/msr
60 # If you use recent XMRig with root privileges (Linux) or admin
61 # privileges (Windows) the miner configure all MSR registers
62 # automatically.
63 DynamicUser = lib.mkDefault false;
64 };
65 };
66 };
67
68 meta = with lib; {
69 maintainers = with maintainers; [ ratsclub ];
70 };
71}