nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 cfg = config.services.foldingathome;
9
10 args = [
11 "--team"
12 "${toString cfg.team}"
13 ]
14 ++ lib.optionals (cfg.user != null) [
15 "--user"
16 cfg.user
17 ]
18 ++ cfg.extraArgs;
19in
20{
21 imports = [
22 (lib.mkRenamedOptionModule [ "services" "foldingAtHome" ] [ "services" "foldingathome" ])
23 (lib.mkRenamedOptionModule
24 [ "services" "foldingathome" "nickname" ]
25 [ "services" "foldingathome" "user" ]
26 )
27 (lib.mkRemovedOptionModule [ "services" "foldingathome" "config" ] ''
28 Use <literal>services.foldingathome.extraArgs instead<literal>
29 '')
30 ];
31 options.services.foldingathome = {
32 enable = lib.mkEnableOption "Folding@home client";
33
34 package = lib.mkPackageOption pkgs "fahclient" { };
35
36 user = lib.mkOption {
37 type = lib.types.nullOr lib.types.str;
38 default = null;
39 description = ''
40 The user associated with the reported computation results. This will
41 be used in the ranking statistics.
42 '';
43 };
44
45 team = lib.mkOption {
46 type = lib.types.int;
47 default = 236565;
48 description = ''
49 The team ID associated with the reported computation results. This
50 will be used in the ranking statistics.
51
52 By default, use the NixOS folding@home team ID is being used.
53 '';
54 };
55
56 daemonNiceLevel = lib.mkOption {
57 type = lib.types.ints.between (-20) 19;
58 default = 0;
59 description = ''
60 Daemon process priority for FAHClient.
61 0 is the default Unix process priority, 19 is the lowest.
62 '';
63 };
64
65 extraArgs = lib.mkOption {
66 type = lib.types.listOf lib.types.str;
67 default = [ ];
68 description = ''
69 Extra startup options for the FAHClient. Run
70 `fah-client --help` to find all the available options.
71 '';
72 };
73 };
74
75 config = lib.mkIf cfg.enable {
76 systemd.services.foldingathome = {
77 description = "Folding@home client";
78 after = [ "network.target" ];
79 wantedBy = [ "multi-user.target" ];
80 script = ''
81 exec ${lib.getExe cfg.package} ${lib.escapeShellArgs args}
82 '';
83 serviceConfig = {
84 DynamicUser = true;
85 StateDirectory = "foldingathome";
86 Nice = cfg.daemonNiceLevel;
87 WorkingDirectory = "%S/foldingathome";
88 };
89 };
90 };
91
92 meta = {
93 maintainers = with lib.maintainers; [ zimbatm ];
94 };
95}