Referencing 'networking.hostName' in another variable definition

This is probably a stupid question but I’m essentially assigning data to a variable and I’m trying to refer to the data stored in “networking.hostName” inside the assignment.

variable = ''${pkgs.opentofu} lorem ipsum ${networking.hostName} other string data going here'';

Trying to rebuild my configuration with this vs just entering the literal string of the hostname leads to errors. I’m assuming I’m making a stupid mistake as I’m just getting into writing more with nix.

Thanks in advance for any help

You need two things:

  1. Add config to the arguments in the module where you’re trying to use this (you probably already have pkgs in that list of arguments)
  2. Now you can use config.networking.hostName

I didn’t realize I needed to prepend that to the variable reference. That solved my problem. Thank you.