···
1
+
{ config, lib, pkgs, ... }:
5
+
cfg = config.services.jirafeau;
7
+
group = config.services.nginx.group;
8
+
user = config.services.nginx.user;
10
+
withTrailingSlash = str: if hasSuffix "/" str then str else "${str}/";
12
+
localConfig = pkgs.writeText "config.local.php" ''
14
+
$cfg['admin_password'] = '${cfg.adminPasswordSha256}';
15
+
$cfg['web_root'] = 'http://${withTrailingSlash cfg.hostName}';
16
+
$cfg['var_root'] = '${withTrailingSlash cfg.dataDir}';
17
+
$cfg['maximal_upload_size'] = ${builtins.toString cfg.maxUploadSizeMegabytes};
18
+
$cfg['installation_done'] = true;
24
+
options.services.jirafeau = {
25
+
adminPasswordSha256 = mkOption {
29
+
SHA-256 of the desired administration password. Leave blank/unset for no password.
33
+
dataDir = mkOption {
35
+
default = "/var/lib/jirafeau/data/";
36
+
description = "Location of Jirafeau storage directory.";
39
+
enable = mkEnableOption "Jirafeau file upload application.";
41
+
extraConfig = mkOption {
45
+
$cfg['style'] = 'courgette';
46
+
$cfg['organisation'] = 'ACME';
50
+
"https://gitlab.com/mojo42/Jirafeau/-/blob/${cfg.package.version}/lib/config.original.php";
53
+
Jirefeau configuration. Refer to <link xlink:href="${documentationLink}"/> for supported
58
+
hostName = mkOption {
60
+
default = "localhost";
61
+
description = "URL of instance. Must have trailing slash.";
64
+
maxUploadSizeMegabytes = mkOption {
67
+
description = "Maximum upload size of accepted files.";
70
+
maxUploadTimeout = mkOption {
74
+
nginxCoreDocumentation = "http://nginx.org/en/docs/http/ngx_http_core_module.html";
77
+
Timeout for reading client request bodies and headers. Refer to
78
+
<link xlink:href="${nginxCoreDocumentation}#client_body_timeout"/> and
79
+
<link xlink:href="${nginxCoreDocumentation}#client_header_timeout"/> for accepted values.
83
+
nginxConfig = mkOption {
84
+
type = types.submodule
85
+
(import ../web-servers/nginx/vhost-options.nix { inherit config lib; });
88
+
serverAliases = [ "wiki.\${config.networking.domain}" ];
90
+
description = "Extra configuration for the nginx virtual host of Jirafeau.";
93
+
package = mkOption {
94
+
type = types.package;
95
+
default = pkgs.jirafeau;
96
+
defaultText = "pkgs.jirafeau";
97
+
description = "Jirafeau package to use";
98
+
example = "pkgs.jirafeau";
101
+
poolConfig = mkOption {
102
+
type = with types; attrsOf (oneOf [ str int bool ]);
105
+
"pm.max_children" = 32;
106
+
"pm.start_servers" = 2;
107
+
"pm.min_spare_servers" = 2;
108
+
"pm.max_spare_servers" = 4;
109
+
"pm.max_requests" = 500;
112
+
Options for Jirafeau PHP pool. See documentation on <literal>php-fpm.conf</literal> for
113
+
details on configuration directives.
119
+
config = mkIf cfg.enable {
123
+
virtualHosts."${cfg.hostName}" = mkMerge [
127
+
clientMaxBodySize =
128
+
if cfg.maxUploadSizeMegabytes == 0 then "0" else "${cfg.maxUploadSizeMegabytes}m";
132
+
client_max_body_size ${clientMaxBodySize};
133
+
client_body_timeout ${cfg.maxUploadTimeout};
134
+
client_header_timeout ${cfg.maxUploadTimeout};
137
+
"~ \\.php$".extraConfig = ''
138
+
include ${pkgs.nginx}/conf/fastcgi_params;
139
+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
140
+
fastcgi_index index.php;
141
+
fastcgi_pass unix:${config.services.phpfpm.pools.jirafeau.socket};
142
+
fastcgi_param PATH_INFO $fastcgi_path_info;
143
+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
146
+
root = mkForce "${cfg.package}";
151
+
phpfpm.pools.jirafeau = {
152
+
inherit group user;
153
+
phpEnv."JIRAFEAU_CONFIG" = "${localConfig}";
155
+
"listen.mode" = "0660";
156
+
"listen.owner" = user;
157
+
"listen.group" = group;
158
+
} // cfg.poolConfig;
162
+
systemd.tmpfiles.rules = [
163
+
"d ${cfg.dataDir} 0750 ${user} ${group} - -"
164
+
"d ${cfg.dataDir}/files/ 0750 ${user} ${group} - -"
165
+
"d ${cfg.dataDir}/links/ 0750 ${user} ${group} - -"
166
+
"d ${cfg.dataDir}/async/ 0750 ${user} ${group} - -"