I'm misunderstanding something

TL;DR: I think the problem in your code is double import of agenix.nixosModules.default. Get rid of agenix import in nextcloud.nix.

The central ideas behind the way Nix processes modules is merging and fixed points in functions. If I recall correctly, when evaluating a configuration, the order is:

  1. Collect and merge all the imports from all the modules
  2. Merge all the .options from all modules and imports
  3. Merge .config from all modules and imports

“Fixed point” in this context means “apply a function until output equals input and there is no point in proceeding”. In this case – merge modules until it stops making sense or abort if it looks like an infinite recursion.

This part passes agenix into the outputs, which then gets inherited to the inputs of the in block that follows. Then inside the nixosConfigurations.nix0.modules I load(?) the agenix module. That should make it available to other modules, I thnk.

What’s happening here is that you are bringing all .options and .config from agenix.nixosModules.default into your system configuration.

The flake has passed the agenix argument as an attribute set that refers to the agenix module contents?

“agenix” here is the “agenix” -the-flake-input.

That would get passed along implicitly to nextcloud.nix via the imports section, I think?

Nope, the module gets merged into a giant merged attribute set (see above) and that’s how modules can share data.

As an aside, is there anyone out there doing Nix office hours? I feel like 10 minutes with an expert would clue me in on the concepts I’m missing and get this to work.

There’s Nix office hours by Tweag.