]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/websites/tools/kanboard/farm.nix
Remove old domains from ressourcerie
[perso/Immae/Config/Nix.git] / modules / private / websites / tools / kanboard / farm.nix
1 { lib, pkgs, config, ... }:
2 let
3 cfg = config.myServices.tools.kanboard.farm;
4 apacheUser = config.services.httpd.Tools.user;
5 apacheGroup = config.services.httpd.Tools.group;
6 toVardir = name: "/var/lib/kanboard_farm/${name}";
7 varDirs = lib.mapAttrsToList (name: v: toVardir name) cfg.instances;
8 toPhpBaseDir = name: [ rootDir (toVardir name) ];
9 phpBaseDir = builtins.concatStringsSep ":" (lib.unique (lib.flatten (lib.mapAttrsToList (name: v: toPhpBaseDir name) cfg.instances)));
10 rootDir = pkgs.kanboard;
11
12 toVhost = name: ''
13 Alias /${name} "${rootDir}"
14 <Location /${name}>
15 SetEnv DATA_DIR "${toVardir name}"
16 SetEnv MAIL_FROM "kanboard@tools.immae.eu"
17 </Location>
18 '';
19 phpPackage = pkgs.php74;
20 in
21 {
22 options.myServices.tools.kanboard.farm = {
23 instances = lib.mkOption {
24 description = "Instances names for the kanboard Farm";
25 default = {};
26 type = lib.types.attrsOf (lib.types.submodule {
27 options = {};
28 });
29 };
30 vhosts = lib.mkOption {
31 description = "Instance vhosts configs";
32 readOnly = true;
33 type = lib.types.attrsOf lib.types.str;
34 default = lib.mapAttrs (name: v: toVhost name) cfg.instances;
35 };
36 };
37
38 config = lib.mkIf (builtins.length (builtins.attrNames cfg.instances) > 0) {
39 system.activationScripts.kanboard_farm_vardirs = {
40 deps = [ "httpd" ];
41 text = ''
42 install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${builtins.concatStringsSep " " varDirs}
43 install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d /var/lib/kanboard_farm/phpSessions
44 '';
45 };
46 services.phpfpm.pools.kanboard_farm = {
47 user = apacheUser;
48 group = apacheGroup;
49 settings = let
50 instanceNb = builtins.length (builtins.attrNames cfg.instances);
51 in {
52 "listen.owner" = apacheUser;
53 "listen.group" = apacheGroup;
54 "pm" = "dynamic";
55 "pm.max_children" = builtins.toString (60 * instanceNb);
56 "pm.start_servers" = builtins.toString (2 * instanceNb);
57 "pm.min_spare_servers" = builtins.toString (2 * instanceNb);
58 "pm.max_spare_servers" = builtins.toString (3 * instanceNb);
59 "pm.process_idle_timeout" = "60";
60
61 "php_admin_value[output_buffering]" = "0";
62 "php_admin_value[max_execution_time]" = "1800";
63 "php_admin_value[zend_extension]" = "opcache";
64 "php_value[apcu.enable_cli]" = "1";
65 "php_value[apcu.enabled]" = "1";
66 #already enabled by default?
67 #"php_value[opcache.enable]" = "1";
68 "php_value[opcache.enable_cli]" = "1";
69 "php_value[opcache.interned_strings_buffer]" = "8";
70 "php_value[opcache.max_accelerated_files]" = "10000";
71 "php_value[opcache.memory_consumption]" = "128";
72 "php_value[opcache.save_comments]" = "1";
73 "php_value[opcache.revalidate_freq]" = "1";
74 "php_admin_value[memory_limit]" = "512M";
75
76 "php_admin_value[open_basedir]" = "/run/wrappers/bin/sendmail:${phpBaseDir}:/proc/meminfo:/dev/urandom:/proc/self/fd:/tmp";
77 "php_admin_value[session.save_path]" = "/var/lib/kanboard_farm/phpSessions";
78 };
79 inherit phpPackage;
80 };
81 services.websites.env.tools.vhostConfs.kanboard = {
82 certName = "eldiron";
83 addToCerts = true;
84 hosts = ["kanboard.immae.eu"];
85 root = null;
86 extraConfig = [
87 ''
88 <Directory "${rootDir}">
89 DirectoryIndex index.php
90 AllowOverride All
91 Options FollowSymlinks
92 Require all granted
93
94 <FilesMatch "\.php$">
95 SetHandler "proxy:unix:${config.services.phpfpm.pools.kanboard_farm.socket}|fcgi://localhost"
96 </FilesMatch>
97 </Directory>
98 <DirectoryMatch "${rootDir}/data">
99 Require all denied
100 </DirectoryMatch>
101 ''
102 ] ++ builtins.attrValues cfg.vhosts;
103 };
104 };
105 }