aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/services/misc/folding-at-home.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/nixos/modules/services/misc/folding-at-home.nix')
-rw-r--r--nixpkgs/nixos/modules/services/misc/folding-at-home.nix68
1 files changed, 68 insertions, 0 deletions
diff --git a/nixpkgs/nixos/modules/services/misc/folding-at-home.nix b/nixpkgs/nixos/modules/services/misc/folding-at-home.nix
new file mode 100644
index 00000000000..122c89ce068
--- /dev/null
+++ b/nixpkgs/nixos/modules/services/misc/folding-at-home.nix
@@ -0,0 +1,68 @@
+{ config, lib, pkgs, ... }:
+with lib;
+let
+ stateDir = "/var/lib/foldingathome";
+ cfg = config.services.foldingAtHome;
+ fahUser = "foldingathome";
+in {
+
+ ###### interface
+
+ options = {
+
+ 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 = ''
+ Extra configuration. Contents will be added verbatim to the
+ configuration file.
+ '';
+ };
+
+ };
+
+ };
+
+ ###### implementation
+
+ config = mkIf cfg.enable {
+
+ users.users = singleton
+ { name = fahUser;
+ uid = config.ids.uids.foldingathome;
+ description = "Folding@Home user";
+ home = stateDir;
+ };
+
+ systemd.services.foldingathome = {
+ after = [ "network.target" ];
+ wantedBy = [ "multi-user.target" ];
+ preStart = ''
+ mkdir -m 0755 -p ${stateDir}
+ chown ${fahUser} ${stateDir}
+ cp -f ${pkgs.writeText "client.cfg" cfg.config} ${stateDir}/client.cfg
+ '';
+ script = "${pkgs.su}/bin/su -s ${pkgs.runtimeShell} ${fahUser} -c 'cd ${stateDir}; ${pkgs.foldingathome}/bin/fah6'";
+ };
+
+ services.foldingAtHome.config = ''
+ [settings]
+ username=${cfg.nickname}
+ '';
+ };
+}