-
-
Notifications
You must be signed in to change notification settings - Fork 17.8k
nixos/nextcloud: Add services.nextcloud.settings.mail_* options #460529
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nixos/nextcloud: Add services.nextcloud.settings.mail_* options #460529
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
yes and we should aim to have it simpler within our nix options so users dont shoot themselfes int he foot :D ... PS: i like the nixos test :D |
This comment was marked as resolved.
This comment was marked as resolved.
|
I have tried to create a test for sendmail based on your test ... environment.systemPackages = [
pkgs.msmtp
];
environment.etc."msmtprc".text = ''
defaults
auth on
tls on
tls_starttls on
account default
host ${domain}
port 587
from alice@${domain}
user alice
password foobar
'';let me send via sendmail inside the test vms from nextcloud to stalward manually ... BUT nextcloud fails to do so :/ click to expandFrom eb766e6d0af65510f951334598f1ced6e9451e2e Mon Sep 17 00:00:00 2001
From: 6543 <[email protected]>
Date: Tue, 11 Nov 2025 04:31:46 +0100
Subject: [PATCH] nixos/nextcloud: add test for mail config via sendmail
---
nixos/tests/nextcloud/default.nix | 1 +
nixos/tests/nextcloud/with-sendmail.nix | 109 ++++++++++++++++++++++++
2 files changed, 110 insertions(+)
create mode 100644 nixos/tests/nextcloud/with-sendmail.nix
diff --git a/nixos/tests/nextcloud/default.nix b/nixos/tests/nextcloud/default.nix
index 72f7a28070b5..e4b71f1d4385 100644
--- a/nixos/tests/nextcloud/default.nix
+++ b/nixos/tests/nextcloud/default.nix
@@ -136,6 +136,7 @@ let
./with-postgresql-and-redis.nix
./with-objectstore.nix
./with-mail.nix
+ ./with-sendmail.nix
]
++ (pkgs.lib.optional (version >= 32) ./without-admin-user.nix)
);
diff --git a/nixos/tests/nextcloud/with-sendmail.nix b/nixos/tests/nextcloud/with-sendmail.nix
new file mode 100644
index 000000000000..a41b55f148c1
--- /dev/null
+++ b/nixos/tests/nextcloud/with-sendmail.nix
@@ -0,0 +1,109 @@
+{
+ name,
+ pkgs,
+ testBase,
+ system,
+ ...
+}:
+with import ../../lib/testing-python.nix { inherit system pkgs; };
+runTest (
+ { config, lib, ... }:
+ let
+ certs = import ../common/acme/server/snakeoil-certs.nix;
+ domain = certs.domain;
+ in
+ {
+ inherit name;
+
+ meta.maintainers = lib.teams.nextcloud.members;
+
+ imports = [ testBase ];
+
+ nodes = {
+ nextcloud =
+ {
+ config,
+ pkgs,
+ nodes,
+ ...
+ }:
+ {
+ security.pki.certificateFiles = [ certs.ca.cert ];
+
+ networking.extraHosts = ''
+ ${nodes.stalwart.networking.primaryIPAddress} ${domain}
+ '';
+
+ environment.etc."nextcloud/mail_smtppassword".text = "foobar";
+ environment.systemPackages = [
+ pkgs.msmtp
+ ];
+ environment.etc."msmtprc".text = ''
+ defaults
+ auth on
+ tls on
+ tls_starttls on
+ account default
+ host ${domain}
+ port 587
+ from alice@${domain}
+ user alice
+ password foobar
+ '';
+
+ services.nextcloud.config = {
+ dbtype = "sqlite";
+
+ mail = {
+ from_address = "alice";
+ inherit domain;
+ smtpmode = "sendmail";
+ send_plaintext_only = true;
+ };
+ };
+ };
+
+ stalwart =
+ { pkgs, ... }:
+ {
+ imports = [ ../stalwart/stalwart-mail-config.nix ];
+
+ networking.firewall.allowedTCPPorts = [ 587 ];
+
+ environment.systemPackages = [
+ (pkgs.writers.writePython3Bin "test-imap-read" { } ''
+ from imaplib import IMAP4
+
+ with IMAP4('localhost') as imap:
+ imap.starttls()
+ status, [caps] = imap.login('bob', 'foobar')
+ assert status == 'OK'
+ imap.select()
+ status, [ref] = imap.search(None, 'ALL')
+ assert status == 'OK'
+ [msgId] = ref.split()
+ status, msg = imap.fetch(msgId, 'BODY[TEXT]')
+ assert status == 'OK'
+ assert (msg[0][1].strip()
+ == (b'Well done, ${config.adminuser}!\r\n\r\n'
+ b'If you received this email, the email configuration '
+ b's=\r\neems to be correct.\r\n\r\n\r\n--=20\r\n'
+ b'Nextcloud - a safe home for all your data=\r\n\r\n'
+ b'This is an automatically sent email, please do not reply.'))
+ '')
+ ];
+ };
+ };
+
+ test-helpers.init = ''
+ stalwart.wait_for_unit("multi-user.target")
+ stalwart.wait_until_succeeds("nc -vzw 2 localhost 587")
+
+ nextcloud.succeed("nc -vzw 2 ${domain} 587")
+ nextcloud.succeed("curl -sS --fail-with-body -u ${config.adminuser}:${config.adminpass} -H 'OCS-APIRequest: true' -X PUT http://nextcloud/ocs/v2.php/cloud/users/${config.adminuser} -H 'Content-Type: application/json' --data-raw '{\"key\":\"email\",\"value\":\"bob@${domain}\"}'")
+ nextcloud.succeed("curl -sS --fail-with-body -u ${config.adminuser}:${config.adminpass} -H 'OCS-APIRequest: true' -X POST http://nextcloud/settings/admin/mailtest")
+
+ stalwart.succeed("test-imap-read")
+ '';
+ }
+)
--
2.50.1 |
|
Any reason to do this in Historically we've been trying to get rid of For the password we have two options:
|
I get your point, but I feel like it's easier to understand by just following the docs. This is also easier for admins who port their config/knowledge from a different method of deployment.
Well it's how the options are called, but the reason is mostly that even if you use sendmail, the smtp options can apply if you use smtp with sendmail. Like I said, really confusing -_-
While I feel like it's not the job of the test to check that sendmail actually works, it certainly won't hurt either having this as a test and example for anyone who wants to use it. |
TBH I didn't put much though into that part, so I'm happy to change it how you see fit.
I would still like to define them, as it makes it easier to spot problems early.
I'm not sure I follow. Does this require changes besides moving from config to settings? |
78da731 to
e063852
Compare
|
@Ma27 I did what I think you meant, but please tell me if I got it wrong. I'm not super happy with the way it works now, but at least it works 🤷♀️ |
e063852 to
acd0bcd
Compare
|
I based this on #394136 and now I'm happy with the way it works :) |
Ma27
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Explicitly blocking merge until #394136 is through.
6543
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested nix run .#nixosTests.nextcloud.with-mail32.driver: PASS
code looks nice
acd0bcd to
3fc5278
Compare
Ma27
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I'm reading the NC sources, does Nextcloud always send emails? Asking because I wondered if we'd accidentally turn this on by default for everyone.
| type = lib.types.str; | ||
| default = "127.0.0.1"; | ||
| description = '' | ||
| This depends on `mail_smtpmode`. Specify the IP address of your mail server host. This may contain multiple hosts separated by a semicolon. If you need to specify the port number, append it to the IP address separated by a colon, like this: `127.0.0.1:24`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhm, what will happen if you specify both mail_smtpport and 127.0.0.1:24 as smtphost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I have no idea, this is just copied from the sample config docs. I suppose the mail_smtpport would act as a default and with the colon it would be possible to override it for each server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I see.
We don't have much of a choice anyways.
Yes it does, while looking into this I found it doesn't even check the config and just blindly sends emails (and the errors are hidden away until nextcloud/server#56090). I only realized this later on, while doing other Nextcloud development. I think adding these configs doesn't change anything, as they are just the default values from the server. What we could do instead is just add the assertion to use services.nextcloud.secrets and not add any of the options in services.nextcloud.settings. Then we definitely don't interfere with anything that isn't happening upstream anyway. |
OK, in that case we're good. |
Uses existing `nix_read_secret` and LoadCredential to read contents of a file into an entry in `config.php`
3fc5278 to
2718336
Compare
Replaces #413728. I started from scratch and modeled it as closely as possible to the docs: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#mail-parameters. The config options are super confusing and I have to admit that I had to look up a bunch of logic in the server to understand when and how they are used.
CC @6543
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.