2021-11-22 21:39:44 +01:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.wordpress;
|
2021-11-22 21:46:14 +01:00
|
|
|
callPackage = pkgs.callPackage;
|
2021-11-22 21:59:18 +01:00
|
|
|
appConfig = (import ./default-app-config.nix).extend (self: super: {
|
|
|
|
wpConfig = super.wpConfig.extend (self: super: {
|
|
|
|
secrets = cfg.wpConfigSecrets;
|
|
|
|
});
|
|
|
|
});
|
2021-11-22 21:39:44 +01:00
|
|
|
writeableDataPath = "/var/lib/phpfpm/${appConfig.name}";
|
2021-11-22 21:43:19 +01:00
|
|
|
phpFpmListen = "/run/phpfpm/wordpress-pool.sock";
|
2021-11-22 22:19:31 +01:00
|
|
|
php = import ./php-config.nix { inherit pkgs config appConfig;
|
|
|
|
php = pkgs.php74;
|
2021-11-22 21:48:45 +01:00
|
|
|
};
|
2021-11-22 22:19:31 +01:00
|
|
|
phpIni = php.phpIni;
|
2021-11-22 21:39:44 +01:00
|
|
|
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:39:44 +01:00
|
|
|
};
|
|
|
|
};
|
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";
|
2021-11-22 21:59:18 +01:00
|
|
|
wpConfigSecrets = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
};
|
2021-11-22 22:34:31 +01:00
|
|
|
enablePageSpeed = mkOption {
|
|
|
|
type = types.bool;
|
2021-11-22 22:46:09 +01:00
|
|
|
default = false; # TODO: backport some patch first, pkgs.stdenv.isLinux && appConfig.googlePageSpeed.enable; - https://github.com/apache/incubator-pagespeed-ngx/issues/1735
|
|
|
|
};
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "wordpress";
|
|
|
|
};
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "wordpress";
|
2021-11-22 22:34:31 +01:00
|
|
|
};
|
2021-11-22 21:43:19 +01:00
|
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
2021-11-22 22:46:09 +01:00
|
|
|
users.users.${cfg.user} = {
|
2021-11-22 22:56:57 +01:00
|
|
|
isSystemUser = true;
|
2021-11-22 22:46:09 +01:00
|
|
|
inherit (cfg) group;
|
|
|
|
};
|
|
|
|
users.groups.${cfg.group} = {};
|
|
|
|
|
2021-11-22 21:43:19 +01:00
|
|
|
environment.systemPackages = [ pkgs.wp-cli ];
|
2021-11-22 21:39:44 +01:00
|
|
|
|
2021-11-22 21:43:19 +01:00
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
2021-11-22 22:37:00 +01:00
|
|
|
additionalModules = with pkgs.nginxModules; [
|
|
|
|
dav cache-purge moreheaders
|
|
|
|
] ++ optional cfg.enablePageSpeed pagespeed;
|
2021-11-22 21:43:19 +01:00
|
|
|
# httpConfig = nginxConfig;
|
|
|
|
# TODO: ajouter les locations pour wordpress
|
|
|
|
};
|
2021-11-22 21:39:44 +01:00
|
|
|
|
|
|
|
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" ];
|
2021-11-22 21:39:44 +01:00
|
|
|
serviceConfig = {
|
2021-11-22 21:43:19 +01:00
|
|
|
Type = "oneshot";
|
2021-11-22 21:39:44 +01:00
|
|
|
ExecStart = app.initScript;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-11-22 21:43:19 +01:00
|
|
|
systemd.services.install-wp =
|
|
|
|
let deps = [ "init-writeable-paths.service" "mysql.service" ];
|
2021-11-22 21:39:44 +01:00
|
|
|
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" ];
|
2021-11-22 21:39:44 +01:00
|
|
|
serviceConfig = {
|
2021-11-22 21:43:19 +01:00
|
|
|
Type = "oneshot";
|
|
|
|
ExecStart = import ./install-wp.nix {
|
2021-11-22 21:39:44 +01:00
|
|
|
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;
|
2021-11-22 21:39:44 +01:00
|
|
|
in "${pkgs.php}/etc:${customIni}";
|
2021-11-22 21:43:19 +01:00
|
|
|
};
|
2021-11-22 21:39:44 +01:00
|
|
|
|
|
|
|
services.phpfpm = {
|
|
|
|
pools.wordpress-pool = import ./phpfpm-conf.nix {
|
2021-11-22 22:46:09 +01:00
|
|
|
inherit (cfg) user group;
|
2021-11-22 21:39:44 +01:00
|
|
|
inherit pkgs config phpFpmListen;
|
2021-11-22 22:19:31 +01:00
|
|
|
phpPackage = php;
|
2021-11-22 21:39:44 +01:00
|
|
|
processSettings = appConfig.phpFpmProcessSettings;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.mysql = {
|
|
|
|
enable = true;
|
|
|
|
package = pkgs.mariadb;
|
2021-11-22 22:46:09 +01:00
|
|
|
|
|
|
|
ensureDatabases = [ "wordpress" ];
|
|
|
|
ensureUsers = [
|
|
|
|
{
|
|
|
|
name = cfg.user;
|
|
|
|
ensurePermissions = {
|
|
|
|
"wordpress.*" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2021-11-22 21:39:44 +01:00
|
|
|
};
|
2021-11-22 21:43:19 +01:00
|
|
|
};
|
|
|
|
}
|