nur/modules/web-apps/wordpress/module.nix

78 lines
2.4 KiB
Nix
Raw Normal View History

{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.wordpress;
2021-11-22 21:43:19 +01:00
appConfig = (import ./default-app-config.nix).extend (self: super: { });
writeableDataPath = "/var/lib/phpfpm/${appConfig.name}";
2021-11-22 21:43:19 +01:00
phpFpmListen = "/run/phpfpm/wordpress-pool.sock";
phpIni = import ./php-config.nix { inherit pkgs config appConfig; };
2021-11-22 21:43:19 +01:00
enablePageSpeed = pkgs.stdenv.isLinux && appConfig.googlePageSpeed.enable;
app = callPackage ./app.nix {
inherit appConfig;
writeable = {
sysPath = writeableDataPath;
2021-11-22 21:43:19 +01:00
owner = config.services.nginx.user;
};
};
2021-11-22 21:43:19 +01:00
in {
2021-11-22 21:45:16 +01:00
disabledModules = [ "services/web-apps/wordpress.nix" ];
2021-11-22 21:43:19 +01:00
options.services.wordpress = {
enable = mkEnableOption "Enable the WordPress module";
};
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.wp-cli ];
2021-11-22 21:43:19 +01:00
services.nginx = {
enable = true;
# package = pkgs.callPackage ./nginx.nix { inherit enablePageSpeed; };
# httpConfig = nginxConfig;
# TODO: ajouter les locations pour wordpress
};
systemd.services.init-writeable-paths = {
2021-11-22 21:43:19 +01:00
description = "Initialize writeable directories for the app";
before = [ "phpfpm.service" ];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" "phpfpm.service" "nginx.service" ];
serviceConfig = {
2021-11-22 21:43:19 +01:00
Type = "oneshot";
ExecStart = app.initScript;
};
};
2021-11-22 21:43:19 +01:00
systemd.services.install-wp =
let deps = [ "init-writeable-paths.service" "mysql.service" ];
in {
2021-11-22 21:43:19 +01:00
enable = appConfig.autoInstall.enable;
description = "Configure WordPress installation with WP-CLI";
before = [ "nginx.service" ];
after = deps;
wants = deps;
wantedBy = [ "multi-user.target" ];
serviceConfig = {
2021-11-22 21:43:19 +01:00
Type = "oneshot";
ExecStart = import ./install-wp.nix {
inherit pkgs config appConfig writeableDataPath;
appPackage = app.package;
};
};
2021-11-22 21:43:19 +01:00
environment.PHP_INI_SCAN_DIR =
let customIni = pkgs.writeTextDir "wp-cli-custom.ini" phpIni;
in "${pkgs.php}/etc:${customIni}";
2021-11-22 21:43:19 +01:00
};
services.phpfpm = {
phpOptions = phpIni;
pools.wordpress-pool = import ./phpfpm-conf.nix {
inherit pkgs config phpFpmListen;
processSettings = appConfig.phpFpmProcessSettings;
};
};
services.mysql = {
enable = true;
package = pkgs.mariadb;
};
2021-11-22 21:43:19 +01:00
};
}