4 cfg = config.services.phpApplication;
5 cfgByEnv = lists.groupBy (x: x.websiteEnv) (builtins.attrValues cfg);
9 services.phpApplication = with types; mkOption {
12 php applications to define
14 type = attrsOf (submodule {
19 Path to application’s vardir.
26 Mode to apply to the vardir
29 phpSession = mkOption {
32 description = "Handle phpsession files separately in vardir";
34 websiteEnv = mkOption {
37 website instance name to use
40 httpdUser = mkOption {
42 default = config.services.httpd.user;
44 httpd user to run the prestart scripts as.
47 httpdGroup = mkOption {
49 default = config.services.httpd.group;
51 httpd group to run the prestart scripts as.
57 Path to application root
60 webappName = mkOption {
63 Alias name for the app, to be used in services.websites.webappDirs
69 Path to the web root path of the application. May differ from the application itself (usually a subdirectory)
72 preStartActions = mkOption {
76 List of actions to run as apache user at preStart when
77 whatchFiles or app dir changed.
80 serviceDeps = mkOption {
84 List of systemd services this application depends on
87 watchFiles = mkOption {
91 Path to other files to watch to trigger preStart scripts
100 services.websites.env = attrsets.mapAttrs' (name: cfgs: attrsets.nameValuePair
102 modules = [ "proxy_fcgi" ];
103 watchPaths = builtins.concatLists (map (c: c.watchFiles) cfgs);
107 services.websites.webappDirs = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
108 icfg.webappName icfg.webRoot
109 ) (attrsets.filterAttrs (n: v: !isNull v.webappName && !isNull v.webRoot) cfg);
111 systemd.services = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
113 after = lib.mkAfter icfg.serviceDeps;
114 wants = icfg.serviceDeps;
115 preStart = lib.mkAfter (optionalString (!isNull icfg.varDir) ''
116 watchFilesChanged() {
117 ${optionalString (builtins.length icfg.watchFiles == 0) "return 0"}
118 [ ! -f "${icfg.varDir}"/watchedFiles ] \
119 || ! sha512sum -c --status ${icfg.varDir}/watchedFiles
122 [ ! -f "${icfg.varDir}/currentWebappDir" -o \
123 "${icfg.app}" != "$(cat ${icfg.varDir}/currentWebappDir 2>/dev/null)" ]
126 ${optionalString (builtins.length icfg.watchFiles == 0) "return 0"}
127 sha512sum ${builtins.concatStringsSep " " icfg.watchFiles} > ${icfg.varDir}/watchedFiles
130 if watchFilesChanged || appDirChanged; then
131 pushd ${icfg.app} > /dev/null
132 ${builtins.concatStringsSep "\n " (map (c: "/run/wrappers/bin/sudo -u ${icfg.httpdUser} ${c}") icfg.preStartActions) }
134 echo -n "${icfg.app}" > ${icfg.varDir}/currentWebappDir
141 system.activationScripts = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
144 text = optionalString (!isNull icfg.varDir) ''
145 install -m ${icfg.mode} -o ${icfg.httpdUser} -g ${icfg.httpdGroup} -d ${icfg.varDir}
146 '' + optionalString (icfg.phpSession) ''
147 install -m 0700 -o ${icfg.httpdUser} -g ${icfg.httpdGroup} -d ${icfg.varDir}/phpSessions