]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/websites/php-application.nix
Upgrade syden peertube to flake
[perso/Immae/Config/Nix.git] / modules / websites / php-application.nix
index 1bc4872eae3bfd3c8f7a083397531d20c0e68b05..23e2b233581c3b92cc252360e220155f89fdb537 100644 (file)
@@ -1,4 +1,4 @@
-{ lib, config, ... }:
+{ lib, config, pkgs, ... }:
 with lib;
 let
   cfg = config.services.phpApplication;
@@ -19,6 +19,13 @@ in
               Path to application’s vardir.
               '';
           };
+          varDirPaths = mkOption {
+            type = attrsOf str;
+            default = {};
+            description = ''
+              Map of additional folders => mode to create under varDir
+              '';
+          };
           mode = mkOption {
             type = str;
             default = "0700";
@@ -37,10 +44,20 @@ in
             description = "Name of the socket to listen to. Defaults to app name if null";
           };
           phpPool = mkOption {
-            type = lines;
-            default = "";
+            type = attrsOf str;
+            default = {};
             description = "Pool configuration to append";
           };
+          phpEnv = mkOption {
+            type = attrsOf str;
+            default = {};
+            description = "Pool environment to append";
+          };
+          phpPackage = mkOption {
+            type = attrsOf str;
+            default = pkgs.php;
+            description = "Php package to use";
+          };
           phpOptions = mkOption {
             type = lines;
             default = "";
@@ -128,7 +145,7 @@ in
     services.phpApplication.phpListenPaths = mkOption {
       type = attrsOf path;
       default = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
-        name "/run/phpfpm/${if icfg.phpListen == null then name else icfg.phpListen}.sock"
+        name config.services.phpfpm.pools."${name}".socket
       ) cfg.apps;
       readOnly = true;
       description = ''
@@ -155,17 +172,17 @@ in
 
     services.phpfpm.pools = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
       name {
-        listen = cfg.phpListenPaths."${name}";
-        extraConfig = ''
-          user = ${icfg.httpdUser}
-          group = ${icfg.httpdGroup}
-          listen.owner = ${icfg.httpdUser}
-          listen.group = ${icfg.httpdGroup}
-          ${optionalString (icfg.phpSession) ''
-            php_admin_value[session.save_path] = "${icfg.varDir}/phpSessions"''}
-          php_admin_value[open_basedir] = "${builtins.concatStringsSep ":" ([icfg.app icfg.varDir] ++ icfg.phpOpenbasedir)}"
-          '' + icfg.phpPool;
+        user = icfg.httpdUser;
+        group = icfg.httpdUser;
+        settings = {
+          "listen.owner" = icfg.httpdUser;
+          "listen.group" = icfg.httpdGroup;
+          "php_admin_value[open_basedir]" = builtins.concatStringsSep ":" ([icfg.app icfg.varDir] ++ icfg.phpWatchFiles ++ icfg.phpOpenbasedir);
+        }
+        // optionalAttrs (icfg.phpSession) { "php_admin_value[session.save_path]" = "${icfg.varDir}/phpSessions"; }
+        // icfg.phpPool;
         phpOptions = config.services.phpfpm.phpOptions + icfg.phpOptions;
+        inherit (icfg) phpEnv phpPackage;
       }
     ) cfg.apps;
 
@@ -173,6 +190,13 @@ in
       (if icfg.webappName == null then name else icfg.webappName) icfg.webRoot
     ) (attrsets.filterAttrs (n: v: !isNull v.webRoot) cfg.apps);
 
+    services.filesWatcher = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
+      "phpfpm-${name}" {
+        restart = true;
+        paths = icfg.phpWatchFiles;
+      }
+    ) (attrsets.filterAttrs (n: v: builtins.length v.phpWatchFiles > 0) cfg.apps);
+
     systemd.services = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
       "phpfpm-${name}" {
         after = lib.mkAfter icfg.serviceDeps;
@@ -210,7 +234,9 @@ in
           install -m ${icfg.mode} -o ${icfg.httpdUser} -g ${icfg.httpdGroup} -d ${icfg.varDir}
           '' + optionalString (icfg.phpSession) ''
           install -m 0700 -o ${icfg.httpdUser} -g ${icfg.httpdGroup} -d ${icfg.varDir}/phpSessions
-          '';
+          '' + builtins.concatStringsSep "\n" (attrsets.mapAttrsToList (n: v: ''
+            install -m ${v} -o ${icfg.httpdUser} -g ${icfg.httpdGroup} -d ${icfg.varDir}/${n}
+            '') icfg.varDirPaths);
       }
     ) cfg.apps;
   };