aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/apps/php-fpm.nix34
1 files changed, 29 insertions, 5 deletions
diff --git a/modules/apps/php-fpm.nix b/modules/apps/php-fpm.nix
index ed90c1a..cdc83c6 100644
--- a/modules/apps/php-fpm.nix
+++ b/modules/apps/php-fpm.nix
@@ -4,12 +4,14 @@ let
inherit (builtins)
filter isAttrs isBool ;
+
inherit (lib)
- concatStringsSep filterAttrs foldl hasPrefix
- mapAttrsToList mkIf mkOption types ;
- inherit (types)
- attrsOf bool either enum int nullOr package path str
- submodule ;
+ concatStringsSep filterAttrs foldl hasPrefix mapAttrs' mapAttrsToList
+ mkDefault mkIf mkOption ;
+
+ inherit (lib.types)
+ attrsOf bool either enum int nullOr package path str submodule ;
+
explicit = filterAttrs (n: v: n != "_module" && v != null);
concatNonEmpty = sep: list: concatStringsSep sep (filter (s: s != "") list);
@@ -23,6 +25,26 @@ let
users = mapAttrsToList (_: v: v.user) instances;
+ mkLogRotate = name: cfg:
+ let instance = "php-fpm-${name}";
+ in {
+ name = instance;
+ value = {
+ files = "${cfg.logDir}/*.log";
+ directives = {
+ delaycompress = mkDefault true;
+ missingok = mkDefault true;
+ notifempty = mkDefault true;
+ rotate = mkDefault 14;
+ sharedscripts = true;
+ daily = mkDefault true;
+ create = mkDefault "0640 ${cfg.user} ${cfg.user}";
+ postrotate = pkgs.writeBashScript "logrotate-${instance}-postrotate"
+ "systemctl kill -s SIGUSR1 --kill-who=main '${instance}.service'";
+ };
+ };
+ };
+
mkService = name: cfg:
let
show = v: if isBool v then (if v then "yes" else "no") else toString v;
@@ -72,6 +94,7 @@ let
'';
serviceConfig = {
ExecStart = exec;
+ KillMode = "mixed";
PermissionsStartOnly = true;
Restart = "always";
User = cfg.user;
@@ -162,6 +185,7 @@ in {
})));
config = mkIf ({} != instances) {
+ nixsap.apps.logrotate.conf = mapAttrs' mkLogRotate instances;
nixsap.system.users.daemons = users;
systemd.services = foldl (a: b: a//b) {} (mapAttrsToList mkService instances);
};