1{config, lib, pkgs, ...}:
2
3with lib;
4
5let
6 cfg = config.services.boinc;
7 allowRemoteGuiRpcFlag = optionalString cfg.allowRemoteGuiRpc "--allow_remote_gui_rpc";
8
9 fhsEnv = pkgs.buildFHSUserEnv {
10 name = "boinc-fhs-env";
11 targetPkgs = pkgs': [ cfg.package ] ++ cfg.extraEnvPackages;
12 runScript = "/bin/boinc_client";
13 };
14 fhsEnvExecutable = "${fhsEnv}/bin/${fhsEnv.name}";
15
16in
17 {
18 options.services.boinc = {
19 enable = mkOption {
20 type = types.bool;
21 default = false;
22 description = ''
23 Whether to enable the BOINC distributed computing client. If this
24 option is set to true, the boinc_client daemon will be run as a
25 background service. The boinccmd command can be used to control the
26 daemon.
27 '';
28 };
29
30 package = mkOption {
31 type = types.package;
32 default = pkgs.boinc;
33 defaultText = "pkgs.boinc";
34 description = ''
35 Which BOINC package to use.
36 '';
37 };
38
39 dataDir = mkOption {
40 type = types.path;
41 default = "/var/lib/boinc";
42 description = ''
43 The directory in which to store BOINC's configuration and data files.
44 '';
45 };
46
47 allowRemoteGuiRpc = mkOption {
48 type = types.bool;
49 default = false;
50 description = ''
51 If set to true, any remote host can connect to and control this BOINC
52 client (subject to password authentication). If instead set to false,
53 only the hosts listed in <varname>dataDir</varname>/remote_hosts.cfg will be allowed to
54 connect.
55
56 See also: <link xlink:href="http://boinc.berkeley.edu/wiki/Controlling_BOINC_remotely#Remote_access"/>
57 '';
58 };
59
60 extraEnvPackages = mkOption {
61 type = types.listOf types.package;
62 default = [];
63 example = "[ pkgs.virtualbox ]";
64 description = ''
65 Additional packages to make available in the environment in which
66 BOINC will run. Common choices are:
67 <variablelist>
68 <varlistentry>
69 <term><varname>pkgs.virtualbox</varname></term>
70 <listitem><para>
71 The VirtualBox virtual machine framework. Required by some BOINC
72 projects, such as ATLAS@home.
73 </para></listitem>
74 </varlistentry>
75 <varlistentry>
76 <term><varname>pkgs.ocl-icd</varname></term>
77 <listitem><para>
78 OpenCL infrastructure library. Required by BOINC projects that
79 use OpenCL, in addition to a device-specific OpenCL driver.
80 </para></listitem>
81 </varlistentry>
82 <varlistentry>
83 <term><varname>pkgs.linuxPackages.nvidia_x11</varname></term>
84 <listitem><para>
85 Provides CUDA libraries. Required by BOINC projects that use
86 CUDA. Note that this requires an NVIDIA graphics device to be
87 present on the system.
88 </para><para>
89 Also provides OpenCL drivers for NVIDIA GPUs;
90 <varname>pkgs.ocl-icd</varname> is also needed in this case.
91 </para></listitem>
92 </varlistentry>
93 </variablelist>
94 '';
95 };
96 };
97
98 config = mkIf cfg.enable {
99 environment.systemPackages = [cfg.package];
100
101 users.users.boinc = {
102 createHome = false;
103 description = "BOINC Client";
104 home = cfg.dataDir;
105 isSystemUser = true;
106 };
107
108 systemd.services.boinc = {
109 description = "BOINC Client";
110 after = ["network.target" "local-fs.target"];
111 wantedBy = ["multi-user.target"];
112 preStart = ''
113 mkdir -p ${cfg.dataDir}
114 chown boinc ${cfg.dataDir}
115 '';
116 script = ''
117 ${fhsEnvExecutable} --dir ${cfg.dataDir} --redirectio ${allowRemoteGuiRpcFlag}
118 '';
119 serviceConfig = {
120 PermissionsStartOnly = true; # preStart must be run as root
121 User = "boinc";
122 Nice = 10;
123 };
124 };
125 };
126
127 meta = {
128 maintainers = with lib.maintainers; [kierdavis];
129 };
130 }