How can I refer to an attribute of config in foo in the above, e.g. foo = config.networking.hostName;?
I understand that a module can be a function, like ( { config, ... }: { stuff } ) but I’m not sure how I can pass config into the arguments of simple-nixos-mailserver.nixosModule { config.myattribute } .
error: anonymous function at /nix/store/5zhjwvmif5xidfffvaxxrz0xa7v0mj0f-source/default.nix:17:1 called without required argument 'config'
at /nix/store/mmv2qc4728i2pwdr9knckr205v9lrk02-source/hosts/blah/host.nix:14:35:
14| ( { config, pkgs, lib, ... }: inputs.simple-nixos-mailserver.nixosModule {
| ^
I guess this is supposed to work at least if foo is properly defined as a module option and if you are not creating some sort of infinite reduction (like if simple-nixos-server exports the value of foo then you define the value of foo depending on its own value)… And it’s hard to tell what’s wrong exactly as you cut the message after error message ! Can you maybe provide the real error message and ideally a minimal (Minimal Working Example, MWE) flake config that has this issue?
The logic of enabling the mailserver based on whether ssh is enabled is not really my intention, just an example. The real goal is actually to refer to agenix-managed secrets in the mailserver config, typically you put a secret in a file and then do something like mySecretFile = config.age.secrets."my-secret".path;.
In your last example you’re trying to access config variable outside the function that has this argument.
You should define this module as a function and then use this argument:
In your original example you’re using simple-nixos-mailserver.nixosModule as a function that returns a module, but it is a module itself, so it complains that it doesn’t receive necessary arguments, but instead it gets only mailserver argument. simple-nixos-mailserver.nixosModule and the attribute set that follows it in your first example are not a function call, they are just separate elements of the modules list. Nix language is confusing like that:
nix-repl> f = x: x + 1
nix-repl> a = 1
nix-repl> f a
2
nix-repl> [f a]
[ «lambda @ (string):1:2» 1 ]
nix-repl> [(f a)]
[ 2 ]