···18051805 </listitem>
18061806 <listitem>
18071807 <para>
18081808+ The option
18091809+ <literal>services.prometheus.environmentFile</literal> has
18101810+ been removed since it was causing
18111811+ <link xlink:href="https://github.com/NixOS/nixpkgs/issues/126083">issues</link>
18121812+ and Prometheus now has native support for secret files, i.e.
18131813+ <literal>basic_auth.password_file</literal> and
18141814+ <literal>authorization.credentials_file</literal>.
18151815+ </para>
18161816+ </listitem>
18171817+ <listitem>
18181818+ <para>
18081819 Dokuwiki now supports caddy! However
18091820 </para>
18101821 <itemizedlist spacing="compact">
+2
nixos/doc/manual/release-notes/rl-2111.section.md
···508508509509- A new option `services.prometheus.enableReload` has been added which can be enabled to reload the prometheus service when its config file changes instead of restarting.
510510511511+- The option `services.prometheus.environmentFile` has been removed since it was causing [issues](https://github.com/NixOS/nixpkgs/issues/126083) and Prometheus now has native support for secret files, i.e. `basic_auth.password_file` and `authorization.credentials_file`.
512512+511513- Dokuwiki now supports caddy! However
512514 - the nginx option has been removed, in the new configuration, please use the `dokuwiki.webserver = "nginx"` instead.
513515 - The "${hostname}" option has been deprecated, please use `dokuwiki.sites = [ "${hostname}" ]` instead
···991010 prometheusYmlOut = "${workingDir}/prometheus-substituted.yaml";
11111212- writeConfig = pkgs.writeShellScriptBin "write-prometheus-config" ''
1313- PATH="${makeBinPath (with pkgs; [ coreutils envsubst ])}"
1414- touch '${prometheusYmlOut}'
1515- chmod 600 '${prometheusYmlOut}'
1616- envsubst -o '${prometheusYmlOut}' -i '${prometheusYml}'
1717- '';
1818-1912 triggerReload = pkgs.writeShellScriptBin "trigger-reload-prometheus" ''
2013 PATH="${makeBinPath (with pkgs; [ systemd ])}"
2114 if systemctl -q is-active prometheus.service; then
···7669 "--storage.tsdb.path=${workingDir}/data/"
7770 "--config.file=${
7871 if cfg.enableReload
7979- then prometheusYmlOut
8080- else "/run/prometheus/prometheus-substituted.yaml"
7272+ then "/etc/prometheus/prometheus.yaml"
7373+ else prometheusYml
8174 }"
8275 "--web.listen-address=${cfg.listenAddress}:${builtins.toString cfg.port}"
8376 "--alertmanager.notification-queue-capacity=${toString cfg.alertmanagerNotificationQueueCapacity}"
···1561155415621555 imports = [
15631556 (mkRenamedOptionModule [ "services" "prometheus2" ] [ "services" "prometheus" ])
15571557+ (mkRemovedOptionModule [ "services" "prometheus" "environmentFile" ]
15581558+ "It has been removed since it was causing issues (https://github.com/NixOS/nixpkgs/issues/126083) and Prometheus now has native support for secret files, i.e. `basic_auth.password_file` and `authorization.credentials_file`.")
15641559 ];
1565156015661561 options.services.prometheus = {
···16251620 (<literal>switch-to-configuration</literal>) that changes the prometheus
16261621 configuration only finishes successully when prometheus has finished
16271622 loading the new configuration.
16281628-16291629- Note that prometheus will also get reloaded when the location of the
16301630- <option>environmentFile</option> changes but not when its contents
16311631- changes. So when you change it contents make sure to reload prometheus
16321632- manually or include the hash of <option>environmentFile</option> in its
16331633- name.
16341634- '';
16351635- };
16361636-16371637- environmentFile = mkOption {
16381638- type = types.nullOr types.path;
16391639- default = null;
16401640- example = "/root/prometheus.env";
16411641- description = ''
16421642- Environment file as defined in <citerefentry>
16431643- <refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum>
16441644- </citerefentry>.
16451645-16461646- Secrets may be passed to the service without adding them to the
16471647- world-readable Nix store, by specifying placeholder variables as
16481648- the option value in Nix and setting these variables accordingly in the
16491649- environment file.
16501650-16511651- Environment variables from this file will be interpolated into the
16521652- config file using envsubst with this syntax:
16531653- <literal>$ENVIRONMENT ''${VARIABLE}</literal>
16541654-16551655- <programlisting>
16561656- # Example scrape config entry handling an OAuth bearer token
16571657- {
16581658- job_name = "home_assistant";
16591659- metrics_path = "/api/prometheus";
16601660- scheme = "https";
16611661- bearer_token = "\''${HOME_ASSISTANT_BEARER_TOKEN}";
16621662- [...]
16631663- }
16641664- </programlisting>
16651665-16661666- <programlisting>
16671667- # Content of the environment file
16681668- HOME_ASSISTANT_BEARER_TOKEN=someoauthbearertoken
16691669- </programlisting>
16701670-16711671- Note that this file needs to be available on the host on which
16721672- <literal>Prometheus</literal> is running.
16731623 '';
16741624 };
16751625···18301780 uid = config.ids.uids.prometheus;
18311781 group = "prometheus";
18321782 };
17831783+ environment.etc."prometheus/prometheus.yaml" = mkIf cfg.enableReload {
17841784+ source = prometheusYml;
17851785+ };
18331786 systemd.services.prometheus = {
18341787 wantedBy = [ "multi-user.target" ];
18351788 after = [ "network.target" ];
18361836- preStart = mkIf (!cfg.enableReload) ''
18371837- ${lib.getBin pkgs.envsubst}/bin/envsubst -o "/run/prometheus/prometheus-substituted.yaml" \
18381838- -i "${prometheusYml}"
18391839- '';
18401789 serviceConfig = {
18411790 ExecStart = "${cfg.package}/bin/prometheus" +
18421791 optionalString (length cmdlineArgs != 0) (" \\\n " +
···18441793 ExecReload = mkIf cfg.enableReload "+${reload}/bin/reload-prometheus";
18451794 User = "prometheus";
18461795 Restart = "always";
18471847- EnvironmentFile = mkIf (cfg.environmentFile != null && !cfg.enableReload) [ cfg.environmentFile ];
18481796 RuntimeDirectory = "prometheus";
18491797 RuntimeDirectoryMode = "0700";
18501798 WorkingDirectory = workingDir;
···18521800 StateDirectoryMode = "0700";
18531801 };
18541802 };
18551855- systemd.services.prometheus-config-write = mkIf cfg.enableReload {
18561856- wantedBy = [ "prometheus.service" ];
18571857- before = [ "prometheus.service" ];
18581858- serviceConfig = {
18591859- Type = "oneshot";
18601860- User = "prometheus";
18611861- StateDirectory = cfg.stateDir;
18621862- StateDirectoryMode = "0700";
18631863- EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ];
18641864- ExecStart = "${writeConfig}/bin/write-prometheus-config";
18651865- };
18661866- };
18671803 # prometheus-config-reload will activate after prometheus. However, what we
18681804 # don't want is that on startup it immediately reloads prometheus because
18691805 # prometheus itself might have just started.
···18731809 # harmless message and then stay active (RemainAfterExit).
18741810 #
18751811 # Then, when the config file has changed, switch-to-configuration notices
18761876- # that this service has changed and needs to be reloaded
18771877- # (reloadIfChanged). The reload command then actually writes the new config
18781878- # and reloads prometheus.
18121812+ # that this service has changed (restartTriggers) and needs to be reloaded
18131813+ # (reloadIfChanged). The reload command then reloads prometheus.
18791814 systemd.services.prometheus-config-reload = mkIf cfg.enableReload {
18801815 wantedBy = [ "prometheus.service" ];
18811816 after = [ "prometheus.service" ];
18821817 reloadIfChanged = true;
18181818+ restartTriggers = [ prometheusYml ];
18831819 serviceConfig = {
18841820 Type = "oneshot";
18851885- User = "prometheus";
18861886- StateDirectory = cfg.stateDir;
18871887- StateDirectoryMode = "0700";
18881888- EnvironmentFile = mkIf (cfg.environmentFile != null) [ cfg.environmentFile ];
18891821 RemainAfterExit = true;
18901822 TimeoutSec = 60;
18911823 ExecStart = "${pkgs.logger}/bin/logger 'prometheus-config-reload will only reload prometheus when reloaded itself.'";
18921892- ExecReload = [
18931893- "${writeConfig}/bin/write-prometheus-config"
18941894- "+${triggerReload}/bin/trigger-reload-prometheus"
18951895- ];
18241824+ ExecReload = [ "${triggerReload}/bin/trigger-reload-prometheus" ];
18961825 };
18971826 };
18981827 };
+1-10
nixos/tests/prometheus.nix
···130130131131 # This configuration just adds a new prometheus job
132132 # to scrape the node_exporter metrics of the s3 machine.
133133- # We also use an environmentFile to test if that works correctly.
134133 services.prometheus = {
135135- environmentFile = pkgs.writeText "prometheus-config-env-file" ''
136136- JOB_NAME=s3-node_exporter
137137- '';
138134 scrapeConfigs = [
139135 {
140140- job_name = "$JOB_NAME";
136136+ job_name = "s3-node_exporter";
141137 static_configs = [
142138 {
143139 targets = [ "s3:9100" ];
···231227232228 # Check if prometheus responds to requests:
233229 prometheus.wait_for_unit("prometheus.service")
234234-235235- # Check if prometheus' config file is correctly locked down because it could contain secrets.
236236- prometheus.succeed(
237237- "stat -c '%a %U' /var/lib/prometheus2/prometheus-substituted.yaml | grep '600 prometheus'"
238238- )
239230240231 prometheus.wait_for_open_port(${toString queryPort})
241232 prometheus.succeed("curl -sf http://127.0.0.1:${toString queryPort}/metrics")