feat(wordpress): Start containerization
This commit is contained in:
parent
19c4176015
commit
876d76208c
2 changed files with 80 additions and 7 deletions
|
@ -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 ];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
64
machines/web01/wordpress/module.nix
Normal file
64
machines/web01/wordpress/module.nix
Normal 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);
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue