2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
2010-09-16 04:06:44 +02:00
|
|
|
let
|
|
|
|
stateDir = "/var/lib/foldingathome";
|
|
|
|
cfg = config.services.foldingAtHome;
|
|
|
|
fahUser = "foldingathome";
|
|
|
|
in {
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-09-16 04:06:44 +02:00
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2010-09-16 04:06:44 +02:00
|
|
|
services.foldingAtHome = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable the Folding@Home to use idle CPU time.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
nickname = mkOption {
|
|
|
|
default = "Anonymous";
|
|
|
|
description = ''
|
|
|
|
A unique handle for statistics.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
2011-09-14 20:20:50 +02:00
|
|
|
Extra configuration. Contents will be added verbatim to the
|
2010-09-16 04:06:44 +02:00
|
|
|
configuration file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users = singleton
|
2010-09-16 04:06:44 +02:00
|
|
|
{ name = fahUser;
|
2014-04-29 10:51:42 +02:00
|
|
|
uid = config.ids.uids.foldingathome;
|
2010-09-16 04:06:44 +02:00
|
|
|
description = "Folding@Home user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
|
|
|
|
2016-01-06 07:50:18 +01:00
|
|
|
systemd.services.foldingathome = {
|
2016-09-10 20:11:58 +02:00
|
|
|
after = [ "network.target" ];
|
2016-01-06 07:50:18 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
preStart = ''
|
|
|
|
mkdir -m 0755 -p ${stateDir}
|
|
|
|
chown ${fahUser} ${stateDir}
|
|
|
|
cp -f ${pkgs.writeText "client.cfg" cfg.config} ${stateDir}/client.cfg
|
2010-09-16 04:06:44 +02:00
|
|
|
'';
|
2018-03-01 20:38:53 +01:00
|
|
|
script = "${pkgs.su}/bin/su -s ${pkgs.runtimeShell} ${fahUser} -c 'cd ${stateDir}; ${pkgs.foldingathome}/bin/fah6'";
|
2016-01-06 07:50:18 +01:00
|
|
|
};
|
2010-09-16 04:06:44 +02:00
|
|
|
|
2016-01-06 07:50:18 +01:00
|
|
|
services.foldingAtHome.config = ''
|
|
|
|
[settings]
|
|
|
|
username=${cfg.nickname}
|
|
|
|
'';
|
2010-09-16 04:06:44 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
}
|