anchor.diff:  
   let
     cfg = config.networking.networkmanager;
  +
  +  dynamicHostsEnabled =
  +    cfg.dynamicHosts.enable && cfg.dynamicHosts.hostsDirs != {};
   
     # /var/lib/misc is for dnsmasq.leases.
     stateDirs = "/var/lib/NetworkManager /var/lib/dhclient /var/lib/misc";
  
positive.code:           so you don't need to to that yourself.
          '';
        };
      };
    };
  
  
negative.code:       ++ lib.imap1 (i: s: {
          inherit (s) source;
          target = "NetworkManager/dispatcher.d/${dispatcherTypesSubdirMap.${s.type}}03userscript${lib.fixedWidthNumber 4 i}";
        }) cfg.dispatcherScripts
        ++ optional (dynamicHostsEnabled)
             { target = "NetworkManager/dnsmasq.d/dyndns.conf";
               text = concatMapStrings (n: ''
                 hostsdir=/run/NetworkManager/hostsdirs/${n}
               '') (attrNames cfg.dynamicHosts.hostsDirs);
             };
  
      environment.systemPackages = cfg.packages;
  
  