at 23.11-pre 1.8 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.grafana_reporter; 7 8in { 9 options.services.grafana_reporter = { 10 enable = mkEnableOption (lib.mdDoc "grafana_reporter"); 11 12 grafana = { 13 protocol = mkOption { 14 description = lib.mdDoc "Grafana protocol."; 15 default = "http"; 16 type = types.enum ["http" "https"]; 17 }; 18 addr = mkOption { 19 description = lib.mdDoc "Grafana address."; 20 default = "127.0.0.1"; 21 type = types.str; 22 }; 23 port = mkOption { 24 description = lib.mdDoc "Grafana port."; 25 default = 3000; 26 type = types.port; 27 }; 28 29 }; 30 addr = mkOption { 31 description = lib.mdDoc "Listening address."; 32 default = "127.0.0.1"; 33 type = types.str; 34 }; 35 36 port = mkOption { 37 description = lib.mdDoc "Listening port."; 38 default = 8686; 39 type = types.port; 40 }; 41 42 templateDir = mkOption { 43 description = lib.mdDoc "Optional template directory to use custom tex templates"; 44 default = pkgs.grafana_reporter; 45 defaultText = literalExpression "pkgs.grafana_reporter"; 46 type = types.either types.str types.path; 47 }; 48 }; 49 50 config = mkIf cfg.enable { 51 systemd.services.grafana_reporter = { 52 description = "Grafana Reporter Service Daemon"; 53 wantedBy = ["multi-user.target"]; 54 after = ["network.target"]; 55 serviceConfig = let 56 args = lib.concatStringsSep " " [ 57 "-proto ${cfg.grafana.protocol}://" 58 "-ip ${cfg.grafana.addr}:${toString cfg.grafana.port}" 59 "-port :${toString cfg.port}" 60 "-templates ${cfg.templateDir}" 61 ]; 62 in { 63 ExecStart = "${pkgs.grafana_reporter}/bin/grafana-reporter ${args}"; 64 }; 65 }; 66 }; 67}