Skip to content

Commit

Permalink
nixos/prosody: support mod_http_file_share
Browse files Browse the repository at this point in the history
  • Loading branch information
ju1m committed Jun 1, 2024
1 parent a3c0b23 commit d4954e0
Showing 1 changed file with 46 additions and 11 deletions.
57 changes: 46 additions & 11 deletions nixos/modules/services/networking/prosody.nix
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ let
else if builtins.isList x then "{ ${lib.concatMapStringsSep ", " toLua x} }"
else throw "Invalid Lua value";

settingsToLua = prefix: settings: generators.toKeyValue {
listsAsDuplicateKeys = false;
mkKeyValue = k: generators.mkKeyValueDefault {
mkValueString = toLua;
} " = " (prefix + k);
} (filterAttrs (k: v: v != null) settings);

createSSLOptsStr = o: ''
ssl = {
cafile = "/etc/ssl/certs/ca-bundle.crt";
Expand Down Expand Up @@ -418,15 +425,26 @@ let
httpUploadPath = mkOption {
type = types.str;
description = ''
Directory where the uploaded files will be stored. By
default, uploaded files are put in a sub-directory of the
default Prosody storage path (usually /var/lib/prosody).
Directory where the uploaded files will be stored when the http_upload module is used.
By default, uploaded files are put in a sub-directory of the default Prosody storage path (usually /var/lib/prosody).
'';
default = "/var/lib/prosody";
};
};
};

httpFileShareOpts = { ... }: {
freeformType = with types;
let atom = oneOf [ int bool str (listOf atom) ]; in
attrsOf (nullOr atom) // {
description = "int, bool, string or list of them";
};
options.domain = mkOption {
type = with types; nullOr str;
description = "Domain name for a http_file_share service.";
};
};

vHostOpts = { ... }: {

options = {
Expand Down Expand Up @@ -650,7 +668,7 @@ in

uploadHttp = mkOption {
description = ''
Configures the Prosody builtin HTTP server to handle user uploads.
Configures the old Prosody builtin HTTP server to handle user uploads.
'';
type = types.nullOr (types.submodule uploadHttpOpts);
default = null;
Expand All @@ -659,6 +677,17 @@ in
};
};

httpFileShare = mkOption {
description = ''
Configures the http_file_share module to handle user uploads.
'';
type = types.nullOr (types.submodule httpFileShareOpts);
default = null;
example = {
domain = "uploads.my-xmpp-example-host.org";
};
};

muc = mkOption {
type = types.listOf (types.submodule mucOpts);
default = [ ];
Expand Down Expand Up @@ -740,11 +769,10 @@ in
You need to setup at least a MUC domain to comply with
XEP-0423.
'' + genericErrMsg;}
{ assertion = cfg.uploadHttp != null || !cfg.xmppComplianceSuite;
{ assertion = cfg.uploadHttp != null || cfg.httpFileShare != null || !cfg.xmppComplianceSuite;
message = ''
You need to setup the uploadHttp module through
config.services.prosody.uploadHttp to comply with
XEP-0423.
You need to setup the http_upload or http_file_share modules through config.services.prosody.uploadHttp
or config.services.prosody.httpFileShare to comply with XEP-0423.
'' + genericErrMsg;}
];
in errors;
Expand All @@ -753,8 +781,11 @@ in

environment.etc."prosody/prosody.cfg.lua".text =
let
httpDiscoItems = optionals (cfg.uploadHttp != null)
[{ url = cfg.uploadHttp.domain; description = "HTTP upload endpoint";}];
httpDiscoItems = optional (cfg.uploadHttp != null) {
url = cfg.uploadHttp.domain; description = "HTTP upload endpoint";
} ++ optional (cfg.httpFileShare != null) {
url = cfg.httpFileShare.domain; description = "HTTP file share endpoint";
};
mucDiscoItems = builtins.foldl'
(acc: muc: [{ url = muc.domain; description = "${muc.domain} MUC endpoint";}] ++ acc)
[]
Expand Down Expand Up @@ -833,14 +864,18 @@ in
'') cfg.muc}
${ lib.optionalString (cfg.uploadHttp != null) ''
-- TODO: think about migrating this to mod-http_file_share instead.
Component ${toLua cfg.uploadHttp.domain} "http_upload"
http_upload_file_size_limit = ${cfg.uploadHttp.uploadFileSizeLimit}
http_upload_expire_after = ${cfg.uploadHttp.uploadExpireAfter}
${lib.optionalString (cfg.uploadHttp.userQuota != null) "http_upload_quota = ${toLua cfg.uploadHttp.userQuota}"}
http_upload_path = ${toLua cfg.uploadHttp.httpUploadPath}
''}
${lib.optionalString (cfg.httpFileShare != null) ''
Component ${toLua cfg.httpFileShare.domain} "http_file_share"
${settingsToLua " http_file_share_" (cfg.httpFileShare // { domain = null; })}
''}
${ lib.concatStringsSep "\n" (lib.mapAttrsToList (n: v: ''
VirtualHost "${v.domain}"
enabled = ${boolToString v.enabled};
Expand Down

0 comments on commit d4954e0

Please sign in to comment.