diff options
Diffstat (limited to 'modules/private/websites/tools')
-rw-r--r-- | modules/private/websites/tools/cloud/farm.nix | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/modules/private/websites/tools/cloud/farm.nix b/modules/private/websites/tools/cloud/farm.nix new file mode 100644 index 0000000..7be774c --- /dev/null +++ b/modules/private/websites/tools/cloud/farm.nix | |||
@@ -0,0 +1,123 @@ | |||
1 | { lib, pkgs, config, ... }: | ||
2 | let | ||
3 | cfg = config.myServices.tools.cloud.farm; | ||
4 | apacheUser = config.services.httpd.Prod.user; | ||
5 | apacheGroup = config.services.httpd.Prod.group; | ||
6 | nextcloud = (pkgs.webapps.nextcloud.override { varDir = null; }).withApps (a: [ | ||
7 | a.apporder a.audioplayer a.bookmarks a.calendar a.carnet a.contacts | ||
8 | a.cookbook a.deck a.extract a.files_markdown a.files_readmemd | ||
9 | a.flowupload a.gpxedit a.gpxpod a.impersonate a.keeweb a.maps | ||
10 | a.metadata a.music a.notes a.ocsms a.passman a.polls a.spreed | ||
11 | a.tasks | ||
12 | ]); | ||
13 | toVardir = name: "/var/lib/nextcloud_farm/${name}"; | ||
14 | varDirs = map toVardir cfg.instances; | ||
15 | phpBaseDir = builtins.concatStringsSep ":" ([ nextcloud ] ++ varDirs ++ nextcloud.apps); | ||
16 | toVhost = name: '' | ||
17 | SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 | ||
18 | SetEnv NEXTCLOUD_CONFIG_DIR "${toVardir name}" | ||
19 | <Directory ${nextcloud}> | ||
20 | AcceptPathInfo On | ||
21 | DirectoryIndex index.php | ||
22 | Options FollowSymlinks | ||
23 | Require all granted | ||
24 | AllowOverride all | ||
25 | |||
26 | <IfModule mod_headers.c> | ||
27 | Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload" | ||
28 | </IfModule> | ||
29 | <FilesMatch "\.php$"> | ||
30 | CGIPassAuth on | ||
31 | SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud_farm.socket}|fcgi://localhost" | ||
32 | </FilesMatch> | ||
33 | |||
34 | </Directory> | ||
35 | ''; | ||
36 | in | ||
37 | { | ||
38 | options.myServices.tools.cloud.farm = { | ||
39 | instances = lib.mkOption { | ||
40 | description = "Instances names for the nextcloud Farm"; | ||
41 | default = []; | ||
42 | type = lib.types.listOf lib.types.str; | ||
43 | }; | ||
44 | vhosts = lib.mkOption { | ||
45 | description = "Instance vhosts configs"; | ||
46 | readOnly = true; | ||
47 | type = lib.types.attrsOf lib.types.str; | ||
48 | default = lib.genAttrs cfg.instances toVhost; | ||
49 | }; | ||
50 | package = lib.mkOption { | ||
51 | description = "Nextcloud derivation"; | ||
52 | readOnly = true; | ||
53 | type = lib.types.package; | ||
54 | default = nextcloud; | ||
55 | }; | ||
56 | }; | ||
57 | |||
58 | config = lib.mkIf (builtins.length cfg.instances > 0) { | ||
59 | system.activationScripts.cloud_farm_vardirs = { | ||
60 | deps = [ "httpd" ]; | ||
61 | text = '' | ||
62 | install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${builtins.concatStringsSep " " varDirs} | ||
63 | install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d /var/lib/nextcloud_farm/phpSessions | ||
64 | ''; | ||
65 | }; | ||
66 | systemd.services.phpfpm-nextcloud_farm.after = lib.mkAfter [ "postgresql.service" ]; | ||
67 | systemd.services.phpfpm-nextcloud_farm.wants = [ "postgresql.service" ]; | ||
68 | services.phpfpm.pools.nextcloud_farm = { | ||
69 | user = apacheUser; | ||
70 | group = apacheGroup; | ||
71 | settings = { | ||
72 | "listen.owner" = apacheUser; | ||
73 | "listen.group" = apacheGroup; | ||
74 | "pm" = "ondemand"; | ||
75 | "pm.max_children" = "60"; | ||
76 | "pm.process_idle_timeout" = "60"; | ||
77 | |||
78 | "php_admin_value[output_buffering]" = "0"; | ||
79 | "php_admin_value[max_execution_time]" = "1800"; | ||
80 | "php_admin_value[zend_extension]" = "opcache"; | ||
81 | #already enabled by default? | ||
82 | #"php_value[opcache.enable]" = "1"; | ||
83 | "php_value[opcache.enable_cli]" = "1"; | ||
84 | "php_value[opcache.interned_strings_buffer]" = "8"; | ||
85 | "php_value[opcache.max_accelerated_files]" = "10000"; | ||
86 | "php_value[opcache.memory_consumption]" = "128"; | ||
87 | "php_value[opcache.save_comments]" = "1"; | ||
88 | "php_value[opcache.revalidate_freq]" = "1"; | ||
89 | "php_admin_value[memory_limit]" = "512M"; | ||
90 | |||
91 | "php_admin_value[open_basedir]" = "/run/wrappers/bin/sendmail:${phpBaseDir}:/proc/meminfo:/dev/urandom:/proc/self/fd:/tmp"; | ||
92 | "php_admin_value[session.save_path]" = "/var/lib/nextcloud_farm/phpSessions"; | ||
93 | }; | ||
94 | phpPackage = pkgs.php74.withExtensions({ enabled, all }: enabled ++ [ all.redis all.apcu all.opcache ]); | ||
95 | }; | ||
96 | users.users.root.packages = let | ||
97 | toOcc = name: pkgs.writeScriptBin "nextcloud-occ-${name}" '' | ||
98 | #! ${pkgs.stdenv.shell} | ||
99 | cd ${nextcloud} | ||
100 | NEXTCLOUD_CONFIG_DIR="${toVardir name}" \ | ||
101 | exec \ | ||
102 | sudo -E -u wwwrun ${pkgs.php74}/bin/php \ | ||
103 | -c ${pkgs.php74}/etc/php.ini \ | ||
104 | occ $* | ||
105 | ''; | ||
106 | in map toOcc cfg.instances; | ||
107 | services.cron = { | ||
108 | enable = true; | ||
109 | systemCronJobs = let | ||
110 | toScript = name: pkgs.writeScriptBin "nextcloud-cron" '' | ||
111 | #! ${pkgs.stdenv.shell} | ||
112 | export LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive | ||
113 | export PATH=/run/wrappers/bin:$PATH | ||
114 | export NEXTCLOUD_CONFIG_DIR="${toVardir name}" | ||
115 | ${pkgs.php74}/bin/php -d memory_limit=512M -f ${nextcloud}/cron.php | ||
116 | ''; | ||
117 | toLine = name: '' | ||
118 | */15 * * * * wwwrun ${toScript name}/bin/nextcloud-cron | ||
119 | ''; | ||
120 | in map toLine cfg.instances; | ||
121 | }; | ||
122 | }; | ||
123 | } | ||