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