nixos/dokuwiki: add <name?> option
Enables multi-site configurations. This break compatibility with prior configurations that expect options for a single dokuwiki instance in `services.dokuwiki`.
This commit is contained in:
parent
e233a9d4dd
commit
dc7ed06615
|
@ -3,13 +3,15 @@
|
||||||
let
|
let
|
||||||
|
|
||||||
inherit (lib) mkEnableOption mkForce mkIf mkMerge mkOption optionalAttrs recursiveUpdate types;
|
inherit (lib) mkEnableOption mkForce mkIf mkMerge mkOption optionalAttrs recursiveUpdate types;
|
||||||
|
inherit (lib) flatten mapAttrs mapAttrs' mapAttrsToList nameValuePair;
|
||||||
|
|
||||||
cfg = config.services.dokuwiki;
|
eachSite = config.services.dokuwiki;
|
||||||
|
stateDir = cfg: "/var/lib/dokuwiki/${cfg.hostName}";
|
||||||
|
|
||||||
user = config.services.nginx.user;
|
user = config.services.nginx.user;
|
||||||
group = config.services.nginx.group;
|
group = config.services.nginx.group;
|
||||||
|
|
||||||
dokuwikiAclAuthConfig = pkgs.writeText "acl.auth.php" ''
|
dokuwikiAclAuthConfig = cfg: pkgs.writeText "acl.auth.php" ''
|
||||||
# acl.auth.php
|
# acl.auth.php
|
||||||
# <?php exit()?>
|
# <?php exit()?>
|
||||||
#
|
#
|
||||||
|
@ -18,24 +20,50 @@ let
|
||||||
${toString cfg.acl}
|
${toString cfg.acl}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
dokuwikiLocalConfig = pkgs.writeText "local.php" ''
|
dokuwikiLocalConfig = cfg: pkgs.writeText "local.php" ''
|
||||||
<?php
|
<?php
|
||||||
$conf['savedir'] = '${cfg.stateDir}';
|
$conf['savedir'] = '${stateDir cfg}';
|
||||||
$conf['superuser'] = '${toString cfg.superUser}';
|
$conf['superuser'] = '${toString cfg.superUser}';
|
||||||
$conf['useacl'] = '${toString cfg.aclUse}';
|
$conf['useacl'] = '${toString cfg.aclUse}';
|
||||||
${toString cfg.extraConfig}
|
${toString cfg.extraConfig}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
dokuwikiPluginsLocalConfig = pkgs.writeText "plugins.local.php" ''
|
dokuwikiPluginsLocalConfig = cfg: pkgs.writeText "plugins.local.php" ''
|
||||||
<?php
|
<?php
|
||||||
${cfg.pluginsConfig}
|
${cfg.pluginsConfig}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in
|
pkg = hostName: cfg: pkgs.stdenv.mkDerivation rec {
|
||||||
{
|
pname = "dokuwiki-${hostName}";
|
||||||
options.services.dokuwiki = {
|
version = src.version;
|
||||||
|
src = cfg.package;
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
mkdir -p $out
|
||||||
|
cp -r * $out/
|
||||||
|
|
||||||
|
# symlink the dokuwiki config
|
||||||
|
ln -s ${dokuwikiLocalConfig cfg} $out/share/dokuwiki/local.php
|
||||||
|
|
||||||
|
# symlink plugins config
|
||||||
|
ln -s ${dokuwikiPluginsLocalConfig cfg} $out/share/dokuwiki/plugins.local.php
|
||||||
|
|
||||||
|
# symlink acl
|
||||||
|
ln -s ${dokuwikiAclAuthConfig cfg} $out/share/dokuwiki/acl.auth.php
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
siteOpts = {lib, name, ...}:
|
||||||
|
{
|
||||||
|
options = {
|
||||||
enable = mkEnableOption "DokuWiki web application.";
|
enable = mkEnableOption "DokuWiki web application.";
|
||||||
|
|
||||||
|
package = mkOption {
|
||||||
|
type = types.package;
|
||||||
|
default = pkgs.dokuwiki;
|
||||||
|
description = "Which dokuwiki package to use.";
|
||||||
|
};
|
||||||
|
|
||||||
hostName = mkOption {
|
hostName = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default = "localhost";
|
default = "localhost";
|
||||||
|
@ -44,7 +72,7 @@ in
|
||||||
|
|
||||||
stateDir = mkOption {
|
stateDir = mkOption {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
default = "/var/lib/dokuwiki/data";
|
default = "/var/lib/dokuwiki/${name}/data";
|
||||||
description = "Location of the dokuwiki state directory.";
|
description = "Location of the dokuwiki state directory.";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -166,49 +194,59 @@ in
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
# interface
|
||||||
|
options = {
|
||||||
|
services.dokuwiki = mkOption {
|
||||||
|
type = types.attrsOf (types.submodule siteOpts);
|
||||||
|
default = {};
|
||||||
|
description = "Sepcification of one or more dokuwiki sites to service.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# implementation
|
# implementation
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf (eachSite != {}) {
|
||||||
|
|
||||||
warnings = mkIf (cfg.superUser == null) ["Not setting services.dokuwiki.superUser will impair your ability to administer DokuWiki"];
|
warnings = mapAttrsToList (hostName: cfg: mkIf (cfg.superUser == null) "Not setting services.dokuwiki.${hostName} superUser will impair your ability to administer DokuWiki") eachSite;
|
||||||
|
|
||||||
assertions = [
|
assertions = flatten (mapAttrsToList (hostName: cfg:
|
||||||
{
|
[{
|
||||||
assertion = cfg.aclUse -> (cfg.acl != null || cfg.aclFile != null);
|
assertion = cfg.aclUse -> (cfg.acl != null || cfg.aclFile != null);
|
||||||
message = "Either services.dokuwiki.acl or services.dokuwiki.aclFile is mandatory when aclUse is true";
|
message = "Either services.dokuwiki.${hostName}.acl or services.dokuwiki.${hostName}.aclFile is mandatory when aclUse is true";
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
assertion = cfg.usersFile != null -> cfg.aclUse != false;
|
assertion = cfg.usersFile != null -> cfg.aclUse != false;
|
||||||
message = "services.dokuwiki.aclUse must be true when usersFile is not null";
|
message = "services.dokuwiki.${hostName}.aclUse must be true when usersFile is not null";
|
||||||
}
|
}]) eachSite);
|
||||||
];
|
|
||||||
|
|
||||||
services.phpfpm.pools.dokuwiki = {
|
services.phpfpm.pools = mapAttrs' (hostName: cfg: (
|
||||||
inherit user;
|
nameValuePair "dokuwiki-${hostName}" {
|
||||||
inherit group;
|
inherit user;
|
||||||
phpEnv = {
|
inherit group;
|
||||||
DOKUWIKI_LOCAL_CONFIG = "${dokuwikiLocalConfig}";
|
phpEnv = {
|
||||||
DOKUWIKI_PLUGINS_LOCAL_CONFIG = "${dokuwikiPluginsLocalConfig}";
|
DOKUWIKI_LOCAL_CONFIG = "${dokuwikiLocalConfig cfg}";
|
||||||
} //optionalAttrs (cfg.usersFile != null) {
|
DOKUWIKI_PLUGINS_LOCAL_CONFIG = "${dokuwikiPluginsLocalConfig cfg}";
|
||||||
DOKUWIKI_USERS_AUTH_CONFIG = "${cfg.usersFile}";
|
} //optionalAttrs (cfg.usersFile != null) {
|
||||||
} //optionalAttrs (cfg.aclUse) {
|
DOKUWIKI_USERS_AUTH_CONFIG = "${cfg.usersFile}";
|
||||||
DOKUWIKI_ACL_AUTH_CONFIG = if (cfg.acl != null) then "${dokuwikiAclAuthConfig}" else "${toString cfg.aclFile}";
|
} //optionalAttrs (cfg.aclUse) {
|
||||||
};
|
DOKUWIKI_ACL_AUTH_CONFIG = if (cfg.acl != null) then "${dokuwikiAclAuthConfig cfg}" else "${toString cfg.aclFile}";
|
||||||
|
};
|
||||||
settings = {
|
|
||||||
"listen.mode" = "0660";
|
settings = {
|
||||||
"listen.owner" = user;
|
"listen.mode" = "0660";
|
||||||
"listen.group" = group;
|
"listen.owner" = user;
|
||||||
} // cfg.poolConfig;
|
"listen.group" = group;
|
||||||
};
|
} // cfg.poolConfig;
|
||||||
|
})) eachSite;
|
||||||
|
|
||||||
services.nginx = {
|
services.nginx = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
virtualHosts = {
|
virtualHosts = mapAttrs (hostName: cfg: mkMerge [ cfg.nginx {
|
||||||
${cfg.hostName} = mkMerge [ cfg.nginx {
|
root = mkForce "${pkg hostName cfg}/share/dokuwiki/";
|
||||||
root = mkForce "${pkgs.dokuwiki}/share/dokuwiki/";
|
|
||||||
extraConfig = "fastcgi_param HTTPS on;";
|
extraConfig = "fastcgi_param HTTPS on;";
|
||||||
|
|
||||||
locations."~ /(conf/|bin/|inc/|install.php)" = {
|
locations."~ /(conf/|bin/|inc/|install.php)" = {
|
||||||
|
@ -246,27 +284,25 @@ in
|
||||||
include ${pkgs.nginx}/conf/fastcgi_params;
|
include ${pkgs.nginx}/conf/fastcgi_params;
|
||||||
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
||||||
fastcgi_param REDIRECT_STATUS 200;
|
fastcgi_param REDIRECT_STATUS 200;
|
||||||
fastcgi_pass unix:${config.services.phpfpm.pools.dokuwiki.socket};
|
fastcgi_pass unix:${config.services.phpfpm.pools."dokuwiki-${hostName}".socket};
|
||||||
fastcgi_param HTTPS on;
|
fastcgi_param HTTPS on;
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
}];
|
}]) eachSite;
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
systemd.tmpfiles.rules = flatten (mapAttrsToList (hostName: cfg: [
|
||||||
|
"d ${stateDir cfg}/attic 0750 ${user} ${group} - -"
|
||||||
systemd.tmpfiles.rules = [
|
"d ${stateDir cfg}/cache 0750 ${user} ${group} - -"
|
||||||
"d ${cfg.stateDir}/attic 0750 ${user} ${group} - -"
|
"d ${stateDir cfg}/index 0750 ${user} ${group} - -"
|
||||||
"d ${cfg.stateDir}/cache 0750 ${user} ${group} - -"
|
"d ${stateDir cfg}/locks 0750 ${user} ${group} - -"
|
||||||
"d ${cfg.stateDir}/index 0750 ${user} ${group} - -"
|
"d ${stateDir cfg}/media 0750 ${user} ${group} - -"
|
||||||
"d ${cfg.stateDir}/locks 0750 ${user} ${group} - -"
|
"d ${stateDir cfg}/media_attic 0750 ${user} ${group} - -"
|
||||||
"d ${cfg.stateDir}/media 0750 ${user} ${group} - -"
|
"d ${stateDir cfg}/media_meta 0750 ${user} ${group} - -"
|
||||||
"d ${cfg.stateDir}/media_attic 0750 ${user} ${group} - -"
|
"d ${stateDir cfg}/meta 0750 ${user} ${group} - -"
|
||||||
"d ${cfg.stateDir}/media_meta 0750 ${user} ${group} - -"
|
"d ${stateDir cfg}/pages 0750 ${user} ${group} - -"
|
||||||
"d ${cfg.stateDir}/meta 0750 ${user} ${group} - -"
|
"d ${stateDir cfg}/tmp 0750 ${user} ${group} - -"
|
||||||
"d ${cfg.stateDir}/pages 0750 ${user} ${group} - -"
|
]) eachSite);
|
||||||
"d ${cfg.stateDir}/tmp 0750 ${user} ${group} - -"
|
|
||||||
];
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,29 +1,42 @@
|
||||||
import ./make-test-python.nix ({ lib, ... }:
|
import ./make-test-python.nix ({ pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
name = "dokuwiki";
|
name = "dokuwiki";
|
||||||
meta.maintainers = with maintainers; [ maintainers."1000101" ];
|
meta.maintainers = with pkgs.lib.maintainers; [ "1000101" ];
|
||||||
|
|
||||||
nodes.machine =
|
machine = { ... }: {
|
||||||
{ pkgs, ... }:
|
services.dokuwiki."site1.local" = {
|
||||||
{ services.dokuwiki = {
|
acl = " ";
|
||||||
enable = true;
|
superUser = null;
|
||||||
acl = " ";
|
nginx = {
|
||||||
superUser = null;
|
forceSSL = false;
|
||||||
nginx = {
|
enableACME = false;
|
||||||
forceSSL = false;
|
};
|
||||||
enableACME = false;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
services.dokuwiki."site2.local" = {
|
||||||
|
acl = " ";
|
||||||
|
superUser = null;
|
||||||
|
nginx = {
|
||||||
|
forceSSL = false;
|
||||||
|
enableACME = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
networking.hosts."127.0.0.1" = [ "site1.local" "site2.local" ];
|
||||||
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript = ''
|
||||||
machine.start()
|
site_names = ["site1.local", "site2.local"]
|
||||||
machine.wait_for_unit("phpfpm-dokuwiki.service")
|
|
||||||
|
start_all()
|
||||||
|
|
||||||
|
machine.wait_for_unit("phpfpm-dokuwiki-site1.local.service")
|
||||||
|
machine.wait_for_unit("phpfpm-dokuwiki-site2.local.service")
|
||||||
|
|
||||||
machine.wait_for_unit("nginx.service")
|
machine.wait_for_unit("nginx.service")
|
||||||
|
|
||||||
machine.wait_for_open_port(80)
|
machine.wait_for_open_port(80)
|
||||||
machine.succeed("curl -sSfL http://localhost/ | grep 'DokuWiki'")
|
|
||||||
|
machine.succeed("curl -sSfL http://site1.local/ | grep 'DokuWiki'")
|
||||||
|
machine.succeed("curl -sSfL http://site2.local/ | grep 'DokuWiki'")
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue