1 { config, pkgs, lib, ... }:
4 cfg = config.services.karma;
5 yaml = pkgs.formats.yaml { };
8 options.services.karma = {
9 enable = mkEnableOption (mdDoc "the Karma dashboard service");
14 defaultText = literalExpression "pkgs.karma";
15 description = mdDoc ''
16 The Karma package that should be used.
20 configFile = mkOption {
22 default = yaml.generate "karma.yaml" cfg.settings;
23 defaultText = "A configuration file generated from the provided nix attributes settings option.";
24 description = mdDoc ''
25 A YAML config file which can be used to configure karma instead of the nix-generated file.
27 example = "/etc/karma/karma.conf";
30 environment = mkOption {
31 type = with types; attrsOf str;
33 description = mdDoc ''
34 Additional environment variables to provide to karma.
37 ALERTMANAGER_URI = "https://alertmanager.example.com";
38 ALERTMANAGER_NAME= "single";
42 openFirewall = mkOption {
45 description = mdDoc ''
46 Whether to open ports in the firewall needed for karma to function.
50 extraOptions = mkOption {
51 type = with types; listOf str;
53 description = mdDoc ''
54 Extra command line options.
57 "--alertmanager.timeout 10s"
62 type = types.submodule {
63 freeformType = yaml.type;
68 default = "127.0.0.1";
69 description = mdDoc ''
70 Hostname or IP to listen on.
78 description = mdDoc ''
79 HTTP port to listen on.
87 address = "127.0.0.1";
90 description = mdDoc ''
91 Karma dashboard configuration as nix attributes.
93 Reference: <https://github.com/prymitive/karma/blob/main/docs/CONFIGURATION.md>
97 address = "192.168.1.4";
99 prefix = "/dashboard";
106 uri = "http://alertmanager.example.com";
114 config = mkIf cfg.enable {
115 systemd.services.karma = {
116 description = "Alert dashboard for Prometheus Alertmanager";
117 wantedBy = [ "multi-user.target" ];
118 environment = cfg.environment;
122 Restart = "on-failure";
123 ExecStart = "${pkgs.karma}/bin/karma --config.file ${cfg.configFile} ${concatStringsSep " " cfg.extraOptions}";
126 networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ cfg.settings.listen.port ];