From 54d97019c035ccccceb53fb8531d1bc8bea5816a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 22 May 2021 01:00:39 +0200 Subject: Add files for ressourcerie --- modules/private/websites/tools/cloud/farm.nix | 123 ++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 modules/private/websites/tools/cloud/farm.nix (limited to 'modules/private/websites/tools') 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 @@ +{ lib, pkgs, config, ... }: +let + cfg = config.myServices.tools.cloud.farm; + apacheUser = config.services.httpd.Prod.user; + apacheGroup = config.services.httpd.Prod.group; + nextcloud = (pkgs.webapps.nextcloud.override { varDir = null; }).withApps (a: [ + a.apporder a.audioplayer a.bookmarks a.calendar a.carnet a.contacts + a.cookbook a.deck a.extract a.files_markdown a.files_readmemd + a.flowupload a.gpxedit a.gpxpod a.impersonate a.keeweb a.maps + a.metadata a.music a.notes a.ocsms a.passman a.polls a.spreed + a.tasks + ]); + toVardir = name: "/var/lib/nextcloud_farm/${name}"; + varDirs = map toVardir cfg.instances; + phpBaseDir = builtins.concatStringsSep ":" ([ nextcloud ] ++ varDirs ++ nextcloud.apps); + toVhost = name: '' + SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 + SetEnv NEXTCLOUD_CONFIG_DIR "${toVardir name}" + + AcceptPathInfo On + DirectoryIndex index.php + Options FollowSymlinks + Require all granted + AllowOverride all + + + Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload" + + + CGIPassAuth on + SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud_farm.socket}|fcgi://localhost" + + + + ''; +in +{ + options.myServices.tools.cloud.farm = { + instances = lib.mkOption { + description = "Instances names for the nextcloud Farm"; + default = []; + type = lib.types.listOf lib.types.str; + }; + vhosts = lib.mkOption { + description = "Instance vhosts configs"; + readOnly = true; + type = lib.types.attrsOf lib.types.str; + default = lib.genAttrs cfg.instances toVhost; + }; + package = lib.mkOption { + description = "Nextcloud derivation"; + readOnly = true; + type = lib.types.package; + default = nextcloud; + }; + }; + + config = lib.mkIf (builtins.length cfg.instances > 0) { + system.activationScripts.cloud_farm_vardirs = { + deps = [ "httpd" ]; + text = '' + install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${builtins.concatStringsSep " " varDirs} + install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d /var/lib/nextcloud_farm/phpSessions + ''; + }; + systemd.services.phpfpm-nextcloud_farm.after = lib.mkAfter [ "postgresql.service" ]; + systemd.services.phpfpm-nextcloud_farm.wants = [ "postgresql.service" ]; + services.phpfpm.pools.nextcloud_farm = { + user = apacheUser; + group = apacheGroup; + settings = { + "listen.owner" = apacheUser; + "listen.group" = apacheGroup; + "pm" = "ondemand"; + "pm.max_children" = "60"; + "pm.process_idle_timeout" = "60"; + + "php_admin_value[output_buffering]" = "0"; + "php_admin_value[max_execution_time]" = "1800"; + "php_admin_value[zend_extension]" = "opcache"; + #already enabled by default? + #"php_value[opcache.enable]" = "1"; + "php_value[opcache.enable_cli]" = "1"; + "php_value[opcache.interned_strings_buffer]" = "8"; + "php_value[opcache.max_accelerated_files]" = "10000"; + "php_value[opcache.memory_consumption]" = "128"; + "php_value[opcache.save_comments]" = "1"; + "php_value[opcache.revalidate_freq]" = "1"; + "php_admin_value[memory_limit]" = "512M"; + + "php_admin_value[open_basedir]" = "/run/wrappers/bin/sendmail:${phpBaseDir}:/proc/meminfo:/dev/urandom:/proc/self/fd:/tmp"; + "php_admin_value[session.save_path]" = "/var/lib/nextcloud_farm/phpSessions"; + }; + phpPackage = pkgs.php74.withExtensions({ enabled, all }: enabled ++ [ all.redis all.apcu all.opcache ]); + }; + users.users.root.packages = let + toOcc = name: pkgs.writeScriptBin "nextcloud-occ-${name}" '' + #! ${pkgs.stdenv.shell} + cd ${nextcloud} + NEXTCLOUD_CONFIG_DIR="${toVardir name}" \ + exec \ + sudo -E -u wwwrun ${pkgs.php74}/bin/php \ + -c ${pkgs.php74}/etc/php.ini \ + occ $* + ''; + in map toOcc cfg.instances; + services.cron = { + enable = true; + systemCronJobs = let + toScript = name: pkgs.writeScriptBin "nextcloud-cron" '' + #! ${pkgs.stdenv.shell} + export LOCALE_ARCHIVE=/run/current-system/sw/lib/locale/locale-archive + export PATH=/run/wrappers/bin:$PATH + export NEXTCLOUD_CONFIG_DIR="${toVardir name}" + ${pkgs.php74}/bin/php -d memory_limit=512M -f ${nextcloud}/cron.php + ''; + toLine = name: '' + */15 * * * * wwwrun ${toScript name}/bin/nextcloud-cron + ''; + in map toLine cfg.instances; + }; + }; +} -- cgit v1.2.3