feat(wordpress): Start containerization

This commit is contained in:
Tom Hubrecht 2024-01-07 10:26:47 +01:00
parent 19c4176015
commit 876d76208c
2 changed files with 80 additions and 7 deletions

View file

@ -1,11 +1,20 @@
{ ... }:
{ pkgs, lib, ... }:
{
imports = [
./lavoixduntexte.nix
];
let addons = import ./addons { inherit pkgs lib; };
in {
imports = [ ./module.nix ];
services.wordpress = {
webserver = "nginx";
services.wp-containers = {
enable = true;
sites = {
"lavoixduntexte.normalesup.eu" = {
themes = { inherit (addons.themes) avant; };
plugins = { inherit (addons.plugins) wordpress-importer; };
languages = [ pkgs.wordpressPackages.languages.fr_FR ];
};
};
};
}

View file

@ -0,0 +1,64 @@
{ config, lib, options, ... }:
let
inherit (lib) mkEnableOption mkIf mkOption;
inherit (lib.types) anything attrsOf port;
cfg = config.services.wp-containers;
mkConfig = { name, value }: {
services.wordpress = {
webserver = "nginx";
sites.${name} = value;
};
networking.hostName = builtins.replaceStrings [ "." ] [ "-" ] name;
};
mkContainer = i: site: {
inherit (site) name;
value = {
privateNetwork = true;
forwardPorts = [{
containerPort = 80;
hostPort = cfg.basePort + i;
}];
config = mkConfig site;
};
};
mkVhost = i: site: {
inherit (site) name;
value = {
enableACME = true;
forceSSL = true;
locations."/".proxyPass =
"http://127.0.0.1:${builtins.toString (cfg.basePort + i)}";
};
};
siteList = lib.attrsToList cfg.sites;
in {
options.services.wp-containers = {
enable = mkEnableOption "wordpress sites in containers";
basePort = mkOption {
type = port;
default = 9090;
};
sites = mkOption {
type = attrsOf anything;
default = { };
};
};
config = mkIf cfg.enable {
containers = builtins.listToAttrs (lib.imap0 mkContainer siteList);
services.nginx.virtualHosts = builtins.listToAttrs (lib.imap0 mkVhost siteList);
};
}