1 { config, lib, pkgs, ... }:
4 cfg = config.services.metabase;
6 inherit (lib) mkEnableOption mkIf mkOption;
7 inherit (lib) optional optionalAttrs types;
9 dataDir = "/var/lib/metabase";
16 enable = mkEnableOption (lib.mdDoc "Metabase service");
22 description = lib.mdDoc ''
23 IP address that Metabase should listen on.
30 description = lib.mdDoc ''
31 Listen port for Metabase.
40 description = lib.mdDoc ''
41 Whether to enable SSL (https) support.
48 description = lib.mdDoc ''
49 Listen port over SSL (https) for Metabase.
54 type = types.nullOr types.path;
55 default = "${dataDir}/metabase.jks";
56 example = "/etc/secrets/keystore.jks";
57 description = lib.mdDoc ''
58 [Java KeyStore](https://www.digitalocean.com/community/tutorials/java-keytool-essentials-working-with-java-keystores) file containing the certificates.
64 openFirewall = mkOption {
67 description = lib.mdDoc ''
68 Open ports in the firewall for Metabase.
75 config = mkIf cfg.enable {
77 systemd.services.metabase = {
78 description = "Metabase server";
79 wantedBy = [ "multi-user.target" ];
80 after = [ "network-online.target" ];
82 MB_PLUGINS_DIR = "${dataDir}/plugins";
83 MB_DB_FILE = "${dataDir}/metabase.db";
84 MB_JETTY_HOST = cfg.listen.ip;
85 MB_JETTY_PORT = toString cfg.listen.port;
86 } // optionalAttrs (cfg.ssl.enable) {
88 MB_JETTY_SSL_PORT = toString cfg.ssl.port;
89 MB_JETTY_SSL_KEYSTORE = cfg.ssl.keystore;
93 StateDirectory = baseNameOf dataDir;
94 ExecStart = "${pkgs.metabase}/bin/metabase";
98 networking.firewall = mkIf cfg.openFirewall {
99 allowedTCPPorts = [ cfg.listen.port ] ++ optional cfg.ssl.enable cfg.ssl.port;