at 23.11-pre 2.9 kB view raw
1{ lib, config, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.xmr-stak; 8 9 pkg = pkgs.xmr-stak.override { 10 inherit (cfg) openclSupport cudaSupport; 11 }; 12 13in 14 15{ 16 options = { 17 services.xmr-stak = { 18 enable = mkEnableOption (lib.mdDoc "xmr-stak miner"); 19 openclSupport = mkEnableOption (lib.mdDoc "support for OpenCL (AMD/ATI graphics cards)"); 20 cudaSupport = mkEnableOption (lib.mdDoc "support for CUDA (NVidia graphics cards)"); 21 22 extraArgs = mkOption { 23 type = types.listOf types.str; 24 default = []; 25 example = [ "--noCPU" "--currency monero" ]; 26 description = lib.mdDoc "List of parameters to pass to xmr-stak."; 27 }; 28 29 configFiles = mkOption { 30 type = types.attrsOf types.str; 31 default = {}; 32 example = literalExpression '' 33 { 34 "config.txt" = ''' 35 "verbose_level" : 4, 36 "h_print_time" : 60, 37 "tls_secure_algo" : true, 38 '''; 39 "pools.txt" = ''' 40 "currency" : "monero7", 41 "pool_list" : 42 [ { "pool_address" : "pool.supportxmr.com:443", 43 "wallet_address" : "my-wallet-address", 44 "rig_id" : "", 45 "pool_password" : "nixos", 46 "use_nicehash" : false, 47 "use_tls" : true, 48 "tls_fingerprint" : "", 49 "pool_weight" : 23 50 }, 51 ], 52 '''; 53 } 54 ''; 55 description = lib.mdDoc '' 56 Content of config files like config.txt, pools.txt or cpu.txt. 57 ''; 58 }; 59 }; 60 }; 61 62 config = mkIf cfg.enable { 63 systemd.services.xmr-stak = { 64 wantedBy = [ "multi-user.target" ]; 65 bindsTo = [ "network-online.target" ]; 66 after = [ "network-online.target" ]; 67 environment = mkIf cfg.cudaSupport { 68 LD_LIBRARY_PATH = "${pkgs.linuxPackages_latest.nvidia_x11}/lib"; 69 }; 70 71 preStart = concatStrings (flip mapAttrsToList cfg.configFiles (fn: content: '' 72 ln -sf '${pkgs.writeText "xmr-stak-${fn}" content}' '${fn}' 73 '')); 74 75 serviceConfig = let rootRequired = cfg.openclSupport || cfg.cudaSupport; in { 76 ExecStart = "${pkg}/bin/xmr-stak ${concatStringsSep " " cfg.extraArgs}"; 77 # xmr-stak generates cpu and/or gpu configuration files 78 WorkingDirectory = "/tmp"; 79 PrivateTmp = true; 80 DynamicUser = !rootRequired; 81 LimitMEMLOCK = toString (1024*1024); 82 }; 83 }; 84 }; 85 86 imports = [ 87 (mkRemovedOptionModule ["services" "xmr-stak" "configText"] '' 88 This option was removed in favour of `services.xmr-stak.configFiles` 89 because the new config file `pools.txt` was introduced. You are 90 now able to define all other config files like cpu.txt or amd.txt. 91 '') 92 ]; 93}