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
13 xmrConfArg = optionalString (cfg.configText != "") ("-c " +
14 pkgs.writeText "xmr-stak-config.txt" cfg.configText);
15
16in
17
18{
19 options = {
20 services.xmr-stak = {
21 enable = mkEnableOption "xmr-stak miner";
22 openclSupport = mkEnableOption "support for OpenCL (AMD/ATI graphics cards)";
23 cudaSupport = mkEnableOption "support for CUDA (NVidia graphics cards)";
24
25 extraArgs = mkOption {
26 type = types.listOf types.str;
27 default = [];
28 example = [ "--noCPU" "--currency monero" ];
29 description = "List of parameters to pass to xmr-stak.";
30 };
31
32 configText = mkOption {
33 type = types.lines;
34 default = "";
35 example = ''
36 "currency" : "monero",
37 "pool_list" :
38 [ { "pool_address" : "pool.supportxmr.com:5555",
39 "wallet_address" : "<long-hash>",
40 "pool_password" : "minername",
41 "pool_weight" : 1,
42 },
43 ],
44 '';
45 description = ''
46 Verbatim xmr-stak config.txt. If empty, the <literal>-c</literal>
47 parameter will not be added to the xmr-stak command.
48 '';
49 };
50 };
51 };
52
53 config = mkIf cfg.enable {
54 systemd.services.xmr-stak = {
55 wantedBy = [ "multi-user.target" ];
56 bindsTo = [ "network-online.target" ];
57 after = [ "network-online.target" ];
58 environment = mkIf cfg.cudaSupport {
59 LD_LIBRARY_PATH = "${pkgs.linuxPackages_latest.nvidia_x11}/lib";
60 };
61 script = ''
62 exec ${pkg}/bin/xmr-stak ${xmrConfArg} ${concatStringsSep " " cfg.extraArgs}
63 '';
64 serviceConfig = let rootRequired = cfg.openclSupport || cfg.cudaSupport; in {
65 # xmr-stak generates cpu and/or gpu configuration files
66 WorkingDirectory = "/tmp";
67 PrivateTmp = true;
68 DynamicUser = !rootRequired;
69 LimitMEMLOCK = toString (1024*1024);
70 };
71 };
72 };
73}