How to configure dnsmasq under NetworkManager?

I can’t figure out how to configure dnsmasq under /etc/NetworkManager/dnsmasq.d/dnsmasq-nm.conf and /etc/NetworkManager/dnsmasq-shared.d/dnsmasq-shared-nm.conf.

In networking.networkmanager.dns it is stated that:

It is possible to pass custom options to the dnsmasq instance by adding them to files in the /etc/NetworkManager/dnsmasq.d/ directory.

I played around with environment.etc which is really close to what i want, but i don’t know how to make it place files in subdirectories, if that is possible.

Can i do this in a clean NixOS way, any help is appreciated? :slight_smile:

I haven’t done this myself but in the description for environment.etc it looks like you simply include a slash in the key name, as in

  environment.etc = {
    "NetworkManager/dnsmasq.d/foo".text = "contents of file";

Perfect solution, thank you!