Change:
I am currently struggling with the ability to configure a valid federation between two Prometheus instances. Instance A is my Prometheus master and import all scraped values from Instance B with a specific label. The current module implementation does not result in a valid federation configuration (or i dont get it how to properly escape it). A minimal setup for a federation is The problematic part is here the field. From the match Params has to contain a line like . The specific params from does define the type as a attribute list of strings, so my example should result in the desired result. Please notice that the quotes around the LabelValue are important in that case otherwise it does not result in a valid request to a federation instance. Steps to reproduce the behavior: example code form above generated configuration file for missing quotes. (Optional) Have another Prometheus instance set up and data available to be loaded and verity that no values can be imported The generated config from aboves example is Which is missing the quotes, which are required to be a valid configuration. The actual error the server may get on loading the data could be something like that (I did just fill in the params as GET like the documentation of Prometheus explains how the federation values are loaded) A user is able to configure a federation via declarative scrapeConfig attribute. The expected configuration for above's example is I also tried other combinations like resulting in an escaped value , which is also obvious wrong. I already tried to analyze the issue to some point. At is the actual writing of the file. When i do something like with my flake (tank is the hostname of the Prometheus master) That should be the minimal part of the config writing without the prior validation logic and results in the expected result So my assumption is that it gets somewhere on validation broken and that is here: Sadly i am a newbie on nix language and not able to bring that to a nix repl to play around. But as the plain write operation does result in a valid configuration i am at least optimistic that i do not do things wrong. As workaround i can use configText attribute to bring in again the fixed generated config. <!-- Please @ people who are in the list of the offending package or module. If in doubt, check for whoever last touched something. -- (I have @ the last editor of the file and the persons which edited the section i assume may causes the issue, as the module has no meta tag) Please run and paste the result.
The issue do occur due echoing the content that way . This removed the qoutes. There is a nice tool in which handles that situation, but should basically do the same as it was done before.

Discussion:
with lib; let <ins> json = pkgs.formats.json { }; </ins> cfg = config.services.prometheus; workingDir = "/var/lib/" + cfg.stateDir;

promtool ${what} $out '' else file; <del> # Pretty-print JSON to a file writePrettyJSON = name: x: pkgs.runCommandLocal name { } '' echo '${builtins.toJSON x}' | ${pkgs.jq}/bin/jq . > $out ''; generatedPrometheusYml = writePrettyJSON "prometheus.yml" promConfig; </del> <ins> generatedPrometheusYml = json.generate "prometheus.yml" promConfig; </ins> # This becomes the main config file for Prometheus promConfig = {