Reusing a variable in my configuration is giving a type error

I have a firewall definition in my Nixos configuration.nix. I also declared ports in the Zammad pkg.

services.zammad = {
port = 8000;
}

For my networking, instead of declaring the value again, like this
networking.firewall.allowedTCPPorts = [ 7944 2595 ];

I would like to do something like
networking.firewall.allowedTCPPorts = [ 7944 options.services.zammad.port ];

When I tried the above it failed with

  error: A definition for option `networking.firewall.allowedTCPPorts."│  # networking.firewall.allowedUDPPorts = [ ... ];
[definition 1-entry 2]"' is not of type `16 bit unsigned integer; between 0 │  # Or disable the firewall altogether.
and 65535 (both inclusive)'. Definition values:                             │  # networking.firewall.enable = false;
       - In `/etc/nixos/configuration.nix':                                 │
           {                                                                │  # This value determines the NixOS release from which the default
             __toString = <function>;                                       │  # settings for stateful data, like file locations and database versions
             _type = "option";                                              │  # on your system were taken. It‘s perfectly fine and recommended to lea
             declarationPositions = [                                       │ve
               {                                                            │  # this value at the release version of the first install of this system
           ...                                       

In MyNixOS it says that services.zammard.port is a 16 bit unsigned integer. So, I’m not sure what the issue is.

use config, not options, to access the final value

I can confirm, your advice was the golden ticket!

The working solution was config.services.zammad.port indeed returned a number as a value.

May I ask of you to provide an overview in comparison between options and config, for sake of completeness? Curious that’s all :slight_smile:

If you want to access the option’s declaration (default value, description, or other attrs) then use options.
If you want the finally-merged value then use config, as mentioned here.

There’s also definitionsWithLocations, which is confusingly under options

The NixOS manual should be helpful in terms of writing your own modules.