1
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-06-26 11:06:44 +03:00
nixpkgs/nixos/modules/services/monitoring/mimir.nix

98 lines
2.1 KiB
Nix
Raw Normal View History

{
config,
lib,
pkgs,
...
}:
2022-04-28 19:11:19 -04:00
let
inherit (lib)
escapeShellArgs
mkEnableOption
mkPackageOption
mkIf
mkOption
types
;
2022-04-28 19:11:19 -04:00
cfg = config.services.mimir;
settingsFormat = pkgs.formats.yaml { };
in
{
2022-04-28 19:11:19 -04:00
options.services.mimir = {
enable = mkEnableOption "mimir";
2022-04-28 19:11:19 -04:00
configuration = mkOption {
type = (pkgs.formats.json { }).type;
default = { };
description = ''
2022-04-28 19:11:19 -04:00
Specify the configuration for Mimir in Nix.
'';
};
configFile = mkOption {
type = types.nullOr types.path;
default = null;
description = ''
2022-04-28 19:11:19 -04:00
Specify a configuration file that Mimir should use.
'';
};
2022-11-06 02:16:51 +01:00
package = mkPackageOption pkgs "mimir" { };
2023-09-04 01:02:57 +02:00
extraFlags = mkOption {
type = types.listOf types.str;
default = [ ];
2023-09-04 01:02:57 +02:00
example = [ "--config.expand-env=true" ];
description = ''
2023-09-04 01:02:57 +02:00
Specify a list of additional command line flags,
which get escaped and are then passed to Mimir.
'';
};
2022-04-28 19:11:19 -04:00
};
config = mkIf cfg.enable {
# for mimirtool
2023-09-04 01:02:57 +02:00
environment.systemPackages = [ cfg.package ];
assertions = [
{
assertion = (
(cfg.configuration == { } -> cfg.configFile != null)
&& (cfg.configFile != null -> cfg.configuration == { })
);
message = ''
Please specify either
'services.mimir.configuration' or
'services.mimir.configFile'.
'';
}
];
2022-04-28 19:11:19 -04:00
systemd.services.mimir = {
description = "mimir Service Daemon";
wantedBy = [ "multi-user.target" ];
serviceConfig =
let
conf =
if cfg.configFile == null then
settingsFormat.generate "config.yaml" cfg.configuration
else
cfg.configFile;
in
{
ExecStart = "${cfg.package}/bin/mimir --config.file=${conf} ${escapeShellArgs cfg.extraFlags}";
DynamicUser = true;
Restart = "always";
ProtectSystem = "full";
DevicePolicy = "closed";
NoNewPrivileges = true;
WorkingDirectory = "/var/lib/mimir";
StateDirectory = "mimir";
};
2022-04-28 19:11:19 -04:00
};
};
}