about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/computing/boinc/client.nix
blob: 7022751b3f012d0f0d6ca570889b6de14ea77741 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{config, lib, pkgs, ...}:

with lib;

let
  cfg = config.services.boinc;
  allowRemoteGuiRpcFlag = optionalString cfg.allowRemoteGuiRpc "--allow_remote_gui_rpc";

  fhsEnv = pkgs.buildFHSUserEnv {
    name = "boinc-fhs-env";
    targetPkgs = pkgs': [ cfg.package ] ++ cfg.extraEnvPackages;
    runScript = "/bin/boinc_client";
  };
  fhsEnvExecutable = "${fhsEnv}/bin/${fhsEnv.name}";

in
  {
    options.services.boinc = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = ''
          Whether to enable the BOINC distributed computing client. If this
          option is set to true, the boinc_client daemon will be run as a
          background service. The boinccmd command can be used to control the
          daemon.
        '';
      };

      package = mkOption {
        type = types.package;
        default = pkgs.boinc;
        defaultText = "pkgs.boinc";
        description = ''
          Which BOINC package to use.
        '';
      };

      dataDir = mkOption {
        type = types.path;
        default = "/var/lib/boinc";
        description = ''
          The directory in which to store BOINC's configuration and data files.
        '';
      };

      allowRemoteGuiRpc = mkOption {
        type = types.bool;
        default = false;
        description = ''
          If set to true, any remote host can connect to and control this BOINC
          client (subject to password authentication). If instead set to false,
          only the hosts listed in <varname>dataDir</varname>/remote_hosts.cfg will be allowed to
          connect.

          See also: <link xlink:href="http://boinc.berkeley.edu/wiki/Controlling_BOINC_remotely#Remote_access"/>
        '';
      };

      extraEnvPackages = mkOption {
        type = types.listOf types.package;
        default = [];
        example = "[ pkgs.virtualbox ]";
        description = ''
          Additional packages to make available in the environment in which
          BOINC will run. Common choices are:
          <variablelist>
            <varlistentry>
              <term><varname>pkgs.virtualbox</varname></term>
              <listitem><para>
                The VirtualBox virtual machine framework. Required by some BOINC
                projects, such as ATLAS@home.
              </para></listitem>
            </varlistentry>
            <varlistentry>
              <term><varname>pkgs.ocl-icd</varname></term>
              <listitem><para>
                OpenCL infrastructure library. Required by BOINC projects that
                use OpenCL, in addition to a device-specific OpenCL driver.
              </para></listitem>
            </varlistentry>
            <varlistentry>
              <term><varname>pkgs.linuxPackages.nvidia_x11</varname></term>
              <listitem><para>
                Provides CUDA libraries. Required by BOINC projects that use
                CUDA. Note that this requires an NVIDIA graphics device to be
                present on the system.
              </para><para>
                Also provides OpenCL drivers for NVIDIA GPUs;
                <varname>pkgs.ocl-icd</varname> is also needed in this case.
              </para></listitem>
            </varlistentry>
          </variablelist>
        '';
      };
    };

    config = mkIf cfg.enable {
      environment.systemPackages = [cfg.package];

      users.users.boinc = {
        createHome = false;
        description = "BOINC Client";
        home = cfg.dataDir;
        isSystemUser = true;
      };

      systemd.tmpfiles.rules = [
        "d '${cfg.dataDir}' - boinc - - -"
      ];

      systemd.services.boinc = {
        description = "BOINC Client";
        after = ["network.target" "local-fs.target"];
        wantedBy = ["multi-user.target"];
        script = ''
          ${fhsEnvExecutable} --dir ${cfg.dataDir} --redirectio ${allowRemoteGuiRpcFlag}
        '';
        serviceConfig = {
          User = "boinc";
          Nice = 10;
        };
      };
    };

    meta = {
      maintainers = with lib.maintainers; [kierdavis];
    };
  }