8 cfg = config.services.blendfarm;
9 json = pkgs.formats.json { };
10 configFile = json.generate "ServerSettings" (defaultConfig // cfg.serverConfig);
13 BroadcastPort = 16342;
14 BypassScriptUpdate = false;
15 BasicSecurityPassword = null;
19 meta.maintainers = with lib.maintainers; [ gador ];
21 options.services.blendfarm = with lib.types; {
22 enable = lib.mkEnableOption "Blendfarm, a render farm management software for Blender";
23 package = lib.mkPackageOption pkgs "blendfarm" { };
24 openFirewall = lib.mkEnableOption "allowing blendfarm network access through the firewall";
27 description = "User under which blendfarm runs.";
28 default = "blendfarm";
32 group = lib.mkOption {
33 description = "Group under which blendfarm runs.";
34 default = "blendfarm";
38 basicSecurityPasswordFile = lib.mkOption {
40 Path to the password file the client needs to connect to the server.
41 The password must not contain a forward slash.'';
46 blenderPackage = lib.mkPackageOption pkgs "blender" { };
48 serverConfig = lib.mkOption {
49 description = "Server configuration";
50 default = defaultConfig;
52 freeformType = attrsOf anything;
55 description = "Default port blendfarm server listens on.";
59 BroadcastPort = lib.mkOption {
60 description = "Default port blendfarm server advertises itself on.";
65 BypassScriptUpdate = lib.mkOption {
66 description = "Prevents blendfarm from replacing the .py self-generated scripts.";
75 config = lib.mkIf cfg.enable {
76 environment.systemPackages = [ cfg.package ];
77 networking.firewall = lib.optionalAttrs (cfg.openFirewall) {
78 allowedTCPPorts = [ cfg.serverConfig.Port ];
79 allowedUDPPorts = [ cfg.serverConfig.BroadcastPort ];
82 systemd.services.blendfarm-server = {
83 wantedBy = [ "multi-user.target" ];
84 after = [ "network-online.target" ];
85 wants = [ "network-online.target" ];
86 description = "blendfarm server";
87 path = [ cfg.blenderPackage ];
91 install -m640 ${configFile} ServerSettings
92 if [ ! -d "BlenderData/nix-blender-linux64" ]; then
93 mkdir -p BlenderData/nix-blender-linux64
94 echo "nix-blender" > VersionCustom
96 rm -f BlenderData/nix-blender-linux64/blender
97 ln -s ${lib.getExe cfg.blenderPackage} BlenderData/nix-blender-linux64/blender
99 + lib.optionalString (cfg.basicSecurityPasswordFile != null) ''
100 BLENDFARM_PASSWORD=$(${pkgs.systemd}/bin/systemd-creds cat BLENDFARM_PASS_FILE)
101 sed -i "s/null/\"$BLENDFARM_PASSWORD\"/g" ServerSettings
104 ExecStart = "${cfg.package}/bin/LogicReinc.BlendFarm.Server";
106 LogsDirectory = "blendfarm";
107 StateDirectory = "blendfarm";
108 WorkingDirectory = "/var/lib/blendfarm";
111 StateDirectoryMode = "0755";
112 LoadCredential = lib.optional (
113 cfg.basicSecurityPasswordFile != null
114 ) "BLENDFARM_PASS_FILE:${cfg.basicSecurityPasswordFile}";
116 CapabilityBoundingSet = "";
117 RestrictAddressFamilies = [
122 RestrictNamespaces = true;
123 PrivateDevices = true;
126 ProtectControlGroups = true;
128 ProtectKernelLogs = true;
129 ProtectKernelModules = true;
130 ProtectKernelTunables = true;
131 SystemCallArchitectures = "native";
137 RestrictRealtime = true;
138 LockPersonality = true;
140 ProtectHostname = true;
144 users.users.blendfarm = {
148 users.groups.blendfarm = { };