···24242525- Added `rewriteURL` attribute to the nixpkgs `config`, to allow for rewriting the URLs downloaded by `fetchurl`.
26262727+- `vmalert` now supports multiple instances with the option `services.vmalert.instances."".enable`
2828+ et al..
2929+2730## Nixpkgs Library {#sec-nixpkgs-release-25.11-lib}
28312932<!-- To avoid merge conflicts, consider adding your item at an arbitrary place in the list instead. -->
+1-1
nixos/doc/manual/release-notes/rl-2305.section.md
···105105106106- [ivpn](https://www.ivpn.net/), a secure, private VPN with fast WireGuard connections. Available as [services.ivpn](#opt-services.ivpn.enable).
107107108108-- [vmalert](https://victoriametrics.com/), an alerting engine for VictoriaMetrics. Available as [services.vmalert](#opt-services.vmalert.enable).
108108+- [vmalert](https://victoriametrics.com/), an alerting engine for VictoriaMetrics. Available as [services.vmalert.instances](#opt-services.vmalert.instances._name_.enable).
109109110110- [jellyseerr](https://github.com/Fallenbagel/jellyseerr), a web-based requests manager for Jellyfin, forked from Overseerr. Available as [services.jellyseerr](#opt-services.jellyseerr.enable).
111111
+151-104
nixos/modules/services/monitoring/vmalert.nix
···10101111 format = pkgs.formats.yaml { };
12121313- confOpts = concatStringsSep " \\\n" (
1414- mapAttrsToList mkLine (filterAttrs (_: v: v != false) cfg.settings)
1515- );
1313+ mkConfOpts =
1414+ settings:
1515+ concatStringsSep " \\\n" (mapAttrsToList mkLine (filterAttrs (_: v: v != false) settings));
1616 confType =
1717 with types;
1818 let
···3333 concatMapStringsSep " " (v: "-${key}=${escapeShellArg (toString v)}") value
3434 else
3535 "-${key}=${escapeShellArg (toString value)}";
3636+3737+ vmalertName = name: "vmalert" + lib.optionalString (name != "") ("-" + name);
3838+ enabledInstances = lib.filterAttrs (name: conf: conf.enable) config.services.vmalert.instances;
3639in
3740{
4141+ imports = [
4242+ (lib.mkRenamedOptionModule
4343+ [ "services" "vmalert" "enable" ]
4444+ [ "services" "vmalert" "instances" "" "enable" ]
4545+ )
4646+ (lib.mkRenamedOptionModule
4747+ [ "services" "vmalert" "rules" ]
4848+ [ "services" "vmalert" "instances" "" "rules" ]
4949+ )
5050+ (lib.mkRenamedOptionModule
5151+ [ "services" "vmalert" "settings" ]
5252+ [ "services" "vmalert" "instances" "" "settings" ]
5353+ )
5454+ ];
5555+3856 # interface
3939- options.services.vmalert = {
4040- enable = lib.mkOption {
4141- type = lib.types.bool;
4242- default = false;
4343- description = ''
4444- Wether to enable VictoriaMetrics's `vmalert`.
5757+ options.services.vmalert.package = mkPackageOption pkgs "victoriametrics" { };
45584646- `vmalert` evaluates alerting and recording rules against a data source, sends notifications via Alertmanager.
4747- '';
4848- };
5959+ options.services.vmalert.instances = mkOption {
6060+ default = { };
49615050- package = mkPackageOption pkgs "victoriametrics" { };
6262+ description = ''
6363+ Define multiple instances of vmalert.
6464+ '';
51655252- settings = mkOption {
5353- type = types.submodule {
5454- freeformType = confType;
5555- options = {
6666+ type = types.attrsOf (
6767+ types.submodule (
6868+ { name, config, ... }:
6969+ {
7070+ options = {
7171+ enable = lib.mkOption {
7272+ type = lib.types.bool;
7373+ default = false;
7474+ description = ''
7575+ Wether to enable VictoriaMetrics's `vmalert`.
56765757- "datasource.url" = mkOption {
5858- type = types.nonEmptyStr;
5959- example = "http://localhost:8428";
6060- description = ''
6161- Datasource compatible with Prometheus HTTP API.
6262- '';
6363- };
7777+ `vmalert` evaluates alerting and recording rules against a data source, sends notifications via Alertmanager.
7878+ '';
7979+ };
64806565- "notifier.url" = mkOption {
6666- type = with types; listOf nonEmptyStr;
6767- default = [ ];
6868- example = [ "http://127.0.0.1:9093" ];
6969- description = ''
7070- Prometheus Alertmanager URL. List all Alertmanager URLs if it runs in the cluster mode to ensure high availability.
7171- '';
7272- };
8181+ settings = mkOption {
8282+ type = types.submodule {
8383+ freeformType = confType;
8484+ options = {
73857474- "rule" = mkOption {
7575- type = with types; listOf path;
7676- description = ''
7777- Path to the files with alerting and/or recording rules.
8686+ "datasource.url" = mkOption {
8787+ type = types.nonEmptyStr;
8888+ example = "http://localhost:8428";
8989+ description = ''
9090+ Datasource compatible with Prometheus HTTP API.
9191+ '';
9292+ };
9393+9494+ "notifier.url" = mkOption {
9595+ type = with types; listOf nonEmptyStr;
9696+ default = [ ];
9797+ example = [ "http://127.0.0.1:9093" ];
9898+ description = ''
9999+ Prometheus Alertmanager URL. List all Alertmanager URLs if it runs in the cluster mode to ensure high availability.
100100+ '';
101101+ };
781027979- ::: {.note}
8080- Consider using the {option}`services.vmalert.rules` option as a convenient alternative for declaring rules
8181- directly in the `nix` language.
8282- :::
8383- '';
103103+ "rule" = mkOption {
104104+ type = with types; listOf path;
105105+ description = ''
106106+ Path to the files with alerting and/or recording rules.
107107+108108+ ::: {.note}
109109+ Consider using the {option}`services.vmalert.instances.<name>.rules` option as a convenient alternative for declaring rules
110110+ directly in the `nix` language.
111111+ :::
112112+ '';
113113+ };
114114+115115+ };
116116+ };
117117+ default = { };
118118+ example = {
119119+ "datasource.url" = "http://localhost:8428";
120120+ "datasource.disableKeepAlive" = true;
121121+ "datasource.showURL" = false;
122122+ "rule" = [
123123+ "http://<some-server-addr>/path/to/rules"
124124+ "dir/*.yaml"
125125+ ];
126126+ };
127127+ description = ''
128128+ `vmalert` configuration, passed via command line flags. Refer to
129129+ <https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmalert/README.md#configuration>
130130+ for details on supported values.
131131+ '';
132132+ };
133133+134134+ rules = mkOption {
135135+ type = format.type;
136136+ default = { };
137137+ example = {
138138+ group = [
139139+ {
140140+ name = "TestGroup";
141141+ rules = [
142142+ {
143143+ alert = "ExampleAlertAlwaysFiring";
144144+ expr = ''
145145+ sum by(job)
146146+ (up == 1)
147147+ '';
148148+ }
149149+ ];
150150+ }
151151+ ];
152152+ };
153153+ description = ''
154154+ A list of the given alerting or recording rules against configured `"datasource.url"` compatible with
155155+ Prometheus HTTP API for `vmalert` to execute. Refer to
156156+ <https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmalert/README.md#rules>
157157+ for details on supported values.
158158+ '';
159159+ };
84160 };
851618686- };
8787- };
8888- default = { };
8989- example = {
9090- "datasource.url" = "http://localhost:8428";
9191- "datasource.disableKeepAlive" = true;
9292- "datasource.showURL" = false;
9393- "rule" = [
9494- "http://<some-server-addr>/path/to/rules"
9595- "dir/*.yaml"
9696- ];
9797- };
9898- description = ''
9999- `vmalert` configuration, passed via command line flags. Refer to
100100- <https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmalert/README.md#configuration>
101101- for details on supported values.
102102- '';
103103- };
104104-105105- rules = mkOption {
106106- type = format.type;
107107- default = { };
108108- example = {
109109- group = [
110110- {
111111- name = "TestGroup";
112112- rules = [
113113- {
114114- alert = "ExampleAlertAlwaysFiring";
115115- expr = ''
116116- sum by(job)
117117- (up == 1)
118118- '';
119119- }
162162+ config = {
163163+ settings.rule = [
164164+ "/etc/${vmalertName name}/rules.yml"
120165 ];
121121- }
122122- ];
123123- };
124124- description = ''
125125- A list of the given alerting or recording rules against configured `"datasource.url"` compatible with
126126- Prometheus HTTP API for `vmalert` to execute. Refer to
127127- <https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/app/vmalert/README.md#rules>
128128- for details on supported values.
129129- '';
130130- };
166166+ };
167167+ }
168168+ )
169169+ );
131170 };
132171133172 # implementation
134134- config = mkIf cfg.enable {
173173+ config = mkIf (enabledInstances != { }) {
174174+ environment.etc = lib.mapAttrs' (
175175+ name:
176176+ { rules, ... }:
177177+ lib.nameValuePair "${vmalertName name}/rules.yml" {
178178+ source = format.generate "rules.yml" rules;
179179+ }
180180+ ) enabledInstances;
135181136136- environment.etc."vmalert/rules.yml".source = format.generate "rules.yml" cfg.rules;
182182+ systemd.services = lib.mapAttrs' (
183183+ name:
184184+ { settings, ... }:
185185+ let
186186+ name' = vmalertName name;
187187+ in
188188+ lib.nameValuePair name' {
189189+ description = "vmalert service";
190190+ wantedBy = [ "multi-user.target" ];
191191+ after = [ "network.target" ];
192192+ reloadTriggers = [ config.environment.etc."${name'}/rules.yml".source ];
137193138138- services.vmalert.settings.rule = [
139139- "/etc/vmalert/rules.yml"
140140- ];
141141-142142- systemd.services.vmalert = {
143143- description = "vmalert service";
144144- wantedBy = [ "multi-user.target" ];
145145- after = [ "network.target" ];
146146- reloadTriggers = [ config.environment.etc."vmalert/rules.yml".source ];
147147-148148- serviceConfig = {
149149- DynamicUser = true;
150150- Restart = "on-failure";
151151- ExecStart = "${cfg.package}/bin/vmalert ${confOpts}";
152152- ExecReload = ''${pkgs.coreutils}/bin/kill -SIGHUP "$MAINPID"'';
153153- };
154154- };
194194+ serviceConfig = {
195195+ DynamicUser = true;
196196+ Restart = "on-failure";
197197+ ExecStart = "${cfg.package}/bin/vmalert ${mkConfOpts settings}";
198198+ ExecReload = ''${pkgs.coreutils}/bin/kill -SIGHUP "$MAINPID"'';
199199+ };
200200+ }
201201+ ) enabledInstances;
155202 };
156203}