wifi="wpl123" ;
if "${wifi}" != "" then interfaces."${wifi}".useDHCP = true ;
I would like to only add the line (the interface) to the config if "${wifi}" != "" (if it exists)
Wouldn’t like to do it fixed via a import script per device
How to do this in nix?
the current inputs:
(the aim is to provide a config for all devices in for every human readable and adjustable manner ~> json)
all parameter/variables not in in a specific device (like "P3") will be checked in "default".
Thanks for the idea
but interfaces is an already defined configuration.nix", "message": "attribute 'interfaces' at /home/ae/ae_share_VM/z_DS_setup/vm_setup/NixOS/configuration/configuration.nix:685:7 already defined",
I only want to add a wifi device (with its name and the value true for useDHCP) if the device has an internal/external wifi chip - interfaces."${wifi}"
(at the moment I define if a device has a wifi chip via a string in a config file [where all devices are listed/configured])
before configuring the value for interfaces."${wifi}".useDHCP, the device "${wifi}" should only be created if the device has an wifi chip
(It is possible to create "${wifi}" as empty sting but that leads to a longer start up of the OS because is trying to load/configure the “”-wifi device )
As I said, you’re going to want to learn about the module system. If one module already has an interfaces definition (e.g. for the other interfaces you care about), you’ll need a separate module to do the mkIf thing. You can either include that module via the imports line, or by having multiple module configs in a mkMerge call. I suggest you read the section.
as I wrote, I don’t want to create a import script for each device
merge could be needed (done automatically by nix) BUT only if interfaces."${wifi}" exists (and wifi="" should be treated as not existing)
The focus here probably shouldn’t be at the interfaces but interfaces."${wifi}"
The question is how to create interfaces."${wifi}" depending on other variables (/if the device has an wifi chip)
Ah, I misread. No I wasn’t suggesting a different import for each device. I was suggesting that you make a custom option that provides conditional configuration depending on how each device has configured its wifi definition.