]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Add maison bbc website
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 24 Dec 2019 08:41:27 +0000 (09:41 +0100)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Tue, 24 Dec 2019 10:11:56 +0000 (11:11 +0100)
modules/private/default.nix
modules/private/websites/default.nix
modules/private/websites/papa/maison_bbc.nix [new file with mode: 0644]
modules/websites/default.nix

index f768aedf7842192e2815b0908ef701b011a983a6..be39993ee2948160e0bce7140791da104703139b 100644 (file)
@@ -38,6 +38,7 @@ set = {
   nassimeProd = ./websites/nassime/production.nix;
   naturaloutilProd = ./websites/naturaloutil/production.nix;
   telioTortayProd = ./websites/teliotortay/production.nix;
+  papaMaisonBbc = ./websites/papa/maison_bbc.nix;
   papaSurveillance = ./websites/papa/surveillance.nix;
   piedsjalouxInte = ./websites/piedsjaloux/integration.nix;
   piedsjalouxProd = ./websites/piedsjaloux/production.nix;
index 3ac4cb548153f2af390c612d34572be381b728e4..dcbbef85c8dc30160934aa9729ef1b68e70ce3bc 100644 (file)
@@ -259,6 +259,7 @@ in
       telioTortay.production.enable = true;
 
       papa.surveillance.enable = true;
+      papa.maison_bbc.enable = true;
 
       piedsjaloux.integration.enable = true;
       piedsjaloux.production.enable = true;
diff --git a/modules/private/websites/papa/maison_bbc.nix b/modules/private/websites/papa/maison_bbc.nix
new file mode 100644 (file)
index 0000000..7295de8
--- /dev/null
@@ -0,0 +1,68 @@
+{ lib, pkgs, config, ... }:
+let
+  cfg = config.myServices.websites.papa.maison_bbc;
+  varDir = "/var/lib/ftp/papa/site";
+in {
+  options.myServices.websites.papa.maison_bbc.enable = lib.mkEnableOption "enable Papa Maison bbc website";
+
+  config = lib.mkIf cfg.enable {
+    services.duplyBackup.profiles.papa_maison_bbc.rootDir = varDir;
+    services.webstats.sites = [ { name = "maison.bbc.bouya.org"; } ];
+    services.phpfpm.pools.papa_maison_bbc = {
+      listen = "/run/phpfpm/papa_maison_bbc.sock";
+      extraConfig = ''
+        user = wwwrun
+        group = wwwrun
+        listen.owner = wwwrun
+        listen.group = wwwrun
+
+        pm = ondemand
+        pm.max_children = 5
+        pm.process_idle_timeout = 60
+
+        php_admin_value[open_basedir] = "${varDir}"
+        '';
+      phpOptions = config.services.phpfpm.phpOptions + ''
+        extension=${pkgs.php}/lib/php/extensions/mysqli.so
+        '';
+    };
+
+    services.websites.env.production.modules = [ "proxy_fcgi" ];
+    services.websites.env.production.vhostNoSSLConfs.papa_maison_bbc = {
+      hosts        = [ "maison.bbc.bouya.org" ];
+      root         = varDir;
+      extraConfig  = [
+        ''
+        RedirectMatch 301 ^/((?!(\.well-known|add.php).*$).*)$ https://maison.bbc.bouya.org/$1
+        <Directory ${varDir}>
+          DirectoryIndex index.php index.htm index.html
+          AllowOverride None
+          Require all granted
+          <FilesMatch "\.php$">
+            SetHandler "proxy:unix:/run/phpfpm/papa_maison_bbc.sock|fcgi://localhost"
+          </FilesMatch>
+        </Directory>
+          ''
+      ];
+    };
+    services.websites.env.production.vhostConfs.papa_maison_bbc = {
+      certName     = "papa";
+      addToCerts   = true;
+      hosts        = [ "maison.bbc.bouya.org" ];
+      root         = varDir;
+      extraConfig  = [
+        ''
+        <Directory ${varDir}>
+          DirectoryIndex index.php index.htm index.html
+          AllowOverride None
+          Require all granted
+          <FilesMatch "\.php$">
+            SetHandler "proxy:unix:/run/phpfpm/papa_maison_bbc.sock|fcgi://localhost"
+          </FilesMatch>
+        </Directory>
+          ''
+      ];
+    };
+  };
+}
+
index 043fc6ecf619c0a51e8d57133649188af8afe777..6ba0d687d2069c38b08a8df81c0b087914a1edb4 100644 (file)
@@ -86,6 +86,17 @@ in
               };
             };
           };
+          vhostNoSSLConfs = mkOption {
+            default = {};
+            description = "List of no ssl vhosts to define for Apache";
+            type = attrsOf (submodule {
+              options = {
+                hosts    = mkOption { type = listOf string; };
+                root     = mkOption { type = nullOr path; };
+                extraConfig = mkOption { type = listOf lines; default = []; };
+              };
+            });
+          };
           vhostConfs = mkOption {
             default = {};
             description = "List of vhosts to define for Apache";
@@ -177,6 +188,15 @@ in
       documentRoot = vhostConf.root;
       extraConfig = builtins.concatStringsSep "\n" vhostConf.extraConfig;
     };
+    toVhostNoSSL = ips: vhostConf: {
+      enableSSL = false;
+      logFormat = "combinedVhost";
+      listen = map (ip: { inherit ip; port = 80; }) ips;
+      hostName = builtins.head vhostConf.hosts;
+      serverAliases = builtins.tail vhostConf.hosts or [];
+      documentRoot = vhostConf.root;
+      extraConfig = builtins.concatStringsSep "\n" vhostConf.extraConfig;
+    };
   in attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
     icfg.httpdName (mkIf icfg.enable {
       enable = true;
@@ -190,6 +210,7 @@ in
       extraConfig = builtins.concatStringsSep "\n" icfg.extraConfig;
       virtualHosts = [ (toVhost icfg.ips icfg.fallbackVhost) ]
         ++ optionals (icfg.nosslVhost.enable) [ (nosslVhost icfg.ips icfg.nosslVhost) ]
+        ++ (attrsets.mapAttrsToList (n: v: toVhostNoSSL icfg.ips v) icfg.vhostNoSSLConfs)
         ++ (attrsets.mapAttrsToList (n: v: toVhost icfg.ips v) icfg.vhostConfs)
         ++ [ (redirectVhost icfg.ips) ];
     })