1 { lib, pkgs, config, ... }:
3 cfg = config.services.alloy;
7 maintainers = with lib.maintainers; [ flokli hbjydev ];
10 options.services.alloy = {
11 enable = lib.mkEnableOption "Grafana Alloy";
13 package = lib.mkPackageOption pkgs "grafana-alloy" { };
15 configPath = lib.mkOption {
16 type = lib.types.path;
17 default = "/etc/alloy";
19 Alloy configuration file/directory path.
21 We default to `/etc/alloy` here, and expect the user to configure a
22 configuration file via `environment.etc."alloy/config.alloy"`.
24 This allows config reload, contrary to specifying a store path.
25 A `reloadTrigger` for `config.alloy` is configured.
27 Other `*.alloy` files in the same directory (ignoring subdirs) are also
28 honored, but it's necessary to manually extend
29 `systemd.services.alloy.reloadTriggers` to enable config reload
30 during nixos-rebuild switch.
32 This can also point to another directory containing `*.alloy` files, or
33 a single Alloy file in the Nix store (at the cost of reload).
35 Component names must be unique across all Alloy configuration files, and
36 configuration blocks must not be repeated.
38 Alloy will continue to run if subsequent reloads of the configuration
39 file fail, potentially marking components as unhealthy depending on
40 the nature of the failure. When this happens, Alloy will continue
41 functioning in the last valid state.
45 extraFlags = lib.mkOption {
46 type = with lib.types; listOf str;
48 example = [ "--server.http.listen-addr=127.0.0.1:12346" "--disable-reporting" ];
50 Extra command-line flags passed to {command}`alloy run`.
52 See <https://grafana.com/docs/alloy/latest/reference/cli/run/>
58 config = lib.mkIf cfg.enable {
59 systemd.services.alloy = {
60 wantedBy = [ "multi-user.target" ];
61 reloadTriggers = [ config.environment.etc."alloy/config.alloy".source or null ];
66 SupplementaryGroups = [
67 # allow to read the systemd journal for loki log forwarding
70 ExecStart = "${lib.getExe cfg.package} run ${cfg.configPath} ${lib.escapeShellArgs cfg.extraFlags}";
71 ExecReload = "${pkgs.coreutils}/bin/kill -SIGHUP $MAINPID";
72 ConfigurationDirectory = "alloy";
73 StateDirectory = "alloy";
74 WorkingDirectory = "%S/alloy";