]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Add files for ressourcerie
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 21 May 2021 23:00:39 +0000 (01:00 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Fri, 21 May 2021 23:00:39 +0000 (01:00 +0200)
modules/private/default.nix
modules/private/websites/bakeer/cloud.nix
modules/private/websites/default.nix
modules/private/websites/ressourcerie_banon/cloud.nix [new file with mode: 0644]
modules/private/websites/ressourcerie_banon/cryptpad.nix [new file with mode: 0644]
modules/private/websites/ressourcerie_banon/production.nix [new file with mode: 0644]
modules/private/websites/tools/cloud/farm.nix [new file with mode: 0644]

index 8542e209c9c4f1ca592a012760ae0d7ddc431bc9..f12fc4812468f90b6733fdfe285dda5a4e61aec7 100644 (file)
@@ -71,6 +71,10 @@ set = {
   piedsjalouxInte = ./websites/piedsjaloux/integration.nix;
   piedsjalouxProd = ./websites/piedsjaloux/production.nix;
 
+  ressourcerieBanonProd = ./websites/ressourcerie_banon/production.nix;
+  ressourcerieBanonCloud = ./websites/ressourcerie_banon/cloud.nix;
+  ressourcerieBanonCryptpad = ./websites/ressourcerie_banon/cryptpad.nix;
+
   richieProd = ./websites/richie/production.nix;
 
   sydenPeertube = ./websites/syden/peertube.nix;
@@ -80,6 +84,7 @@ set = {
   # Tools
   assetsTools = ./websites/tools/assets;
   cloudTool = ./websites/tools/cloud;
+  cloudFarmTool = ./websites/tools/cloud/farm.nix;
   commentoTool = ./websites/tools/commento;
   davTool = ./websites/tools/dav;
   vpnTool = ./websites/tools/vpn;
index 001ca0355f241cb4d106751e096fb2dbce0645b2..bf78317ff9b37b47a119d450db03163940707128 100644 (file)
@@ -1,69 +1,12 @@
 { lib, pkgs, config,  ... }:
 let
   cfg = config.myServices.websites.bakeer.cloud;
-  varDir = "/var/lib/nextcloud_farm/bakeer";
-  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
-  ]);
-  phpBaseDir = builtins.concatStringsSep ":" ([ nextcloud varDir ] ++ nextcloud.apps);
+  nextcloud = config.myServices.tools.cloud.farm.package;
 in {
   options.myServices.websites.bakeer.cloud.enable = lib.mkEnableOption "enable Bakeer’s cloud";
 
   config = lib.mkIf cfg.enable {
-    system.activationScripts.bakeer_cloud = {
-      deps = [ "httpd" ];
-      text = ''
-        install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${varDir}
-        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
-      occ = pkgs.writeScriptBin "nextcloud-occ-bakeer" ''
-        #! ${pkgs.stdenv.shell}
-        cd ${nextcloud}
-        NEXTCLOUD_CONFIG_DIR="${varDir}" \
-          exec \
-          sudo -E -u wwwrun ${pkgs.php74}/bin/php \
-          -c ${pkgs.php74}/etc/php.ini \
-          occ $*
-        '';
-    in [ occ ];
+    myServices.tools.cloud.farm.instances = [ "bakeer" ];
     services.websites.env.production.modules = [ "proxy_fcgi" ];
     services.websites.env.production.vhostConfs.bakeer = {
       certName     = "bakeer";
@@ -72,42 +15,7 @@ in {
       hosts        = ["bakeer.immae.eu" "baxsolution.immae.eu"];
       root         = nextcloud;
       extraConfig  = [
-        ''
-          SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
-          SetEnv NEXTCLOUD_CONFIG_DIR "${varDir}"
-          <Directory ${nextcloud}>
-            AcceptPathInfo On
-            DirectoryIndex index.php
-            Options FollowSymlinks
-            Require all granted
-            AllowOverride all
-
-            <IfModule mod_headers.c>
-              Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
-            </IfModule>
-            <FilesMatch "\.php$">
-              CGIPassAuth on
-              SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud_farm.socket}|fcgi://localhost"
-            </FilesMatch>
-
-          </Directory>
-          ''
-      ];
-    };
-    services.cron = {
-      enable = true;
-      systemCronJobs = let
-        script = 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="${varDir}"
-          ${pkgs.php74}/bin/php -d memory_limit=512M -f ${nextcloud}/cron.php
-          '';
-      in [
-        ''
-          */15 * * * * wwwrun ${script}/bin/nextcloud-cron
-        ''
+        config.myServices.tools.cloud.farm.vhosts.bakeer
       ];
     };
   };
index bacfb53c073ba4662be2b26ea622b3567da93ccc..b0c7496db20344a695ea8b632aa34e8945f16e6b 100644 (file)
@@ -292,6 +292,10 @@ in
         production.enable = true;
       };
 
+      ressourcerie_banon.production.enable = true;
+      ressourcerie_banon.cryptpad.enable = true;
+      ressourcerie_banon.cloud.enable = true;
+
       richie.production.enable = true;
 
       syden.peertube.enable = true;
diff --git a/modules/private/websites/ressourcerie_banon/cloud.nix b/modules/private/websites/ressourcerie_banon/cloud.nix
new file mode 100644 (file)
index 0000000..5179218
--- /dev/null
@@ -0,0 +1,20 @@
+{ lib, pkgs, config,  ... }:
+let
+  cfg = config.myServices.websites.ressourcerie_banon.cloud;
+  nextcloud = config.myServices.tools.cloud.farm.package;
+in {
+  options.myServices.websites.ressourcerie_banon.cloud.enable = lib.mkEnableOption "enable Ressourcerie Banon’s cloud";
+
+  config = lib.mkIf cfg.enable {
+    myServices.tools.cloud.farm.instances = [ "ressourcerie_banon" ];
+    services.websites.env.production.modules = [ "proxy_fcgi" ];
+    services.websites.env.production.vhostConfs.ressourcerie_banon_cloud = {
+      certName     = "ressourcerie_banon";
+      addToCerts   = true;
+      hosts        = ["cloud.le-garage-autonome.org"];
+      root         = nextcloud;
+      extraConfig  = [ config.myServices.tools.cloud.farm.vhosts.ressourcerie_banon ];
+    };
+  };
+}
+
diff --git a/modules/private/websites/ressourcerie_banon/cryptpad.nix b/modules/private/websites/ressourcerie_banon/cryptpad.nix
new file mode 100644 (file)
index 0000000..961302d
--- /dev/null
@@ -0,0 +1,33 @@
+{ lib, pkgs, config, ... }:
+let
+  cfg = config.myServices.websites.ressourcerie_banon.cryptpad;
+  configFile = "${pkgs.cryptpad}/lib/node_modules/cryptpad/config/config.example.js";
+in {
+  options.myServices.websites.ressourcerie_banon.cryptpad.enable = lib.mkEnableOption "Enable Ressourcerie Banon’s cryptpad";
+
+  config = lib.mkIf cfg.enable {
+    systemd.services.cryptpad-ressourcerie_banon = {
+      description = "Cryptpad Banon Service";
+      wantedBy = [ "multi-user.target" ];
+      after = [ "networking.target" ];
+      serviceConfig = {
+        DynamicUser = true;
+        Environment = [
+          "CRYPTPAD_CONFIG=${configFile}"
+          "HOME=%S/cryptpad/ressourcerie_banon"
+        ];
+        ExecStart = "${pkgs.cryptpad}/bin/cryptpad";
+        PrivateTmp = true;
+        Restart = "always";
+        StateDirectory = "cryptpad/ressourcerie_banon";
+        WorkingDirectory = "%S/cryptpad/ressourcerie_banon";
+      };
+    };
+    services.websites.env.production.vhostConfs.ressourcerie_banon_cryptpad = {
+      certName = "ressourcerie_banon";
+      addToCerts = true;
+      hosts = ["pad.le-garage-autonome.org"];
+      root = null;
+    };
+  };
+}
diff --git a/modules/private/websites/ressourcerie_banon/production.nix b/modules/private/websites/ressourcerie_banon/production.nix
new file mode 100644 (file)
index 0000000..fa00d92
--- /dev/null
@@ -0,0 +1,70 @@
+{ lib, pkgs, config,  ... }:
+let
+  cfg = config.myServices.websites.ressourcerie_banon.production;
+  varDir = "/var/lib/ftp/ressourcerie_banon";
+  apacheUser = config.services.httpd.Prod.user;
+  apacheGroup = config.services.httpd.Prod.group;
+in {
+  options.myServices.websites.ressourcerie_banon.production.enable = lib.mkEnableOption "enable Ressourcerie Banon's website";
+
+  config = lib.mkIf cfg.enable {
+    services.webstats.sites = [ { name = "ressourcerie-banon.org"; } ];
+
+    system.activationScripts.ressourcerie_banon = {
+      deps = [ "httpd" ];
+      text = ''
+        install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d /var/lib/php/sessions/ressourcerie_banon
+        '';
+    };
+    systemd.services.phpfpm-ressourcerie_banon.after = lib.mkAfter [ "mysql.service" ];
+    systemd.services.phpfpm-ressourcerie_banon.wants = [ "mysql.service" ];
+    services.phpfpm.pools.ressourcerie_banon = {
+      user = apacheUser;
+      group = apacheGroup;
+      settings = {
+        "listen.owner" = apacheUser;
+        "listen.group" = apacheGroup;
+
+        "pm" = "ondemand";
+        "pm.max_children" = "5";
+        "pm.process_idle_timeout" = "60";
+
+        "php_admin_value[open_basedir]" = "/var/lib/php/sessions/ressourcerie_banon:${varDir}:/tmp";
+        "php_admin_value[session.save_path]" = "/var/lib/php/sessions/ressourcerie_banon";
+      };
+      phpOptions = config.services.phpfpm.phpOptions + ''
+        disable_functions = "mail"
+      '';
+      phpPackage = pkgs.php72;
+    };
+    services.websites.env.production.modules = [ "proxy_fcgi" ];
+    services.websites.env.production.vhostConfs.ressourcerie_banon = {
+      certName     = "ressourcerie_banon";
+      certMainHost = "ressourcerie-banon.org";
+      hosts        = ["ressourcerie-banon.org" "www.ressourcerie-banon.org" "ressourcerie-sault.org" "www.ressourcerie-sault.org" "le-garage-autonome.org"
+      "www.le-garage-autonome.org"];
+      root         = varDir;
+      extraConfig  = [
+        ''
+        Use Stats ressourcerie-banon.org
+
+        RewriteEngine on
+        RewriteCond "%{HTTP_HOST}" "!^ressourcerie-banon\.org$" [NC]
+        RewriteRule ^(.+)$ https://ressourcerie-banon.org$1 [R=302,L]
+
+        <FilesMatch "\.php$">
+          SetHandler "proxy:unix:${config.services.phpfpm.pools.ressourcerie_banon.socket}|fcgi://localhost"
+        </FilesMatch>
+
+        <Directory ${varDir}>
+          DirectoryIndex index.php index.htm index.html
+          Options Indexes FollowSymLinks MultiViews Includes
+          AllowOverride all
+          Require all granted
+        </Directory>
+          ''
+      ];
+    };
+  };
+}
+
diff --git a/modules/private/websites/tools/cloud/farm.nix b/modules/private/websites/tools/cloud/farm.nix
new file mode 100644 (file)
index 0000000..7be774c
--- /dev/null
@@ -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}"
+    <Directory ${nextcloud}>
+      AcceptPathInfo On
+      DirectoryIndex index.php
+      Options FollowSymlinks
+      Require all granted
+      AllowOverride all
+
+      <IfModule mod_headers.c>
+        Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
+      </IfModule>
+      <FilesMatch "\.php$">
+        CGIPassAuth on
+        SetHandler "proxy:unix:${config.services.phpfpm.pools.nextcloud_farm.socket}|fcgi://localhost"
+      </FilesMatch>
+
+    </Directory>
+    '';
+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;
+    };
+  };
+}