Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/filesender: init #305132

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions maintainers/maintainer-list.nix
Expand Up @@ -14175,6 +14175,12 @@
githubId = 399535;
name = "Niklas Hamb眉chen";
};
nhnn = {
matrix = "@nhnn:nhnn.dev";
github = "thenhnn";
githubId = 162156666;
name = "nhnn";
};
nhooyr = {
email = "anmol@aubble.com";
github = "nhooyr";
Expand Down
4 changes: 4 additions & 0 deletions nixos/doc/manual/release-notes/rl-2405.section.md
Expand Up @@ -165,6 +165,10 @@ The pre-existing [services.ankisyncd](#opt-services.ankisyncd.enable) has been m

- [prometheus-nats-exporter](https://github.com/nats-io/prometheus-nats-exporter), a Prometheus exporter for NATS. Available as [services.prometheus.exporters.nats](#opt-services.prometheus.exporters.nats.enable).

- [SimpleSAMLphp](https://simplesamlphp.org/), an application written in native PHP that deals with authentication. Available as [services.simplesamlphp](#opt-services.simplesamlphp).

- [Filesender](https://filesender.org/), a file sharing software. Available as [services.filesender](#opt-services.filesender.enable).

## Backward Incompatibilities {#sec-release-24.05-incompatibilities}

<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
Expand Down
2 changes: 2 additions & 0 deletions nixos/modules/module-list.nix
Expand Up @@ -1324,6 +1324,7 @@
./services/web-apps/dolibarr.nix
./services/web-apps/engelsystem.nix
./services/web-apps/ethercalc.nix
./services/web-apps/filesender.nix
./services/web-apps/fluidd.nix
./services/web-apps/freshrss.nix
./services/web-apps/galene.nix
Expand Down Expand Up @@ -1394,6 +1395,7 @@
./services/web-apps/selfoss.nix
./services/web-apps/shiori.nix
./services/web-apps/silverbullet.nix
./services/web-apps/simplesamlphp.nix
./services/web-apps/slskd.nix
./services/web-apps/snipe-it.nix
./services/web-apps/sogo.nix
Expand Down
256 changes: 256 additions & 0 deletions nixos/modules/services/web-apps/filesender.nix
@@ -0,0 +1,256 @@
{ config
, lib
, pkgs
, ...
}:
let
format = pkgs.formats.php { finalVariable = "$config"; };

cfg = config.services.filesender;
simpleSamlCfg = config.services.simplesamlphp.filesender;
fpm = config.services.phpfpm.pools.filesender;

phpPackage = pkgs.php.withExtensions (
{ enabled
, all
}: with all;
[
xml
mbstring
]
++ enabled
);

filesenderConfigDirectory = pkgs.runCommand "filesender-config" {} ''
mkdir $out
cp ${format.generate "config.php" cfg.settings} $out/config.php
'';
in
{
meta = {
maintainers = with lib.maintainers; [ nhnn ];
};

options.services.filesender = with lib; {
enable = mkEnableOption "Filesender";
package = mkPackageOption pkgs "filesender" { };
user = lib.mkOption {
description = "User under which filesender runs.";
type = lib.types.str;
default = "filesender";
};
database = {
createLocally = mkOption {
type = types.bool;
default = true;
description = ''
Create the PostgreSQL database and database user locally.
'';
};
hostname = mkOption {
type = types.str;
default = "/run/postgresql";
description = "Database hostname.";
};
port = mkOption {
type = types.port;
default = 5432;
description = "Database port.";
};
name = mkOption {
type = types.str;
default = "filesender";
description = "Database name.";
};
user = mkOption {
type = types.str;
default = "filesender";
description = "Database user.";
};
passwordFile = mkOption {
type = types.nullOr types.path;
default = null;
example = "/run/keys/filesender-dbpassword";
description = ''
A file containing the password corresponding to
[](#opt-services.filesender.database.user).
'';
};
};
settings = mkOption {
type = lib.types.submodule {
freeformType = format.type;
options = {
site_url = mkOption {
type = types.str;
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.";
};
admin = mkOption {
type = types.commas;
description = ''
UIDs (as per the configured saml_uid_attribute) of FileSender administrators.
Accounts with these UIDs can access the Admin page through the web UI.
'';
};
admin_email = mkOption {
type = types.commas;
description = ''
Email address of FileSender administrator(s).
Emails regarding disk full etc. are sent here.
You should use a role-address here.
'';
};
storage_filesystem_path = mkOption {
type = types.nullOr types.str;
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.";
};
log_facilities = mkOption {
type = format.type;
default = [
{
type = "syslog";
}
];
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.";
};
};
};
default = { };
description = ''
Configuration options used by Filesender.
See [](https://docs.filesender.org/filesender/v2.0/admin/configuration/)
for available options.
'';
};

configureNginx = mkOption {
type = types.bool;
default = true;
description = "Configure nginx as a reverse proxy for Filesender.";
};
localDomain = mkOption {
type = types.str;
example = "filesender.example.org";
description = "The domain serving your Filesender instance.";
};
poolSettings = mkOption {
type = with types; attrsOf (oneOf [ str int bool ]);
default = {
"pm" = "dynamic";
"pm.max_children" = "32";
"pm.start_servers" = "2";
"pm.min_spare_servers" = "2";
"pm.max_spare_servers" = "4";
"pm.max_requests" = "500";
};
description = ''
Options for Filesender's PHP pool. See the documentation on `php-fpm.conf` for details on configuration directives.
'';
};
};
config = lib.mkIf cfg.enable {
services.simplesamlphp.filesender = {
localDomain = cfg.localDomain;
};

services.phpfpm = {
pools.filesender = {
user = cfg.user;
group = config.services.nginx.group;
inherit phpPackage;
phpEnv = {
FILESENDER_CONFIG_DIR = filesenderConfigDirectory;
SIMPLESAMLPHP_CONFIG_DIR = simpleSamlCfg.configDir;
};
settings = {
"listen.owner" = config.services.nginx.user;
"listen.group" = config.services.nginx.group;
} // cfg.poolSettings;
};
};

services.nginx = lib.mkIf cfg.configureNginx {
enable = true;
virtualHosts.${cfg.localDomain} = {
root = "${cfg.package}/www";
extraConfig = ''
index index.php;
'';
locations = {
"/".extraConfig = ''
try_files $uri $uri/ /index.php?args;
'';
"~ [^/]\\.php(/|$)" = {
extraConfig = ''
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:${fpm.socket};
include ${pkgs.nginx}/conf/fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
'';
};
thenhnn marked this conversation as resolved.
Show resolved Hide resolved
"~ /\\.".extraConfig = "deny all;";
};
};
};

services.postgresql = lib.mkIf cfg.database.createLocally {
enable = true;
ensureDatabases = [ cfg.database.name ];
ensureUsers = [
{
name = cfg.database.user;
ensureDBOwnership = true;
}
];
};

services.filesender.settings = lib.mkMerge [
(lib.mkIf cfg.database.createLocally {
db_host = "/run/postgresql";
db_port = "5432";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't those two options irrelevant when using socket auth?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, PostgreSQL ignores them but Filesender requires them to be a string.

Port is used when connecting to socket to define it name.

db_password = "test";
})
(lib.mkIf (!cfg.database.createLocally) {
db_host = cfg.database.hostname;
db_port = toString cfg.database.port;
db_password._secret = cfg.database.passwordFile;
})
{
db_type = "pgsql";
db_username = cfg.database.user;
db_database = cfg.database.name;
"auth_sp_saml_simplesamlphp_url" = "/saml";
"auth_sp_saml_simplesamlphp_location" = "${simpleSamlCfg.libDir}";
}
];

systemd.services.filesender-initdb = {
description = "Init filesender DB";

wantedBy = [ "multi-user.target" "phpfpm-filesender.service" ];
after = [ "postgresql.service" ];

restartIfChanged = true;

serviceConfig = {
Environment = [
"FILESENDER_CONFIG_DIR=${filesenderConfigDirectory}"
"SIMPLESAMLPHP_CONFIG_DIR=${simpleSamlCfg.configDir}"
];
Type = "oneshot";
Group = config.services.nginx.group;
User = "filesender";
ExecStart = "${phpPackage}/bin/php ${cfg.package}/scripts/upgrade/database.php";
};
};

users.extraUsers.filesender = lib.mkIf (cfg.user == "filesender") {
home = "/var/lib/filesender";
group = config.services.nginx.group;
createHome = true;
isSystemUser = true;
};
};
}