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