From 876d76208c4c007bbb416513ed6f734473889953 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sun, 7 Jan 2024 10:26:47 +0100 Subject: [PATCH] feat(wordpress): Start containerization --- machines/web01/wordpress/default.nix | 23 +++++++--- machines/web01/wordpress/module.nix | 64 ++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 machines/web01/wordpress/module.nix diff --git a/machines/web01/wordpress/default.nix b/machines/web01/wordpress/default.nix index f34dd15..3da4a2e 100644 --- a/machines/web01/wordpress/default.nix +++ b/machines/web01/wordpress/default.nix @@ -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 ]; + }; + }; }; } diff --git a/machines/web01/wordpress/module.nix b/machines/web01/wordpress/module.nix new file mode 100644 index 0000000..7d10e52 --- /dev/null +++ b/machines/web01/wordpress/module.nix @@ -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); + }; +}