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