From 7979d496ce67c60293137b176d71de66dd3f956a Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 14 Nov 2026 16:50:08 +0100 Subject: [PATCH 1/7] nixos/nextcloud: restructure tests We now have `nixosTests.nextcloud.nextcloudXY.*`. This is much less unhinged than the attr filtering. --- nixos/tests/nextcloud/default.nix | 40 +++++++++---------- .../ne/nextcloud-notify_push/package.nix | 4 +- pkgs/servers/nextcloud/default.nix | 4 +- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/nixos/tests/nextcloud/default.nix b/nixos/tests/nextcloud/default.nix index 293b8e221dab..d95e902d03c7 100644 --- a/nixos/tests/nextcloud/default.nix +++ b/nixos/tests/nextcloud/default.nix @@ -7,6 +7,7 @@ with pkgs.lib; let + inherit (pkgs) lib; baseModule = { config, ... }: { @@ -121,32 +122,31 @@ let }; } ]; - - callNextcloudTest = - path: - let - name = "${removeSuffix ".nix" (baseNameOf path)}${toString version}"; - in - nameValuePair name ( + in + lib.nameValuePair "nextcloud${toString version}" ( + lib.mapAttrs + ( + name: + path: import path { inherit system pkgs testBase; name = "nextcloud-${name}"; } - ); - in - map callNextcloudTest [ - ./basic.nix - ./home-bindmount.nix - ./home-mount.nix - ./with-declarative-redis-and-secrets.nix - ./with-mysql-and-memcached.nix - ./with-postgresql-and-redis.nix - ./with-objectstore.nix - ./with-mail.nix - ]; + ) + { + basic = ./basic.nix; + home-bindmout = ./home-bindmount.nix; + home-mount = ./home-mount.nix; + with-declarative-redis-and-secrets = ./with-declarative-redis-and-secrets.nix; + with-mysql-and-memcached = ./with-mysql-and-memcached.nix; + with-postgresql-and-redis = ./with-postgresql-and-redis.nix; + with-objectstore = ./with-objectstore.nix; + with-mail = ./with-mail.nix; + } + ); in listToAttrs ( - concatMap genTests [ + map genTests [ 33 34 35 diff --git a/pkgs/by-name/ne/nextcloud-notify_push/package.nix b/pkgs/by-name/ne/nextcloud-notify_push/package.nix index 48ce67865531..18ae85789e93 100644 --- a/pkgs/by-name/ne/nextcloud-notify_push/package.nix +++ b/pkgs/by-name/ne/nextcloud-notify_push/package.nix @@ -60,8 +60,8 @@ rustPlatform.buildRustPackage rec { }; }; tests = - lib.filterAttrs ( - key: lib.const (lib.hasPrefix "with-postgresql-and-redis" key) + lib.mapAttrs' ( + k: { with-postgresql-and-redis, ... }: lib.nameValuePair k with-postgresql-and-redis ) nixosTests.nextcloud // { inherit test_client; diff --git a/pkgs/servers/nextcloud/default.nix b/pkgs/servers/nextcloud/default.nix index 27ef2606cfba..6711bc2ab97c 100644 --- a/pkgs/servers/nextcloud/default.nix +++ b/pkgs/servers/nextcloud/default.nix @@ -37,9 +37,7 @@ let ''; passthru = { - tests = lib.filterAttrs ( - key: _: (lib.hasSuffix (lib.versions.major version) key) - ) nixosTests.nextcloud; + tests = nixosTests.nextcloud."nextcloud${lib.versions.major version}"; inherit packages; }; From 88ba56a2e261a1e36cf4af5b0baff9006e276ab6 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 14 Nov 2026 17:35:40 +0100 Subject: [PATCH 2/7] nixos/nextcloud: inject package function into each subtest --- nixos/tests/nextcloud/basic.nix | 2 + nixos/tests/nextcloud/default.nix | 77 +++++++++---------- nixos/tests/nextcloud/home-bindmount.nix | 2 + nixos/tests/nextcloud/home-mount.nix | 2 + .../with-declarative-redis-and-secrets.nix | 2 + nixos/tests/nextcloud/with-mail.nix | 2 + .../nextcloud/with-mysql-and-memcached.nix | 2 + nixos/tests/nextcloud/with-objectstore.nix | 2 + .../nextcloud/with-postgresql-and-redis.nix | 2 + 9 files changed, 52 insertions(+), 41 deletions(-) diff --git a/nixos/tests/nextcloud/basic.nix b/nixos/tests/nextcloud/basic.nix index 523678971643..a30d63c69737 100644 --- a/nixos/tests/nextcloud/basic.nix +++ b/nixos/tests/nextcloud/basic.nix @@ -3,6 +3,7 @@ pkgs, testBase, system, + package, ... }: @@ -55,6 +56,7 @@ runTest ( services.nextcloud = { enable = true; + package = package pkgs; config.dbtype = "sqlite"; datadir = "/var/lib/nextcloud-data"; autoUpdateApps = { diff --git a/nixos/tests/nextcloud/default.nix b/nixos/tests/nextcloud/default.nix index d95e902d03c7..6bf54c0daea2 100644 --- a/nixos/tests/nextcloud/default.nix +++ b/nixos/tests/nextcloud/default.nix @@ -8,7 +8,7 @@ with pkgs.lib; let inherit (pkgs) lib; - baseModule = + testBase = { config, ... }: { imports = [ @@ -109,46 +109,41 @@ let ''; }; + packages = lib.listToAttrs ( + map + ( + version: + let + attr = "nextcloud${toString version}"; + in + lib.nameValuePair attr (builtins.getAttr attr) + ) + [ + 33 + 34 + 35 + ] + ); + genTests = - version: - let - testBase.imports = [ - baseModule - { - nodes.nextcloud = - { pkgs, ... }: - { - services.nextcloud.package = pkgs.${"nextcloud${toString version}"}; - }; + attr: package: + lib.mapAttrs + ( + name: path: + import path { + inherit system pkgs testBase package; + name = "${attr}-${name}"; } - ]; - in - lib.nameValuePair "nextcloud${toString version}" ( - lib.mapAttrs - ( - name: - path: - import path { - inherit system pkgs testBase; - name = "nextcloud-${name}"; - } - ) - { - basic = ./basic.nix; - home-bindmout = ./home-bindmount.nix; - home-mount = ./home-mount.nix; - with-declarative-redis-and-secrets = ./with-declarative-redis-and-secrets.nix; - with-mysql-and-memcached = ./with-mysql-and-memcached.nix; - with-postgresql-and-redis = ./with-postgresql-and-redis.nix; - with-objectstore = ./with-objectstore.nix; - with-mail = ./with-mail.nix; - } - ); + ) + { + basic = ./basic.nix; + home-bindmout = ./home-bindmount.nix; + home-mount = ./home-mount.nix; + with-declarative-redis-and-secrets = ./with-declarative-redis-and-secrets.nix; + with-mysql-and-memcached = ./with-mysql-and-memcached.nix; + with-postgresql-and-redis = ./with-postgresql-and-redis.nix; + with-objectstore = ./with-objectstore.nix; + with-mail = ./with-mail.nix; + }; in -listToAttrs ( - map genTests [ - 33 - 34 - 35 - ] -) +lib.mapAttrs genTests packages diff --git a/nixos/tests/nextcloud/home-bindmount.nix b/nixos/tests/nextcloud/home-bindmount.nix index a48882544508..13d171b9d2ff 100644 --- a/nixos/tests/nextcloud/home-bindmount.nix +++ b/nixos/tests/nextcloud/home-bindmount.nix @@ -3,6 +3,7 @@ pkgs, testBase, system, + package, ... }: @@ -48,6 +49,7 @@ runTest ( pkgs.util-linux ]; services.nextcloud = { + package = package pkgs; config.dbtype = "sqlite"; }; }; diff --git a/nixos/tests/nextcloud/home-mount.nix b/nixos/tests/nextcloud/home-mount.nix index d69f1d59c92c..df9d4d9af02c 100644 --- a/nixos/tests/nextcloud/home-mount.nix +++ b/nixos/tests/nextcloud/home-mount.nix @@ -3,6 +3,7 @@ pkgs, testBase, system, + package, ... }: @@ -22,6 +23,7 @@ runTest ( }; services.nextcloud = { config.dbtype = "sqlite"; + package = package pkgs; home = "/mnt/nextcloud"; }; }; diff --git a/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix b/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix index 40e82a269623..13b25de5cc36 100644 --- a/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix +++ b/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix @@ -3,6 +3,7 @@ pkgs, testBase, system, + package, ... }: @@ -24,6 +25,7 @@ runTest ( { environment.systemPackages = [ pkgs.jq ]; services.nextcloud = { + package = package pkgs; caching = { apcu = false; redis = true; diff --git a/nixos/tests/nextcloud/with-mail.nix b/nixos/tests/nextcloud/with-mail.nix index 0a193ce76076..33eb9f960d1e 100644 --- a/nixos/tests/nextcloud/with-mail.nix +++ b/nixos/tests/nextcloud/with-mail.nix @@ -3,6 +3,7 @@ pkgs, testBase, system, + package, ... }: with import ../../lib/testing-python.nix { inherit system pkgs; }; @@ -37,6 +38,7 @@ runTest ( environment.etc."nextcloud/mail_smtppassword".text = "foobar"; services.nextcloud = { + package = package pkgs; config.dbtype = "sqlite"; settings = { diff --git a/nixos/tests/nextcloud/with-mysql-and-memcached.nix b/nixos/tests/nextcloud/with-mysql-and-memcached.nix index f05dcd0a9835..222d257f9bc4 100644 --- a/nixos/tests/nextcloud/with-mysql-and-memcached.nix +++ b/nixos/tests/nextcloud/with-mysql-and-memcached.nix @@ -3,6 +3,7 @@ pkgs, testBase, system, + package, ... }: @@ -21,6 +22,7 @@ runTest ( { config, pkgs, ... }: { services.nextcloud = { + package = package pkgs; caching = { apcu = true; memcached = true; diff --git a/nixos/tests/nextcloud/with-objectstore.nix b/nixos/tests/nextcloud/with-objectstore.nix index 39235d4f1fc9..ce589db0a147 100644 --- a/nixos/tests/nextcloud/with-objectstore.nix +++ b/nixos/tests/nextcloud/with-objectstore.nix @@ -3,6 +3,7 @@ pkgs, testBase, system, + package, ... }: @@ -40,6 +41,7 @@ runTest ( ... }: { + services.nextcloud.package = package pkgs; services.nextcloud.config.dbtype = "sqlite"; environment.variables.AWS_CONFIG_FILE = awsCfg; diff --git a/nixos/tests/nextcloud/with-postgresql-and-redis.nix b/nixos/tests/nextcloud/with-postgresql-and-redis.nix index ed4eea689fd0..26bc8506cbd6 100644 --- a/nixos/tests/nextcloud/with-postgresql-and-redis.nix +++ b/nixos/tests/nextcloud/with-postgresql-and-redis.nix @@ -3,6 +3,7 @@ pkgs, testBase, system, + package, ... }: @@ -26,6 +27,7 @@ runTest ( { environment.systemPackages = [ pkgs.jq ]; services.nextcloud = { + package = package pkgs; caching = { apcu = false; redis = true; From 0ced783f7f27cae6bd159641d6f6065be456faba Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 14 Nov 2026 18:48:44 +0100 Subject: [PATCH 3/7] nixos/tests/stalwart: pin stalwart_0_15 pkgs.stalwart doesn't exist when having a pkgs with allowAliases=false. --- nixos/tests/stalwart/stalwart-config.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nixos/tests/stalwart/stalwart-config.nix b/nixos/tests/stalwart/stalwart-config.nix index 399b527ea1d4..c3c64f4a6876 100644 --- a/nixos/tests/stalwart/stalwart-config.nix +++ b/nixos/tests/stalwart/stalwart-config.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ pkgs, lib, ... }: let certs = import ../common/acme/server/snakeoil-certs.nix; @@ -9,6 +9,7 @@ in services.stalwart = { enable = true; + package = pkgs.stalwart_0_15; stateVersion = lib.trivial.release; # Only for the test; please don't do in production From cc5124f5e69a51315bb71bd088d8b51a4d12f066 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 14 Nov 2026 18:48:59 +0100 Subject: [PATCH 4/7] nixos/nextcloud: do runTest from default.nix --- nixos/tests/all-tests.nix | 2 +- nixos/tests/nextcloud/basic.nix | 217 ++++++----- nixos/tests/nextcloud/default.nix | 92 ++--- nixos/tests/nextcloud/home-bindmount.nix | 109 +++--- nixos/tests/nextcloud/home-mount.nix | 37 +- .../with-declarative-redis-and-secrets.nix | 180 ++++----- nixos/tests/nextcloud/with-mail.nix | 160 ++++---- .../nextcloud/with-mysql-and-memcached.nix | 74 ++-- nixos/tests/nextcloud/with-objectstore.nix | 349 +++++++++--------- .../nextcloud/with-postgresql-and-redis.nix | 136 +++---- 10 files changed, 668 insertions(+), 688 deletions(-) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index ef287a336832..3f4499231601 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -1249,7 +1249,7 @@ in networking.scripted = handleTest ./networking/networkd-and-scripted.nix { networkd = false; }; # TODO: put in networking.nix after the test becomes more complete networkingProxy = runTest ./networking-proxy.nix; - nextcloud = handleTest ./nextcloud { }; + nextcloud = import ./nextcloud { inherit runTest lib; }; nextflow = runTestOn [ "x86_64-linux" ] ./nextflow.nix; nextjs-ollama-llm-ui = runTest ./web-apps/nextjs-ollama-llm-ui.nix; nexus = runTest ./nexus.nix; diff --git a/nixos/tests/nextcloud/basic.nix b/nixos/tests/nextcloud/basic.nix index a30d63c69737..59123fa35306 100644 --- a/nixos/tests/nextcloud/basic.nix +++ b/nixos/tests/nextcloud/basic.nix @@ -1,129 +1,124 @@ { name, - pkgs, testBase, - system, package, ... }: -with import ../../lib/testing-python.nix { inherit system pkgs; }; -runTest ( - { config, lib, ... }: - { - inherit name; - meta = { - maintainers = lib.teams.nextcloud.members; - }; +{ config, lib, pkgs, ... }: +{ + inherit name; + meta = { + maintainers = lib.teams.nextcloud.members; + }; - imports = [ testBase ]; + imports = [ testBase ]; - nodes = { - # The only thing the client needs to do is download a file. - client = - { ... }: - { - services.davfs2.enable = true; - systemd.tmpfiles.settings.nextcloud = { - "/tmp/davfs2-secrets"."f+" = { - mode = "0600"; - argument = "http://nextcloud/remote.php/dav/files/${config.adminuser} ${config.adminuser} ${config.adminpass}"; - }; - }; - virtualisation.fileSystems = { - "/mnt/dav" = { - device = "http://nextcloud/remote.php/dav/files/${config.adminuser}"; - fsType = "davfs"; - options = - let - davfs2Conf = (pkgs.writeText "davfs2.conf" "secrets /tmp/davfs2-secrets"); - in - [ - "conf=${davfs2Conf}" - "x-systemd.automount" - "noauto" - ]; - }; + nodes = { + # The only thing the client needs to do is download a file. + client = + { pkgs, ... }: + { + services.davfs2.enable = true; + systemd.tmpfiles.settings.nextcloud = { + "/tmp/davfs2-secrets"."f+" = { + mode = "0600"; + argument = "http://nextcloud/remote.php/dav/files/${config.adminuser} ${config.adminuser} ${config.adminpass}"; }; }; - - nextcloud = - { config, pkgs, ... }: - { - systemd.tmpfiles.rules = [ - "d /var/lib/nextcloud-data 0750 nextcloud nginx - -" - ]; - - services.nextcloud = { - enable = true; - package = package pkgs; - config.dbtype = "sqlite"; - datadir = "/var/lib/nextcloud-data"; - autoUpdateApps = { - enable = true; - startAt = "20:00"; - }; - phpExtraExtensions = all: [ all.bz2 ]; - nginx.enableFastcgiRequestBuffering = true; - secrets.mysecret = "/etc/nextcloud/mysecretfile"; - }; - - environment.etc."nextcloud/mysecretfile".text = "foobar"; - - specialisation.withoutMagick.configuration = { - services.nextcloud.enableImagemagick = false; - }; - }; - }; - - test-helpers.extraTests = - { nodes, ... }: - let - findInClosure = - what: drv: - pkgs.runCommand "find-in-closure" - { - exportReferencesGraph = [ - "graph" - drv + virtualisation.fileSystems = { + "/mnt/dav" = { + device = "http://nextcloud/remote.php/dav/files/${config.adminuser}"; + fsType = "davfs"; + options = + let + davfs2Conf = (pkgs.writeText "davfs2.conf" "secrets /tmp/davfs2-secrets"); + in + [ + "conf=${davfs2Conf}" + "x-systemd.automount" + "noauto" ]; - inherit what; - } - '' - test -e graph - grep "$what" graph >$out || true - ''; - nexcloudWithImagick = findInClosure "imagick" nodes.nextcloud.system.build.vm; - nextcloudWithoutImagick = findInClosure "imagick" nodes.nextcloud.specialisation.withoutMagick.configuration.system.build.vm; - in - # python - '' - with subtest("File is in proper nextcloud home"): - nextcloud.succeed("test -f ${nodes.nextcloud.services.nextcloud.datadir}/data/root/files/test-shared-file") + }; + }; + }; - with subtest("Closure checks"): - assert open("${nexcloudWithImagick}").read() != "" - assert open("${nextcloudWithoutImagick}").read() == "" + nextcloud = + { config, pkgs, ... }: + { + systemd.tmpfiles.rules = [ + "d /var/lib/nextcloud-data 0750 nextcloud nginx - -" + ]; - with subtest("Davfs2"): - assert "hi" in client.succeed("cat /mnt/dav/test-shared-file") + services.nextcloud = { + enable = true; + package = package pkgs; + config.dbtype = "sqlite"; + datadir = "/var/lib/nextcloud-data"; + autoUpdateApps = { + enable = true; + startAt = "20:00"; + }; + phpExtraExtensions = all: [ all.bz2 ]; + nginx.enableFastcgiRequestBuffering = true; + secrets.mysecret = "/etc/nextcloud/mysecretfile"; + }; - with subtest("Ensure SSE is disabled by default"): - nextcloud.succeed("grep -vE '^HBEGIN:oc_encryption_module' /var/lib/nextcloud-data/data/root/files/test-shared-file") + environment.etc."nextcloud/mysecretfile".text = "foobar"; - with subtest("Create non-empty files with Transfer-Encoding: chunked"): - client.succeed( - 'dd if=/dev/urandom of=testfile.bin bs=1M count=10', - 'curl --fail -v -X PUT --header "Transfer-Encoding: chunked" --data-binary @testfile.bin "http://nextcloud/remote.php/webdav/testfile.bin" -u ${config.adminuser}:${config.adminpass}', - ) + specialisation.withoutMagick.configuration = { + services.nextcloud.enableImagemagick = false; + }; + }; + }; - # Verify the local and remote copies of the file are identical. - client_hash = client.succeed("sha256sum $out || true + ''; + nexcloudWithImagick = findInClosure "imagick" nodes.nextcloud.system.build.vm; + nextcloudWithoutImagick = findInClosure "imagick" nodes.nextcloud.specialisation.withoutMagick.configuration.system.build.vm; + in + # python + '' + with subtest("File is in proper nextcloud home"): + nextcloud.succeed("test -f ${nodes.nextcloud.services.nextcloud.datadir}/data/root/files/test-shared-file") - with subtest("secrets"): - assert "foobar" == nextcloud.succeed("nextcloud-occ config:system:get mysecret").strip() - ''; - } -) + with subtest("Closure checks"): + assert open("${nexcloudWithImagick}").read() != "" + assert open("${nextcloudWithoutImagick}").read() == "" + + with subtest("Davfs2"): + assert "hi" in client.succeed("cat /mnt/dav/test-shared-file") + + with subtest("Ensure SSE is disabled by default"): + nextcloud.succeed("grep -vE '^HBEGIN:oc_encryption_module' /var/lib/nextcloud-data/data/root/files/test-shared-file") + + with subtest("Create non-empty files with Transfer-Encoding: chunked"): + client.succeed( + 'dd if=/dev/urandom of=testfile.bin bs=1M count=10', + 'curl --fail -v -X PUT --header "Transfer-Encoding: chunked" --data-binary @testfile.bin "http://nextcloud/remote.php/webdav/testfile.bin" -u ${config.adminuser}:${config.adminpass}', + ) + + # Verify the local and remote copies of the file are identical. + client_hash = client.succeed("sha256sum &2 &") - nextcloud.wait_until_succeeds("journalctl -u nextcloud-notify_push | grep -q \"Sending ping to ${config.adminuser}\"") - ''; - } -) + with subtest("notify-push"): + client.execute("${lib.getExe pkgs.nextcloud-notify_push.passthru.test_client} http://nextcloud ${config.adminuser} ${config.adminpass} >&2 &") + nextcloud.wait_until_succeeds("journalctl -u nextcloud-notify_push | grep -q \"Sending ping to ${config.adminuser}\"") + ''; +} diff --git a/nixos/tests/nextcloud/with-mail.nix b/nixos/tests/nextcloud/with-mail.nix index 33eb9f960d1e..ace5b57ba7fa 100644 --- a/nixos/tests/nextcloud/with-mail.nix +++ b/nixos/tests/nextcloud/with-mail.nix @@ -1,102 +1,102 @@ { name, - pkgs, testBase, - system, package, ... }: -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; +{ + config, + lib, + pkgs, + ... +}: +let + certs = import ../common/acme/server/snakeoil-certs.nix; + domain = certs.domain; +in +{ + inherit name; - meta.maintainers = lib.teams.nextcloud.members; + meta.maintainers = lib.teams.nextcloud.members; - imports = [ testBase ]; + imports = [ testBase ]; - nodes = { - nextcloud = - { - config, - pkgs, - nodes, - ... - }: - { - security.pki.certificateFiles = [ certs.ca.cert ]; + nodes = { + nextcloud = + { + config, + pkgs, + nodes, + ... + }: + { + security.pki.certificateFiles = [ certs.ca.cert ]; - networking.extraHosts = '' - ${nodes.stalwart.networking.primaryIPAddress} ${domain} - ''; + networking.extraHosts = '' + ${nodes.stalwart.networking.primaryIPAddress} ${domain} + ''; - environment.etc."nextcloud/mail_smtppassword".text = "foobar"; + environment.etc."nextcloud/mail_smtppassword".text = "foobar"; - services.nextcloud = { - package = package pkgs; - config.dbtype = "sqlite"; + services.nextcloud = { + package = package pkgs; + config.dbtype = "sqlite"; - settings = { - mail_from_address = "alice"; - mail_domain = domain; - mail_smtpmode = "smtp"; - mail_smtphost = domain; - mail_smtpport = 587; - mail_smtpauth = true; - mail_smtpname = "alice"; - mail_send_plaintext_only = true; - }; - - secrets.mail_smtppassword = "/etc/nextcloud/mail_smtppassword"; + settings = { + mail_from_address = "alice"; + mail_domain = domain; + mail_smtpmode = "smtp"; + mail_smtphost = domain; + mail_smtpport = 587; + mail_smtpauth = true; + mail_smtpname = "alice"; + mail_send_plaintext_only = true; }; + + secrets.mail_smtppassword = "/etc/nextcloud/mail_smtppassword"; }; + }; - stalwart = - { pkgs, ... }: - { - imports = [ ../stalwart/stalwart-config.nix ]; + stalwart = + { pkgs, ... }: + { + imports = [ ../stalwart/stalwart-config.nix ]; - networking.firewall.allowedTCPPorts = [ 587 ]; + networking.firewall.allowedTCPPorts = [ 587 ]; - environment.systemPackages = [ - (pkgs.writers.writePython3Bin "test-imap-read" { } '' - from imaplib import IMAP4 + 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.')) - '') - ]; - }; - }; + 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") + 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") + 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") - ''; - } -) + stalwart.succeed("test-imap-read") + ''; +} diff --git a/nixos/tests/nextcloud/with-mysql-and-memcached.nix b/nixos/tests/nextcloud/with-mysql-and-memcached.nix index 222d257f9bc4..855e23108ad3 100644 --- a/nixos/tests/nextcloud/with-mysql-and-memcached.nix +++ b/nixos/tests/nextcloud/with-mysql-and-memcached.nix @@ -1,51 +1,51 @@ { name, - pkgs, testBase, - system, package, ... }: -with import ../../lib/testing-python.nix { inherit system pkgs; }; -runTest ( - { config, lib, ... }: - { - inherit name; +{ + config, + lib, + pkgs, + ... +}: +{ + inherit name; - meta.maintainers = lib.teams.nextcloud.members; + meta.maintainers = lib.teams.nextcloud.members; - imports = [ testBase ]; + imports = [ testBase ]; - nodes = { - nextcloud = - { config, pkgs, ... }: - { - services.nextcloud = { - package = package pkgs; - caching = { - apcu = true; - memcached = true; - }; - config.dbtype = "mysql"; - configureRedis = false; + nodes = { + nextcloud = + { config, pkgs, ... }: + { + services.nextcloud = { + package = package pkgs; + caching = { + apcu = true; + memcached = true; }; - - services.memcached.enable = true; + config.dbtype = "mysql"; + configureRedis = false; }; - }; - test-helpers.init = - let - configureMemcached = pkgs.writeScript "configure-memcached" '' - nextcloud-occ config:system:set memcached_servers 0 0 --value 127.0.0.1 --type string - nextcloud-occ config:system:set memcached_servers 0 1 --value 11211 --type integer - nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\APCu' --type string - nextcloud-occ config:system:set memcache.distributed --value '\OC\Memcache\Memcached' --type string - ''; - in - '' - nextcloud.succeed("${configureMemcached}") + services.memcached.enable = true; + }; + }; + + test-helpers.init = + let + configureMemcached = pkgs.writeScript "configure-memcached" '' + nextcloud-occ config:system:set memcached_servers 0 0 --value 127.0.0.1 --type string + nextcloud-occ config:system:set memcached_servers 0 1 --value 11211 --type integer + nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\APCu' --type string + nextcloud-occ config:system:set memcache.distributed --value '\OC\Memcache\Memcached' --type string ''; - } -) + in + '' + nextcloud.succeed("${configureMemcached}") + ''; +} diff --git a/nixos/tests/nextcloud/with-objectstore.nix b/nixos/tests/nextcloud/with-objectstore.nix index ce589db0a147..10b6a9b70fad 100644 --- a/nixos/tests/nextcloud/with-objectstore.nix +++ b/nixos/tests/nextcloud/with-objectstore.nix @@ -1,201 +1,196 @@ { name, - pkgs, testBase, - system, package, ... }: -with import ../../lib/testing-python.nix { inherit system pkgs; }; -runTest ( - { - config, - lib, - pkgs, - ... - }: - let - accessKey = "GK85bae09276df06d47a1ed2bf"; - secretKey = "eac031e3379beb05477a9c8381ade716c8f5860f1dffec915ae2a728a88c88c6"; +{ + config, + lib, + pkgs, + ... +}: +let + accessKey = "GK85bae09276df06d47a1ed2bf"; + secretKey = "eac031e3379beb05477a9c8381ade716c8f5860f1dffec915ae2a728a88c88c6"; - awsCfg = "${pkgs.writeText "aws.cfg" '' - [default] - endpoint_url=https://acme.test - aws_access_key_id=${accessKey} - aws_secret_access_key=${secretKey} - region=garage - ''}"; - in - { - inherit name; - meta.maintainers = lib.teams.nextcloud.members; + awsCfg = "${pkgs.writeText "aws.cfg" '' + [default] + endpoint_url=https://acme.test + aws_access_key_id=${accessKey} + aws_secret_access_key=${secretKey} + region=garage + ''}"; +in +{ + inherit name; + meta.maintainers = lib.teams.nextcloud.members; - imports = [ testBase ]; + imports = [ testBase ]; - nodes = { - nextcloud = - { - pkgs, - nodes, - ... - }: - { - services.nextcloud.package = package pkgs; - services.nextcloud.config.dbtype = "sqlite"; + nodes = { + nextcloud = + { + pkgs, + nodes, + ... + }: + { + services.nextcloud.package = package pkgs; + services.nextcloud.config.dbtype = "sqlite"; - environment.variables.AWS_CONFIG_FILE = awsCfg; - environment.variables.AWS_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt"; + environment.variables.AWS_CONFIG_FILE = awsCfg; + environment.variables.AWS_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt"; - services.nextcloud.config.objectstore.s3 = { - enable = true; - bucket = "nextcloud"; - verify_bucket_exists = true; - key = accessKey; - secretFile = "${pkgs.writeText "secretKey" secretKey}"; - hostname = "acme.test"; - useSsl = true; - port = 443; - usePathStyle = true; - region = "garage"; - }; - - security.pki.certificates = [ - (builtins.readFile ../common/acme/server/ca.cert.pem) - ]; - - environment.systemPackages = [ pkgs.awscli2 ]; - - # The dummy certs are for acme.test, so we pretend that's the FQDN - # of the garage VM. - networking.extraHosts = '' - ${nodes.garage.networking.primaryIPAddress} acme.test - ''; + services.nextcloud.config.objectstore.s3 = { + enable = true; + bucket = "nextcloud"; + verify_bucket_exists = true; + key = accessKey; + secretFile = "${pkgs.writeText "secretKey" secretKey}"; + hostname = "acme.test"; + useSsl = true; + port = 443; + usePathStyle = true; + region = "garage"; }; - client = - { pkgs, nodes, ... }: - { - environment.variables.AWS_CONFIG_FILE = awsCfg; - environment.variables.AWS_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt"; - environment.systemPackages = [ pkgs.awscli2 ]; + security.pki.certificates = [ + (builtins.readFile ../common/acme/server/ca.cert.pem) + ]; - security.pki.certificates = [ - (builtins.readFile ../common/acme/server/ca.cert.pem) - ]; - networking.extraHosts = '' - ${nodes.garage.networking.primaryIPAddress} acme.test - ''; - }; + environment.systemPackages = [ pkgs.awscli2 ]; - garage = - { pkgs, ... }: - { - security.pki.certificates = [ - (builtins.readFile ../common/acme/server/ca.cert.pem) - ]; + # The dummy certs are for acme.test, so we pretend that's the FQDN + # of the garage VM. + networking.extraHosts = '' + ${nodes.garage.networking.primaryIPAddress} acme.test + ''; + }; - services.garage = { - enable = true; - package = pkgs.garage_2; - settings = { - rpc_bind_addr = "[::]:3901"; - rpc_public_addr = "[::]:3901"; - rpc_secret = "81e5ab61625a5097c5953a09a16a524479c290ca01921560704395b830ad248d"; - replication_factor = 1; + client = + { pkgs, nodes, ... }: + { + environment.variables.AWS_CONFIG_FILE = awsCfg; + environment.variables.AWS_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt"; + environment.systemPackages = [ pkgs.awscli2 ]; - s3_api = { - s3_region = "garage"; - api_bind_addr = "[::]:3900"; - }; + security.pki.certificates = [ + (builtins.readFile ../common/acme/server/ca.cert.pem) + ]; + networking.extraHosts = '' + ${nodes.garage.networking.primaryIPAddress} acme.test + ''; + }; + + garage = + { pkgs, ... }: + { + security.pki.certificates = [ + (builtins.readFile ../common/acme/server/ca.cert.pem) + ]; + + services.garage = { + enable = true; + package = pkgs.garage_2; + settings = { + rpc_bind_addr = "[::]:3901"; + rpc_public_addr = "[::]:3901"; + rpc_secret = "81e5ab61625a5097c5953a09a16a524479c290ca01921560704395b830ad248d"; + replication_factor = 1; + + s3_api = { + s3_region = "garage"; + api_bind_addr = "[::]:3900"; }; }; - - services.nginx = { - enable = true; - recommendedProxySettings = true; - - virtualHosts."acme.test" = { - onlySSL = true; - sslCertificate = ../common/acme/server/acme.test.cert.pem; - sslCertificateKey = ../common/acme/server/acme.test.key.pem; - locations."/".proxyPass = "http://127.0.0.1:3900"; - }; - }; - - networking.extraHosts = '' - 127.0.0.1 acme.test - ''; - - environment.systemPackages = [ pkgs.gawk ]; - - virtualisation.diskSize = 2 * 1024; - - networking.firewall.allowedTCPPorts = [ - 3900 - 80 - 443 - ]; }; - }; - test-helpers.provision = '' - garage.start() - garage.wait_for_open_port(3900) - garage.wait_for_unit("nginx.service") - garage.wait_for_open_port(443) + services.nginx = { + enable = true; + recommendedProxySettings = true; - node_id = garage.succeed("garage status | tail -n1 | awk '{ print $1 }'") - garage.succeed( - "garage status", - f"garage layout assign -c 1GB -z garage {node_id}", - "garage layout apply --version 1", - "garage key import ${accessKey} ${secretKey} --yes", - "garage bucket create nextcloud", - "garage key list >&2", - "garage bucket allow --read --write --owner nextcloud --key ${accessKey}" - ) + virtualHosts."acme.test" = { + onlySSL = true; + sslCertificate = ../common/acme/server/acme.test.cert.pem; + sslCertificateKey = ../common/acme/server/acme.test.key.pem; + locations."/".proxyPass = "http://127.0.0.1:3900"; + }; + }; + + networking.extraHosts = '' + 127.0.0.1 acme.test + ''; + + environment.systemPackages = [ pkgs.gawk ]; + + virtualisation.diskSize = 2 * 1024; + + networking.firewall.allowedTCPPorts = [ + 3900 + 80 + 443 + ]; + }; + }; + + test-helpers.provision = '' + garage.start() + garage.wait_for_open_port(3900) + garage.wait_for_unit("nginx.service") + garage.wait_for_open_port(443) + + node_id = garage.succeed("garage status | tail -n1 | awk '{ print $1 }'") + garage.succeed( + "garage status", + f"garage layout assign -c 1GB -z garage {node_id}", + "garage layout apply --version 1", + "garage key import ${accessKey} ${secretKey} --yes", + "garage bucket create nextcloud", + "garage key list >&2", + "garage bucket allow --read --write --owner nextcloud --key ${accessKey}" + ) + ''; + + test-helpers.extraTests = + { nodes, ... }: + '' + + with subtest("File is not on the filesystem"): + nextcloud.succeed("test ! -e ${nodes.nextcloud.services.nextcloud.home}/data/root/files/test-shared-file") + + with subtest("Check if file is in S3"): + files = [ + f.rsplit(' ', 2) + for f in nextcloud.succeed('aws s3 ls s3://nextcloud/|sort').strip().split('\n') + ] + print(files) + + # Cannot assert an exact number here, nc27 writes more stuff initially into S3. + # For now let's assume it's always the most recently added file. + assert len(files) > 0, f""" + Expected to have at least one object in garage/nextcloud. But `aws s3 ls` gave output: + + '{files}' + """ + + _, size, file = files[-1] + + assert size == "3", f""" + Expected size of uploaded file to be 3 bytes, got {size} + """ + + assert file.startswith('urn:oid'), """ + Expected filename to start with 'urn:oid', instead got '{file}. + """ + + with subtest("Test download from S3"): + client.succeed( + f"aws s3 cp s3://nextcloud/{file} test " + + "--ca-bundle /etc/ssl/certs/ca-bundle.crt" + ) + + client.succeed("test hi = $(cat test)") ''; - - test-helpers.extraTests = - { nodes, ... }: - '' - - with subtest("File is not on the filesystem"): - nextcloud.succeed("test ! -e ${nodes.nextcloud.services.nextcloud.home}/data/root/files/test-shared-file") - - with subtest("Check if file is in S3"): - files = [ - f.rsplit(' ', 2) - for f in nextcloud.succeed('aws s3 ls s3://nextcloud/|sort').strip().split('\n') - ] - print(files) - - # Cannot assert an exact number here, nc27 writes more stuff initially into S3. - # For now let's assume it's always the most recently added file. - assert len(files) > 0, f""" - Expected to have at least one object in garage/nextcloud. But `aws s3 ls` gave output: - - '{files}' - """ - - _, size, file = files[-1] - - assert size == "3", f""" - Expected size of uploaded file to be 3 bytes, got {size} - """ - - assert file.startswith('urn:oid'), """ - Expected filename to start with 'urn:oid', instead got '{file}. - """ - - with subtest("Test download from S3"): - client.succeed( - f"aws s3 cp s3://nextcloud/{file} test " - + "--ca-bundle /etc/ssl/certs/ca-bundle.crt" - ) - - client.succeed("test hi = $(cat test)") - ''; - } -) +} diff --git a/nixos/tests/nextcloud/with-postgresql-and-redis.nix b/nixos/tests/nextcloud/with-postgresql-and-redis.nix index 26bc8506cbd6..68d364fdbf2d 100644 --- a/nixos/tests/nextcloud/with-postgresql-and-redis.nix +++ b/nixos/tests/nextcloud/with-postgresql-and-redis.nix @@ -1,82 +1,82 @@ { name, - pkgs, testBase, - system, package, ... }: -with import ../../lib/testing-python.nix { inherit system pkgs; }; -runTest ( - { config, lib, ... }: - { - inherit name; - meta.maintainers = lib.teams.nextcloud.members; +{ + config, + lib, + pkgs, + ... +}: +{ + inherit name; + meta.maintainers = lib.teams.nextcloud.members; - imports = [ testBase ]; + imports = [ testBase ]; - nodes = { - nextcloud = - { - config, - pkgs, - lib, - ... - }: - { - environment.systemPackages = [ pkgs.jq ]; - services.nextcloud = { - package = package pkgs; - caching = { - apcu = false; - redis = true; - memcached = false; - }; - config.dbtype = "pgsql"; - notify_push = { - enable = true; - bendDomainToLocalhost = true; - logLevel = "debug"; - }; - extraAppsEnable = true; - extraApps = with config.services.nextcloud.package.packages.apps; { - inherit notes; - }; - settings.trusted_proxies = [ "::1" ]; + nodes = { + nextcloud = + { + config, + pkgs, + lib, + ... + }: + { + environment.systemPackages = [ pkgs.jq ]; + services.nextcloud = { + package = package pkgs; + caching = { + apcu = false; + redis = true; + memcached = false; }; - - services.redis.servers."nextcloud".enable = true; - services.redis.servers."nextcloud".port = 6379; + config.dbtype = "pgsql"; + notify_push = { + enable = true; + bendDomainToLocalhost = true; + logLevel = "debug"; + }; + extraAppsEnable = true; + extraApps = with config.services.nextcloud.package.packages.apps; { + inherit notes; + }; + settings.trusted_proxies = [ "::1" ]; }; - }; - test-helpers.init = - let - configureRedis = pkgs.writeScript "configure-redis" '' - nextcloud-occ config:system:set redis 'host' --value 'localhost' --type string - nextcloud-occ config:system:set redis 'port' --value 6379 --type integer - nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\Redis' --type string - nextcloud-occ config:system:set memcache.locking --value '\OC\Memcache\Redis' --type string - ''; - in - '' - nextcloud.succeed("${configureRedis}") + services.redis.servers."nextcloud".enable = true; + services.redis.servers."nextcloud".port = 6379; + }; + }; + + test-helpers.init = + let + configureRedis = pkgs.writeScript "configure-redis" '' + nextcloud-occ config:system:set redis 'host' --value 'localhost' --type string + nextcloud-occ config:system:set redis 'port' --value 6379 --type integer + nextcloud-occ config:system:set memcache.local --value '\OC\Memcache\Redis' --type string + nextcloud-occ config:system:set memcache.locking --value '\OC\Memcache\Redis' --type string ''; - - test-helpers.extraTests = '' - with subtest("notify-push"): - client.execute("${lib.getExe pkgs.nextcloud-notify_push.passthru.test_client} http://nextcloud ${config.adminuser} ${config.adminpass} >&2 &") - nextcloud.wait_until_succeeds("journalctl -u nextcloud-notify_push | grep -q \"Sending ping to ${config.adminuser}\"") - - with subtest("Redis is used for caching"): - # redis cache should not be empty - assert nextcloud.succeed('redis-cli --json KEYS "*" | jq length').strip() != "0", """ - redis-cli for keys * returned 0 entries - """ - - with subtest("No code is returned when requesting PHP files (regression test)"): - nextcloud.fail("curl -f http://nextcloud/nix-apps/notes/lib/AppInfo/Application.php") + in + '' + nextcloud.succeed("${configureRedis}") ''; - } -) + + test-helpers.extraTests = '' + with subtest("notify-push"): + client.execute("${lib.getExe pkgs.nextcloud-notify_push.passthru.test_client} http://nextcloud ${config.adminuser} ${config.adminpass} >&2 &") + nextcloud.wait_until_succeeds("journalctl -u nextcloud-notify_push | grep -q \"Sending ping to ${config.adminuser}\"") + + with subtest("Redis is used for caching"): + # redis cache should not be empty + assert nextcloud.succeed('redis-cli --json KEYS "*" | jq length').strip() != "0", """ + redis-cli for keys * returned 0 entries + """ + + with subtest("No code is returned when requesting PHP files (regression test)"): + nextcloud.fail("curl -f http://nextcloud/nix-apps/notes/lib/AppInfo/Application.php") + ''; +} From e8582d4da5905c5134c9669db5158cb7fd319994 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 14 Nov 2026 19:09:53 +0100 Subject: [PATCH 5/7] nixos/nextcloud: allow nspawn tests, migrate with-declarative-redis-and-secrets --- nixos/tests/nextcloud/default.nix | 49 ++++++++++++++----- .../with-declarative-redis-and-secrets.nix | 3 +- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/nixos/tests/nextcloud/default.nix b/nixos/tests/nextcloud/default.nix index d7899e96f691..4280b7d59a54 100644 --- a/nixos/tests/nextcloud/default.nix +++ b/nixos/tests/nextcloud/default.nix @@ -5,7 +5,8 @@ }: let - testBase = + mkTestBase = + flavor: { config, pkgs, ... }: { imports = [ @@ -33,7 +34,7 @@ let # This needs to be a "secure" password, since the password_policy app is enabled after installation and will forbid "simple" passwords. adminpass = lib.mkDefault "+CVpTwaOEktxsFc6"; - nodes = { + ${flavor} = { client = { ... }: { }; nextcloud = { lib, ... }: @@ -49,7 +50,7 @@ let }; testScript = - args@{ nodes, ... }: + args@{ nodes, containers, ... }: let inherit (config) test-helpers; rclone = "${pkgs.writeShellScript "rclone" '' @@ -123,27 +124,49 @@ let attr: package: lib.mapAttrs ( - name: path: + name: + { + path, + flavor ? "nodes", + }: runTest ( import path { inherit - testBase package runTest + flavor ; name = "${attr}-${name}"; + testBase = mkTestBase flavor; } ) ) { - basic = ./basic.nix; - home-bindmout = ./home-bindmount.nix; - home-mount = ./home-mount.nix; - with-declarative-redis-and-secrets = ./with-declarative-redis-and-secrets.nix; - with-mysql-and-memcached = ./with-mysql-and-memcached.nix; - with-postgresql-and-redis = ./with-postgresql-and-redis.nix; - with-objectstore = ./with-objectstore.nix; - with-mail = ./with-mail.nix; + basic = { + path = ./basic.nix; + }; + home-bindmout = { + path = ./home-bindmount.nix; + }; + home-mount = { + path = ./home-mount.nix; + }; + with-declarative-redis-and-secrets = { + path = ./with-declarative-redis-and-secrets.nix; + flavor = "containers"; + }; + with-mysql-and-memcached = { + path = ./with-mysql-and-memcached.nix; + }; + with-postgresql-and-redis = { + path = ./with-postgresql-and-redis.nix; + }; + with-objectstore = { + path = ./with-objectstore.nix; + }; + with-mail = { + path = ./with-mail.nix; + }; }; in lib.mapAttrs genTests packages diff --git a/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix b/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix index 3552988a1087..859ebe8cb376 100644 --- a/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix +++ b/nixos/tests/nextcloud/with-declarative-redis-and-secrets.nix @@ -2,6 +2,7 @@ name, testBase, package, + flavor ? "containers", ... }: @@ -20,7 +21,7 @@ in imports = [ testBase ]; - nodes = { + ${flavor} = { nextcloud = { config, pkgs, ... }: { From ed865a39287a3ec1fba6b026309666f2b3e890b1 Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 14 Nov 2026 19:22:41 +0100 Subject: [PATCH 6/7] nixos/nextcloud: migrate mail/mysql/postgresql/objectstore to nspawn --- nixos/tests/nextcloud/default.nix | 4 ++++ nixos/tests/nextcloud/with-mail.nix | 12 +++++------ .../nextcloud/with-mysql-and-memcached.nix | 3 ++- nixos/tests/nextcloud/with-objectstore.nix | 20 +++++++++++-------- .../nextcloud/with-postgresql-and-redis.nix | 3 ++- 5 files changed, 26 insertions(+), 16 deletions(-) diff --git a/nixos/tests/nextcloud/default.nix b/nixos/tests/nextcloud/default.nix index 4280b7d59a54..6e38d75380ad 100644 --- a/nixos/tests/nextcloud/default.nix +++ b/nixos/tests/nextcloud/default.nix @@ -157,15 +157,19 @@ let }; with-mysql-and-memcached = { path = ./with-mysql-and-memcached.nix; + flavor = "containers"; }; with-postgresql-and-redis = { path = ./with-postgresql-and-redis.nix; + flavor = "containers"; }; with-objectstore = { path = ./with-objectstore.nix; + flavor = "containers"; }; with-mail = { path = ./with-mail.nix; + flavor = "containers"; }; }; in diff --git a/nixos/tests/nextcloud/with-mail.nix b/nixos/tests/nextcloud/with-mail.nix index ace5b57ba7fa..c783710d5f09 100644 --- a/nixos/tests/nextcloud/with-mail.nix +++ b/nixos/tests/nextcloud/with-mail.nix @@ -2,12 +2,14 @@ name, testBase, package, + flavor ? "containers", ... }: -{ +args@{ config, lib, - pkgs, + containers, + nodes, ... }: let @@ -21,19 +23,17 @@ in imports = [ testBase ]; - nodes = { + ${flavor} = { nextcloud = { - config, pkgs, - nodes, ... }: { security.pki.certificateFiles = [ certs.ca.cert ]; networking.extraHosts = '' - ${nodes.stalwart.networking.primaryIPAddress} ${domain} + ${args.${flavor}.stalwart.networking.primaryIPAddress} ${domain} ''; environment.etc."nextcloud/mail_smtppassword".text = "foobar"; diff --git a/nixos/tests/nextcloud/with-mysql-and-memcached.nix b/nixos/tests/nextcloud/with-mysql-and-memcached.nix index 855e23108ad3..a2cbd8dffcdb 100644 --- a/nixos/tests/nextcloud/with-mysql-and-memcached.nix +++ b/nixos/tests/nextcloud/with-mysql-and-memcached.nix @@ -2,6 +2,7 @@ name, testBase, package, + flavor ? "containers", ... }: @@ -18,7 +19,7 @@ imports = [ testBase ]; - nodes = { + ${flavor} = { nextcloud = { config, pkgs, ... }: { diff --git a/nixos/tests/nextcloud/with-objectstore.nix b/nixos/tests/nextcloud/with-objectstore.nix index 10b6a9b70fad..532d2c1a9377 100644 --- a/nixos/tests/nextcloud/with-objectstore.nix +++ b/nixos/tests/nextcloud/with-objectstore.nix @@ -2,13 +2,16 @@ name, testBase, package, + flavor ? "containers", ... }: -{ +args@{ config, lib, pkgs, + nodes, + containers, ... }: let @@ -29,11 +32,10 @@ in imports = [ testBase ]; - nodes = { + ${flavor} = { nextcloud = { pkgs, - nodes, ... }: { @@ -65,12 +67,12 @@ in # The dummy certs are for acme.test, so we pretend that's the FQDN # of the garage VM. networking.extraHosts = '' - ${nodes.garage.networking.primaryIPAddress} acme.test + ${args.${flavor}.garage.networking.primaryIPAddress} acme.test ''; }; client = - { pkgs, nodes, ... }: + { pkgs, ... }: { environment.variables.AWS_CONFIG_FILE = awsCfg; environment.variables.AWS_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt"; @@ -80,7 +82,7 @@ in (builtins.readFile ../common/acme/server/ca.cert.pem) ]; networking.extraHosts = '' - ${nodes.garage.networking.primaryIPAddress} acme.test + ${args.${flavor}.garage.networking.primaryIPAddress} acme.test ''; }; @@ -154,11 +156,13 @@ in ''; test-helpers.extraTests = - { nodes, ... }: + { ... }: '' with subtest("File is not on the filesystem"): - nextcloud.succeed("test ! -e ${nodes.nextcloud.services.nextcloud.home}/data/root/files/test-shared-file") + nextcloud.succeed("test ! -e ${ + args.${flavor}.nextcloud.services.nextcloud.home + }/data/root/files/test-shared-file") with subtest("Check if file is in S3"): files = [ diff --git a/nixos/tests/nextcloud/with-postgresql-and-redis.nix b/nixos/tests/nextcloud/with-postgresql-and-redis.nix index 68d364fdbf2d..7b9b66981d35 100644 --- a/nixos/tests/nextcloud/with-postgresql-and-redis.nix +++ b/nixos/tests/nextcloud/with-postgresql-and-redis.nix @@ -2,6 +2,7 @@ name, testBase, package, + flavor ? "containers", ... }: @@ -17,7 +18,7 @@ imports = [ testBase ]; - nodes = { + ${flavor} = { nextcloud = { config, From a61368db44891694a989f802417b6116c73cd83b Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sat, 14 Nov 2026 19:27:28 +0100 Subject: [PATCH 7/7] nixos/nextcloud: accept flavor everywhere, but reject containers when not supported The entire wrapper is built to support both, however some tests require the VM backend, so we make sure with an assertion that this is rejected. --- nixos/tests/nextcloud/basic.nix | 26 ++++++++++++++++++------ nixos/tests/nextcloud/home-bindmount.nix | 5 ++++- nixos/tests/nextcloud/home-mount.nix | 5 ++++- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/nixos/tests/nextcloud/basic.nix b/nixos/tests/nextcloud/basic.nix index 59123fa35306..1177fd292ac2 100644 --- a/nixos/tests/nextcloud/basic.nix +++ b/nixos/tests/nextcloud/basic.nix @@ -2,10 +2,20 @@ name, testBase, package, + flavor ? "nodes", ... }: -{ config, lib, pkgs, ... }: +assert flavor == "nodes"; + +args@{ + config, + lib, + pkgs, + nodes, + containers, + ... +}: { inherit name; meta = { @@ -14,7 +24,7 @@ imports = [ testBase ]; - nodes = { + ${flavor} = { # The only thing the client needs to do is download a file. client = { pkgs, ... }: @@ -73,7 +83,7 @@ }; test-helpers.extraTests = - { nodes, ... }: + { ... }: let findInClosure = what: drv: @@ -89,13 +99,17 @@ test -e graph grep "$what" graph >$out || true ''; - nexcloudWithImagick = findInClosure "imagick" nodes.nextcloud.system.build.vm; - nextcloudWithoutImagick = findInClosure "imagick" nodes.nextcloud.specialisation.withoutMagick.configuration.system.build.vm; + nexcloudWithImagick = findInClosure "imagick" args.${flavor}.nextcloud.system.build.vm; + nextcloudWithoutImagick = + findInClosure "imagick" + args.${flavor}.nextcloud.specialisation.withoutMagick.configuration.system.build.vm; in # python '' with subtest("File is in proper nextcloud home"): - nextcloud.succeed("test -f ${nodes.nextcloud.services.nextcloud.datadir}/data/root/files/test-shared-file") + nextcloud.succeed("test -f ${ + args.${flavor}.nextcloud.services.nextcloud.datadir + }/data/root/files/test-shared-file") with subtest("Closure checks"): assert open("${nexcloudWithImagick}").read() != "" diff --git a/nixos/tests/nextcloud/home-bindmount.nix b/nixos/tests/nextcloud/home-bindmount.nix index c98f76010b9f..b0b295dd1fda 100644 --- a/nixos/tests/nextcloud/home-bindmount.nix +++ b/nixos/tests/nextcloud/home-bindmount.nix @@ -2,9 +2,12 @@ name, testBase, package, + flavor ? "nodes", ... }: +assert flavor == "nodes"; + { pkgs, lib, ... }: { inherit name; @@ -12,7 +15,7 @@ imports = [ testBase ]; - nodes.nextcloud = { pkgs, ... }: { + ${flavor}.nextcloud = { pkgs, ... }: { # Make sure that inside our tmpfs mount an actual directory for Nextcloud exists. boot.initrd.systemd.tmpfiles.settings."nextcloud"."/sysroot/mnt/nextcloud".d = { }; diff --git a/nixos/tests/nextcloud/home-mount.nix b/nixos/tests/nextcloud/home-mount.nix index aa53e5eba5ff..aab4bf9a77a2 100644 --- a/nixos/tests/nextcloud/home-mount.nix +++ b/nixos/tests/nextcloud/home-mount.nix @@ -2,9 +2,12 @@ name, testBase, package, + flavor ? "nodes", ... }: +assert flavor == "nodes"; + { config, lib, ... }: { inherit name; @@ -12,7 +15,7 @@ imports = [ testBase ]; - nodes.nextcloud = { pkgs, ... }: { + ${flavor}.nextcloud = { pkgs, ... }: { fileSystems."/mnt" = { fsType = "tmpfs"; device = "tmpfs";