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.
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";
52 Jirefeau configuration. Refer to <${documentationLink}> for supported
59 default = "localhost";
60 description = "URL of instance. Must have trailing slash.";
63 maxUploadSizeMegabytes = mkOption {
66 description = "Maximum upload size of accepted files.";
69 maxUploadTimeout = mkOption {
73 nginxCoreDocumentation = "http://nginx.org/en/docs/http/ngx_http_core_module.html";
75 Timeout for reading client request bodies and headers. Refer to
76 <${nginxCoreDocumentation}#client_body_timeout> and
77 <${nginxCoreDocumentation}#client_header_timeout> for accepted values.
81 nginxConfig = mkOption {
82 type = types.submodule
83 (import ../web-servers/nginx/vhost-options.nix { inherit config lib; });
85 example = literalExpression ''
87 serverAliases = [ "wiki.''${config.networking.domain}" ];
90 description = "Extra configuration for the nginx virtual host of Jirafeau.";
93 package = mkPackageOption pkgs "jirafeau" { };
95 poolConfig = mkOption {
96 type = with types; attrsOf (oneOf [ str int bool ]);
99 "pm.max_children" = 32;
100 "pm.start_servers" = 2;
101 "pm.min_spare_servers" = 2;
102 "pm.max_spare_servers" = 4;
103 "pm.max_requests" = 500;
106 Options for Jirafeau PHP pool. See documentation on `php-fpm.conf` for
107 details on configuration directives.
113 config = mkIf cfg.enable {
117 virtualHosts."${cfg.hostName}" = mkMerge [
122 if cfg.maxUploadSizeMegabytes == 0 then "0" else "${cfg.maxUploadSizeMegabytes}m";
126 client_max_body_size ${clientMaxBodySize};
127 client_body_timeout ${cfg.maxUploadTimeout};
128 client_header_timeout ${cfg.maxUploadTimeout};
131 "~ \\.php$".extraConfig = ''
132 include ${config.services.nginx.package}/conf/fastcgi_params;
133 fastcgi_split_path_info ^(.+\.php)(/.+)$;
134 fastcgi_index index.php;
135 fastcgi_pass unix:${config.services.phpfpm.pools.jirafeau.socket};
136 fastcgi_param PATH_INFO $fastcgi_path_info;
137 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
140 root = mkForce "${cfg.package}";
145 phpfpm.pools.jirafeau = {
147 phpEnv."JIRAFEAU_CONFIG" = "${localConfig}";
149 "listen.mode" = "0660";
150 "listen.owner" = user;
151 "listen.group" = group;
156 systemd.tmpfiles.rules = [
157 "d ${cfg.dataDir} 0750 ${user} ${group} - -"
158 "d ${cfg.dataDir}/files/ 0750 ${user} ${group} - -"
159 "d ${cfg.dataDir}/links/ 0750 ${user} ${group} - -"
160 "d ${cfg.dataDir}/async/ 0750 ${user} ${group} - -"
164 # uses attributes of the linked package
165 meta.buildDocsInSandbox = false;