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 "Metabase service";
23 IP address that Metabase should listen on.
31 Listen port for Metabase.
41 Whether to enable SSL (https) support.
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";
58 [Java KeyStore](https://www.digitalocean.com/community/tutorials/java-keytool-essentials-working-with-java-keystores) file containing the certificates.
64 openFirewall = mkOption {
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 wants = [ "network-online.target" ];
81 after = [ "network-online.target" ];
83 MB_PLUGINS_DIR = "${dataDir}/plugins";
84 MB_DB_FILE = "${dataDir}/metabase.db";
85 MB_JETTY_HOST = cfg.listen.ip;
86 MB_JETTY_PORT = toString cfg.listen.port;
87 } // optionalAttrs (cfg.ssl.enable) {
89 MB_JETTY_SSL_PORT = toString cfg.ssl.port;
90 MB_JETTY_SSL_KEYSTORE = cfg.ssl.keystore;
94 StateDirectory = baseNameOf dataDir;
95 ExecStart = "${pkgs.metabase}/bin/metabase";
99 networking.firewall = mkIf cfg.openFirewall {
100 allowedTCPPorts = [ cfg.listen.port ] ++ optional cfg.ssl.enable cfg.ssl.port;