feat: web stack make php optional

This commit is contained in:
2025-10-27 16:38:12 +01:00
parent ca04f5d8c3
commit 7af4b6a5d1
3 changed files with 11 additions and 17 deletions

View File

@@ -53,6 +53,7 @@ let
enableMysql = mkEnableOption (lib.mdDoc "MySQL Database");
enableDefaultLocations = mkEnableOption (lib.mdDoc "Create default nginx location directives") // { default = true; };
enablePhp = mkEnableOption (lib.mdDoc "PHP-FPM support") // { default = true; };
authorizedKeys = mkOption {
type = types.listOf types.str;
@@ -138,12 +139,12 @@ in
BindPaths = "BindPaths=/var/www/${domain}:/var/www/${domain}";
};
}
) cfg.instances;
) (lib.filterAttrs (name: opts: opts.enablePhp) cfg.instances);
services.phpfpm.pools = mapAttrs' (instance: instanceOpts:
let
domain = if instanceOpts.domain != null then instanceOpts.domain else instance;
user = if instanceOpts.user != null
user = if instanceOpts.user != null
then instanceOps.user
else builtins.replaceStrings ["." "-"] ["_" "_"] domain;
in
@@ -166,7 +167,7 @@ in
phpPackage = instanceOpts.phpPackage;
phpEnv."PATH" = pkgs.lib.makeBinPath [ instanceOpts.phpPackage ];
}
) cfg.instances;
) (lib.filterAttrs (name: opts: opts.enablePhp) cfg.instances);
};
@@ -216,7 +217,7 @@ in
'';
# Cache Media: images, icons, video, audio, HTC
"~* \\.(?:jpg|jpeg|gif|png|webp|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|woff2)$".extraConfig = ''
"~* \\.(?:css|js|jpg|jpeg|gif|png|webp|avif|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|woff2)$".extraConfig = ''
expires 1y;
access_log off;
add_header Cache-Control "public";
@@ -228,19 +229,12 @@ in
add_header Cache-Control "public";
'';
# Cache CSS, Javascript, Images, Icons, Video, Audio, HTC, Fonts
"~* \\.(?:css|js|jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|woff2)$".extraConfig = ''
expires 1y;
access_log off;
add_header Cache-Control "public";
'';
"/".extraConfig = ''
index index.php index.html;
try_files $uri $uri/ /index.php$is_args$args;
'';
})
{
(mkIf instanceOpts.enablePhp {
"~ [^/]\\.php(/|$)".extraConfig = ''
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
@@ -256,7 +250,7 @@ in
fastcgi_pass unix:${config.services.phpfpm.pools."${domain}".socket};
fastcgi_index index.php;
'';
}
})
];
extraConfig = instanceOpts.extraConfig;

View File

@@ -5,6 +5,8 @@ let
in {
services.webstack.instances."${domain}" = {
enablePhp = false;
authorizedKeys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOXKR0AQdP1zn6pL2yjGA/eo9F5Ah2u6+Y5dIk8wR5/I"
];
@@ -67,7 +69,5 @@ in {
add_header Pragma "public";
add_header Cache-Control "public";
'';
phpPackage = pkgs.php;
};
}

View File

@@ -5,6 +5,8 @@ let
in {
services.webstack.instances."${domain}" = {
enablePhp = false;
authorizedKeys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINrxGbJ8vqOLMySIst+e2Qq06bPLPh+7fmPRM27kMBgC"
];
@@ -67,7 +69,5 @@ in {
add_header Pragma "public";
add_header Cache-Control "public";
'';
phpPackage = pkgs.php;
};
}