{ config, pkgs, lib, ... }: with lib; let cfg = config.services.wordpress; callPackage = pkgs.callPackage; appConfig = (import ./default-app-config.nix).extend (self: super: { wpConfig = super.wpConfig.extend (self: super: { secrets = cfg.wpConfigSecrets; }); }); writeableDataPath = "/var/lib/phpfpm/${appConfig.name}"; phpFpmListen = "/run/phpfpm/wordpress-pool.sock"; phpIni = import ./php-config.nix { inherit pkgs config appConfig; phpPackages = pkgs.php74Packages; phpExtensions = pkgs.php74Extensions; }; enablePageSpeed = pkgs.stdenv.isLinux && appConfig.googlePageSpeed.enable; app = callPackage ./app.nix { inherit appConfig; writeable = { sysPath = writeableDataPath; owner = config.services.nginx.user; }; }; in { disabledModules = [ "services/web-apps/wordpress.nix" ]; options.services.wordpress = { enable = mkEnableOption "Enable the WordPress module"; wpConfigSecrets = mkOption { type = types.str; }; }; config = mkIf cfg.enable { environment.systemPackages = [ pkgs.wp-cli ]; services.nginx = { enable = true; # package = pkgs.callPackage ./nginx.nix { inherit enablePageSpeed; }; # httpConfig = nginxConfig; # TODO: ajouter les locations pour wordpress }; systemd.services.init-writeable-paths = { description = "Initialize writeable directories for the app"; before = [ "phpfpm.service" ]; after = [ "network.target" ]; wantedBy = [ "multi-user.target" "phpfpm.service" "nginx.service" ]; serviceConfig = { Type = "oneshot"; ExecStart = app.initScript; }; }; systemd.services.install-wp = let deps = [ "init-writeable-paths.service" "mysql.service" ]; in { enable = appConfig.autoInstall.enable; description = "Configure WordPress installation with WP-CLI"; before = [ "nginx.service" ]; after = deps; wants = deps; wantedBy = [ "multi-user.target" ]; serviceConfig = { Type = "oneshot"; ExecStart = import ./install-wp.nix { inherit pkgs config appConfig writeableDataPath; appPackage = app.package; }; }; environment.PHP_INI_SCAN_DIR = let customIni = pkgs.writeTextDir "wp-cli-custom.ini" phpIni; in "${pkgs.php}/etc:${customIni}"; }; 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; }; }; }