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