8 cfg = config.services.karma;
9 yaml = pkgs.formats.yaml { };
12 options.services.karma = {
13 enable = lib.mkEnableOption "the Karma dashboard service";
15 package = lib.mkPackageOption pkgs "karma" { };
17 configFile = lib.mkOption {
18 type = lib.types.path;
19 default = yaml.generate "karma.yaml" cfg.settings;
20 defaultText = "A configuration file generated from the provided nix attributes settings option.";
22 A YAML config file which can be used to configure karma instead of the nix-generated file.
24 example = "/etc/karma/karma.conf";
27 environment = lib.mkOption {
28 type = with lib.types; attrsOf str;
31 Additional environment variables to provide to karma.
34 ALERTMANAGER_URI = "https://alertmanager.example.com";
35 ALERTMANAGER_NAME = "single";
39 openFirewall = lib.mkOption {
40 type = lib.types.bool;
43 Whether to open ports in the firewall needed for karma to function.
47 extraOptions = lib.mkOption {
48 type = with lib.types; listOf str;
51 Extra command line options.
54 "--alertmanager.timeout 10s"
58 settings = lib.mkOption {
59 type = lib.types.submodule {
60 freeformType = yaml.type;
63 address = lib.mkOption {
65 default = "127.0.0.1";
67 Hostname or IP to listen on.
73 type = lib.types.port;
76 HTTP port to listen on.
84 address = "127.0.0.1";
88 Karma dashboard configuration as nix attributes.
90 Reference: <https://github.com/prymitive/karma/blob/main/docs/CONFIGURATION.md>
94 address = "192.168.1.4";
96 prefix = "/dashboard";
103 uri = "http://alertmanager.example.com";
111 config = lib.mkIf cfg.enable {
112 systemd.services.karma = {
113 description = "Alert dashboard for Prometheus Alertmanager";
114 wantedBy = [ "multi-user.target" ];
115 environment = cfg.environment;
119 Restart = "on-failure";
120 ExecStart = "${pkgs.karma}/bin/karma --config.file ${cfg.configFile} ${lib.concatStringsSep " " cfg.extraOptions}";
123 networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.settings.listen.port ];