7 cfg = config.services.blendfarm;
8 json = pkgs.formats.json { };
9 configFile = json.generate "ServerSettings" (defaultConfig // cfg.serverConfig);
12 BroadcastPort = 16342;
13 BypassScriptUpdate = false;
14 BasicSecurityPassword = null;
18 meta.maintainers = with lib.maintainers; [ gador ];
20 options.services.blendfarm = with lib.types; {
21 enable = lib.mkEnableOption "Blendfarm, a render farm management software for Blender";
22 package = lib.mkPackageOption pkgs "blendfarm" { };
23 openFirewall = lib.mkEnableOption "allowing blendfarm network access through the firewall";
26 description = "User under which blendfarm runs.";
27 default = "blendfarm";
31 group = lib.mkOption {
32 description = "Group under which blendfarm runs.";
33 default = "blendfarm";
37 basicSecurityPasswordFile = lib.mkOption {
38 description = ''Path to the password file the client needs to connect to the server.
39 The password must not contain a forward slash.'';
44 blenderPackage = lib.mkPackageOption pkgs "blender" { };
46 serverConfig = lib.mkOption {
47 description = "Server configuration";
48 default = defaultConfig;
50 freeformType = attrsOf anything;
53 description = "Default port blendfarm server listens on.";
57 BroadcastPort = lib.mkOption {
58 description = "Default port blendfarm server advertises itself on.";
63 BypassScriptUpdate = lib.mkOption {
64 description = "Prevents blendfarm from replacing the .py self-generated scripts.";
73 config = lib.mkIf cfg.enable {
74 environment.systemPackages = [ cfg.package ];
75 networking.firewall = lib.optionalAttrs (cfg.openFirewall) {
76 allowedTCPPorts = [ cfg.serverConfig.Port ];
77 allowedUDPPorts = [ cfg.serverConfig.BroadcastPort ];
80 systemd.services.blendfarm-server = {
81 wantedBy = [ "multi-user.target" ];
82 after = [ "network-online.target" ];
83 wants = [ "network-online.target" ];
84 description = "blendfarm server";
85 path = [ cfg.blenderPackage ];
88 install -m640 ${configFile} ServerSettings
89 if [ ! -d "BlenderData/nix-blender-linux64" ]; then
90 mkdir -p BlenderData/nix-blender-linux64
91 echo "nix-blender" > VersionCustom
93 rm -f BlenderData/nix-blender-linux64/blender
94 ln -s ${lib.getExe cfg.blenderPackage} BlenderData/nix-blender-linux64/blender
96 lib.optionalString (cfg.basicSecurityPasswordFile != null) ''
97 BLENDFARM_PASSWORD=$(${pkgs.systemd}/bin/systemd-creds cat BLENDFARM_PASS_FILE)
98 sed -i "s/null/\"$BLENDFARM_PASSWORD\"/g" ServerSettings
101 ExecStart = "${cfg.package}/bin/LogicReinc.BlendFarm.Server";
103 LogsDirectory = "blendfarm";
104 StateDirectory = "blendfarm";
105 WorkingDirectory = "/var/lib/blendfarm";
108 StateDirectoryMode = "0755";
109 LoadCredential = lib.optional (cfg.basicSecurityPasswordFile != null) "BLENDFARM_PASS_FILE:${cfg.basicSecurityPasswordFile}";
111 CapabilityBoundingSet = "";
112 RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
113 RestrictNamespaces = true;
114 PrivateDevices = true;
117 ProtectControlGroups = true;
119 ProtectKernelLogs = true;
120 ProtectKernelModules = true;
121 ProtectKernelTunables = true;
122 SystemCallArchitectures = "native";
128 RestrictRealtime = true;
129 LockPersonality = true;
131 ProtectHostname = true;
135 users.users.blendfarm = {
139 users.groups.blendfarm = { };