1 { config, pkgs, lib, ... }:
4 cfg = config.services.zitadel;
6 settingsFormat = pkgs.formats.yaml { };
9 options.services.zitadel =
10 let inherit (lib) mkEnableOption mkOption mkPackageOption types;
12 enable = mkEnableOption "ZITADEL, a user and identity access management platform";
14 package = mkPackageOption pkgs "ZITADEL" { default = [ "zitadel" ]; };
19 description = "The user to run ZITADEL under.";
25 description = "The group to run ZITADEL under.";
28 openFirewall = mkOption {
32 Whether to open the port specified in `listenPort` in the firewall.
36 masterKeyFile = mkOption {
39 Path to a file containing a master encryption key for ZITADEL. The
45 type = types.enum [ "external" "enabled" "disabled" ];
49 The TLS mode to use. Options are:
51 - enabled: ZITADEL accepts HTTPS connections directly. You must
52 configure TLS if this option is selected.
53 - external: ZITADEL forces HTTPS connections, with TLS terminated at a
55 - disabled: ZITADEL accepts HTTP connections only. Should only be used
61 type = lib.types.submodule {
62 freeformType = settingsFormat.type;
68 description = "The port that ZITADEL listens on.";
73 type = types.nullOr types.path;
75 description = "Path to the TLS certificate private key.";
78 type = types.nullOr types.str;
81 The TLS certificate private key, as a base64-encoded string.
83 Note that the contents of this option will be added to the Nix
84 store as world-readable plain text. Set
85 [KeyPath](#opt-services.zitadel.settings.TLS.KeyPath) instead
90 type = types.nullOr types.path;
92 description = "Path to the TLS certificate.";
95 type = types.nullOr types.str;
98 The TLS certificate, as a base64-encoded string.
100 Note that the contents of this option will be added to the Nix
101 store as world-readable plain text. Set
102 [CertPath](#opt-services.zitadel.settings.TLS.CertPath) instead
103 if this is undesired.
110 example = lib.literalExpression ''
113 ExternalDomain = "example.com";
115 CertPath = "/path/to/cert.pem";
116 KeyPath = "/path/to/cert.key";
118 Database.cockroach.Host = "db.example.com";
122 Contents of the runtime configuration file. See
123 https://zitadel.com/docs/self-hosting/manage/configure for more
128 extraSettingsPaths = mkOption {
129 type = types.listOf types.path;
132 A list of paths to extra settings files. These will override the
133 values set in [settings](#opt-services.zitadel.settings). Useful if
134 you want to keep sensitive secrets out of the Nix store.
139 type = settingsFormat.type;
141 example = lib.literalExpression ''
144 InstanceName = "Example";
154 Contents of the database initialization config file. See
155 https://zitadel.com/docs/self-hosting/manage/configure for more
160 extraStepsPaths = mkOption {
161 type = types.listOf types.path;
164 A list of paths to extra steps files. These will override the values
165 set in [steps](#opt-services.zitadel.steps). Useful if you want to
166 keep sensitive secrets out of the Nix store.
171 config = lib.mkIf cfg.enable {
173 assertion = cfg.tlsMode == "enabled"
174 -> ((cfg.settings.TLS.Key != null || cfg.settings.TLS.KeyPath != null)
175 && (cfg.settings.TLS.Cert != null || cfg.settings.TLS.CertPath
178 A TLS certificate and key must be configured in
179 services.zitadel.settings.TLS if services.zitadel.tlsMode is enabled.
183 networking.firewall.allowedTCPPorts =
184 lib.mkIf cfg.openFirewall [ cfg.settings.Port ];
186 systemd.services.zitadel =
188 configFile = settingsFormat.generate "config.yaml" cfg.settings;
189 stepsFile = settingsFormat.generate "steps.yaml" cfg.steps;
191 args = lib.cli.toGNUCommandLineShell { } {
192 config = cfg.extraSettingsPaths ++ [ configFile ];
193 steps = cfg.extraStepsPaths ++ [ stepsFile ];
194 masterkeyFile = cfg.masterKeyFile;
195 inherit (cfg) tlsMode;
199 description = "ZITADEL identity access management";
200 path = [ cfg.package ];
201 wantedBy = [ "multi-user.target" ];
204 zitadel start-from-init ${args}
211 Restart = "on-failure";
215 users.users.zitadel = lib.mkIf (cfg.user == "zitadel") {
219 users.groups.zitadel = lib.mkIf (cfg.group == "zitadel") { };
222 meta.maintainers = [ ];