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.buildFHSEnv {
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 = lib.mdDoc ''
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 = literalExpression "pkgs.boinc";
34 example = literalExpression "pkgs.boinc-headless";
35 description = lib.mdDoc ''
36 Which BOINC package to use.
37 '';
38 };
39
40 dataDir = mkOption {
41 type = types.path;
42 default = "/var/lib/boinc";
43 description = lib.mdDoc ''
44 The directory in which to store BOINC's configuration and data files.
45 '';
46 };
47
48 allowRemoteGuiRpc = mkOption {
49 type = types.bool;
50 default = false;
51 description = lib.mdDoc ''
52 If set to true, any remote host can connect to and control this BOINC
53 client (subject to password authentication). If instead set to false,
54 only the hosts listed in {var}`dataDir`/remote_hosts.cfg will be allowed to
55 connect.
56
57 See also: <https://boinc.berkeley.edu/wiki/Controlling_BOINC_remotely#Remote_access>
58 '';
59 };
60
61 extraEnvPackages = mkOption {
62 type = types.listOf types.package;
63 default = [];
64 example = literalExpression "[ pkgs.virtualbox ]";
65 description = lib.mdDoc ''
66 Additional packages to make available in the environment in which
67 BOINC will run. Common choices are:
68
69 - {var}`pkgs.virtualbox`:
70 The VirtualBox virtual machine framework. Required by some BOINC
71 projects, such as ATLAS@home.
72 - {var}`pkgs.ocl-icd`:
73 OpenCL infrastructure library. Required by BOINC projects that
74 use OpenCL, in addition to a device-specific OpenCL driver.
75 - {var}`pkgs.linuxPackages.nvidia_x11`:
76 Provides CUDA libraries. Required by BOINC projects that use
77 CUDA. Note that this requires an NVIDIA graphics device to be
78 present on the system.
79
80 Also provides OpenCL drivers for NVIDIA GPUs;
81 {var}`pkgs.ocl-icd` is also needed in this case.
82 '';
83 };
84 };
85
86 config = mkIf cfg.enable {
87 environment.systemPackages = [cfg.package];
88
89 users.users.boinc = {
90 group = "boinc";
91 createHome = false;
92 description = "BOINC Client";
93 home = cfg.dataDir;
94 isSystemUser = true;
95 };
96 users.groups.boinc = {};
97
98 systemd.tmpfiles.rules = [
99 "d '${cfg.dataDir}' - boinc boinc - -"
100 ];
101
102 systemd.services.boinc = {
103 description = "BOINC Client";
104 after = ["network.target"];
105 wantedBy = ["multi-user.target"];
106 script = ''
107 ${fhsEnvExecutable} --dir ${cfg.dataDir} ${allowRemoteGuiRpcFlag}
108 '';
109 serviceConfig = {
110 User = "boinc";
111 Nice = 10;
112 };
113 };
114 };
115
116 meta = {
117 maintainers = with lib.maintainers; [kierdavis];
118 };
119 }