8 format = pkgs.formats.php { finalVariable = "config"; };
10 cfg = config.services.filesender;
11 simpleSamlCfg = config.services.simplesamlphp.filesender;
12 fpm = config.services.phpfpm.pools.filesender;
14 filesenderConfigDirectory = pkgs.runCommand "filesender-config" { } ''
16 cp ${format.generate "config.php" cfg.settings} $out/config.php
21 maintainers = with lib.maintainers; [ nhnn ];
22 doc = ./filesender.md;
25 options.services.filesender = with lib; {
26 enable = mkEnableOption "FileSender";
27 package = mkPackageOption pkgs "filesender" { };
29 description = "User under which filesender runs.";
31 default = "filesender";
34 createLocally = mkOption {
38 Create the PostgreSQL database and database user locally.
43 default = "/run/postgresql";
44 description = "Database hostname.";
49 description = "Database port.";
53 default = "filesender";
54 description = "Database name.";
58 default = "filesender";
59 description = "Database user.";
61 passwordFile = mkOption {
62 type = types.nullOr types.path;
64 example = "/run/keys/filesender-dbpassword";
66 A file containing the password corresponding to
67 [](#opt-services.filesender.database.user).
72 type = types.submodule {
73 freeformType = format.type;
77 description = "Site URL. Used in emails, to build URLs for logging in, logging out, build URL for upload endpoint for web workers, to include scripts etc.";
82 UIDs (as per the configured saml_uid_attribute) of FileSender administrators.
83 Accounts with these UIDs can access the Admin page through the web UI.
86 admin_email = mkOption {
89 Email address of FileSender administrator(s).
90 Emails regarding disk full etc. are sent here.
91 You should use a role-address here.
94 storage_filesystem_path = mkOption {
95 type = types.nullOr types.str;
96 description = "When using storage type filesystem this is the absolute path to the file system where uploaded files are stored until they expire. Your FileSender storage root.";
98 log_facilities = mkOption {
100 default = [ { type = "error_log"; } ];
101 description = "Defines where FileSender logging is sent. You can sent logging to a file, to syslog or to the default PHP log facility (as configured through your webserver's PHP module). The directive takes an array of one or more logging targets. Logging can be sent to multiple targets simultaneously. Each logging target is a list containing the name of the logging target and a number of attributes which vary per log target. See below for the exact definiation of each log target.";
107 Configuration options used by FileSender.
108 See [](https://docs.filesender.org/filesender/v2.0/admin/configuration/)
109 for available options.
112 configureNginx = mkOption {
115 description = "Configure nginx as a reverse proxy for FileSender.";
117 localDomain = mkOption {
119 example = "filesender.example.org";
120 description = "The domain serving your FileSender instance.";
122 poolSettings = mkOption {
132 "pm.max_children" = "32";
133 "pm.start_servers" = "2";
134 "pm.min_spare_servers" = "2";
135 "pm.max_spare_servers" = "4";
136 "pm.max_requests" = "500";
139 Options for FileSender's PHP pool. See the documentation on `php-fpm.conf` for details on configuration directives.
143 config = lib.mkIf cfg.enable {
144 services.simplesamlphp.filesender = {
145 phpfpmPool = "filesender";
146 localDomain = cfg.localDomain;
147 settings.baseurlpath = lib.mkDefault "https://${cfg.localDomain}/saml";
153 group = config.services.nginx.group;
155 FILESENDER_CONFIG_DIR = toString filesenderConfigDirectory;
156 SIMPLESAMLPHP_CONFIG_DIR = toString simpleSamlCfg.configDir;
159 "listen.owner" = config.services.nginx.user;
160 "listen.group" = config.services.nginx.group;
161 } // cfg.poolSettings;
165 services.nginx = lib.mkIf cfg.configureNginx {
167 virtualHosts.${cfg.localDomain} = {
168 root = "${cfg.package}/www";
174 try_files $uri $uri/ /index.php?args;
176 "~ [^/]\\.php(/|$)" = {
178 fastcgi_split_path_info ^(.+\.php)(/.+)$;
179 fastcgi_pass unix:${fpm.socket};
180 include ${pkgs.nginx}/conf/fastcgi.conf;
181 fastcgi_intercept_errors on;
182 fastcgi_param PATH_INFO $fastcgi_path_info;
183 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
186 "~ /\\.".extraConfig = "deny all;";
191 services.postgresql = lib.mkIf cfg.database.createLocally {
193 ensureDatabases = [ cfg.database.name ];
196 name = cfg.database.user;
197 ensureDBOwnership = true;
202 services.filesender.settings = lib.mkMerge [
203 (lib.mkIf cfg.database.createLocally {
204 db_host = "/run/postgresql";
206 db_password = "."; # FileSender requires it even when on UNIX socket auth.
208 (lib.mkIf (!cfg.database.createLocally) {
209 db_host = cfg.database.hostname;
210 db_port = toString cfg.database.port;
211 db_password = format.lib.mkRaw "file_get_contents('${cfg.database.passwordFile}')";
214 site_url = lib.mkDefault "https://${cfg.localDomain}";
216 db_username = cfg.database.user;
217 db_database = cfg.database.name;
218 "auth_sp_saml_simplesamlphp_url" = "/saml";
219 "auth_sp_saml_simplesamlphp_location" = "${simpleSamlCfg.libDir}";
223 systemd.services.filesender-initdb = {
224 description = "Init filesender DB";
228 "phpfpm-filesender.service"
230 after = [ "postgresql.service" ];
232 restartIfChanged = true;
236 "FILESENDER_CONFIG_DIR=${toString filesenderConfigDirectory}"
237 "SIMPLESAMLPHP_CONFIG_DIR=${toString simpleSamlCfg.configDir}"
240 Group = config.services.nginx.group;
242 ExecStart = "${fpm.phpPackage}/bin/php ${cfg.package}/scripts/upgrade/database.php";
246 users.extraUsers.filesender = lib.mkIf (cfg.user == "filesender") {
247 home = "/var/lib/filesender";
248 group = config.services.nginx.group;