From ef3a9736aa216af5ecb0c9119ee7c284bc0b568c Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 2 Aug 2026 14:26:37 +0200 Subject: [PATCH] nixos/nextcloud: add test verifying that bind-mounts and special places of /var/lib/nextcloud are OK This is a regular source for confusion and had no test-coverage so far, so adding two tests that * Make sure Nextcloud running in a different location (tmpfs mount here as mock for the mount of a different disk). * A bind-mount of Nextcloud from a disk-mount to /var/lib/nextcloud can be created. --- nixos/tests/nextcloud/default.nix | 2 + nixos/tests/nextcloud/home-bindmount.nix | 68 ++++++++++++++++++++++++ nixos/tests/nextcloud/home-mount.nix | 32 +++++++++++ 3 files changed, 102 insertions(+) create mode 100644 nixos/tests/nextcloud/home-bindmount.nix create mode 100644 nixos/tests/nextcloud/home-mount.nix diff --git a/nixos/tests/nextcloud/default.nix b/nixos/tests/nextcloud/default.nix index 2cb226e353da..6c7ef18068e7 100644 --- a/nixos/tests/nextcloud/default.nix +++ b/nixos/tests/nextcloud/default.nix @@ -136,6 +136,8 @@ let 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 diff --git a/nixos/tests/nextcloud/home-bindmount.nix b/nixos/tests/nextcloud/home-bindmount.nix new file mode 100644 index 000000000000..a48882544508 --- /dev/null +++ b/nixos/tests/nextcloud/home-bindmount.nix @@ -0,0 +1,68 @@ +{ + name, + pkgs, + testBase, + system, + ... +}: + +with import ../../lib/testing-python.nix { inherit system pkgs; }; +runTest ( + { lib, ... }: + { + inherit name; + meta.maintainers = lib.teams.nextcloud.members; + + imports = [ testBase ]; + + nodes.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 = { }; + + boot.initrd.systemd.mounts = [ + # Create a mocked /mnt/nextcloud. Only a tmpfs here, but in reality this could e.g. + # be the mount of a larger disk. + { + unitConfig.DefaultDependencies = "no"; + conflicts = [ "umount.target" ]; + wantedBy = [ "initrd.target" ]; + before = [ "systemd-tmpfiles-setup-sysroot.service" ]; + options = "x-initrd.mount"; + where = "/sysroot/mnt"; + what = "tmpfs"; + type = "tmpfs"; + } + # Bind some directory to /var/lib/nextcloud, the place that the Nextcloud module expects + # by default. + { + conflicts = [ "umount.target" ]; + wantedBy = [ "initrd.target" ]; + before = [ "systemd-tmpfiles-setup-sysroot.service" ]; + options = "x-initrd.mount,bind"; + where = "/sysroot/var/lib/nextcloud"; + what = "/sysroot/mnt/nextcloud"; + type = "none"; + } + ]; + environment.systemPackages = [ + pkgs.util-linux + ]; + services.nextcloud = { + config.dbtype = "sqlite"; + }; + }; + + test-helpers.init = '' + import json + mnts = json.loads(nextcloud.succeed("findmnt /var/lib/nextcloud -J"))["filesystems"] + t.assertEqual(1, len(mnts)) + mnt = mnts[0] + t.assertEqual("tmpfs[/nextcloud]", mnt["source"]) + t.assertEqual("/var/lib/nextcloud", mnt["target"]) + ''; + + test-helpers.extraTests = '' + nextcloud.succeed("test -d /mnt/nextcloud/data/root") + ''; + } +) diff --git a/nixos/tests/nextcloud/home-mount.nix b/nixos/tests/nextcloud/home-mount.nix new file mode 100644 index 000000000000..a79f2fdd97b3 --- /dev/null +++ b/nixos/tests/nextcloud/home-mount.nix @@ -0,0 +1,32 @@ +{ + name, + pkgs, + testBase, + system, + ... +}: + +with import ../../lib/testing-python.nix { inherit system pkgs; }; +runTest ( + { config, lib, ... }: + { + inherit name; + meta.maintainers = lib.teams.nextcloud.members; + + imports = [ testBase ]; + + nodes.nextcloud = { pkgs, ... }: { + system.activationScripts.nc-mock-mount = { + deps = [ "users" ]; + text = '' + ${pkgs.coreutils}/bin/mkdir -p /mnt + ${pkgs.util-linux}/bin/mount -t tmpfs tmpfs /mnt + ''; + }; + services.nextcloud = { + config.dbtype = "sqlite"; + home = "/mnt/nextcloud"; + }; + }; + } +)