2 use serde::{Deserialize, Serialize};
3 use std::net::{IpAddr, Ipv4Addr};
6 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
9 /// settings related to the postgresql database
10 #[default(Default::default())]
11 pub database: DatabaseConfig,
12 /// Settings related to activitypub federation
13 /// Pictrs image server configuration.
14 #[default(Some(Default::default()))]
15 pub(crate) pictrs: Option<PictrsConfig>,
16 /// Email sending configuration. All options except login/password are mandatory
18 #[doku(example = "Some(Default::default())")]
19 pub email: Option<EmailConfig>,
20 /// Parameters for automatic configuration of new instance (only used at first start)
22 #[doku(example = "Some(Default::default())")]
23 pub setup: Option<SetupConfig>,
24 /// the domain name of your instance (mandatory)
26 #[doku(example = "example.com")]
28 /// Address where lemmy should listen for incoming requests
29 #[default(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))]
30 #[doku(as = "String")]
32 /// Port where lemmy should listen for incoming requests
35 /// Whether the site is available over TLS. Needs to be true for federation to work.
37 pub tls_enabled: bool,
38 /// Set the URL for opentelemetry exports. If you do not have an opentelemetry collector, do not set this option
41 pub opentelemetry_url: Option<Url>,
42 /// The number of activitypub federation workers that can be in-flight concurrently
44 pub worker_count: usize,
45 /// The number of activitypub federation retry workers that can be in-flight concurrently
47 pub retry_count: usize,
48 // Prometheus configuration.
50 #[doku(example = "Some(Default::default())")]
51 pub prometheus: Option<PrometheusConfig>,
54 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
55 #[serde(default, deny_unknown_fields)]
56 pub struct PictrsConfig {
57 /// Address where pictrs is available (for image hosting)
58 #[default(Url::parse("http://localhost:8080").expect("parse pictrs url"))]
59 #[doku(example = "http://localhost:8080")]
62 /// Set a custom pictrs API key. ( Required for deleting images )
64 pub api_key: Option<String>,
67 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
69 pub struct DatabaseConfig {
70 #[serde(flatten, default)]
71 pub connection: DatabaseConnection,
73 /// Maximum number of active sql connections
78 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
80 pub enum DatabaseConnection {
81 /// Configure the database by specifying a URI
83 /// This is the preferred method to specify database connection details since
84 /// it is the most flexible.
86 /// Connection URI pointing to a postgres instance
88 /// This example uses peer authentication to obviate the need for creating,
89 /// configuring, and managing passwords.
91 /// For an explanation of how to use connection URIs, see [here][0] in
92 /// PostgreSQL's documentation.
94 /// [0]: https://www.postgresql.org/docs/current/libpq-connect.html#id-1.7.3.8.3.6
95 #[doku(example = "postgresql:///lemmy?user=lemmy&host=/var/run/postgresql")]
99 /// Configure the database by specifying parts of a URI
101 /// Note that specifying the `uri` field should be preferred since it provides
102 /// greater control over how the connection is made. This merely exists for
103 /// backwards-compatibility.
105 Parts(DatabaseConnectionParts),
108 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
110 pub struct DatabaseConnectionParts {
111 /// Username to connect to postgres
113 pub(super) user: String,
114 /// Password to connect to postgres
115 #[default("password")]
116 pub password: String,
117 #[default("localhost")]
118 /// Host where postgres is running
120 /// Port where postgres can be accessed
122 pub(super) port: i32,
123 /// Name of the postgres database for lemmy
125 pub(super) database: String,
128 #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
129 #[serde(deny_unknown_fields)]
130 pub struct EmailConfig {
131 /// Hostname and port of the smtp server
132 #[doku(example = "localhost:25")]
133 pub smtp_server: String,
134 /// Login name for smtp server
135 pub smtp_login: Option<String>,
136 /// Password to login to the smtp server
137 pub smtp_password: Option<String>,
138 #[doku(example = "noreply@example.com")]
139 /// Address to send emails from, eg "noreply@your-instance.com"
140 pub smtp_from_address: String,
141 /// Whether or not smtp connections should use tls. Can be none, tls, or starttls
143 #[doku(example = "none")]
144 pub tls_type: String,
147 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
148 #[serde(deny_unknown_fields)]
149 pub struct SetupConfig {
150 /// Username for the admin user
151 #[doku(example = "admin")]
152 pub admin_username: String,
153 /// Password for the admin user. It must be at least 10 characters.
154 #[doku(example = "tf6HHDS4RolWfFhk4Rq9")]
155 pub admin_password: String,
156 /// Name of the site (can be changed later)
157 #[doku(example = "My Lemmy Instance")]
158 pub site_name: String,
159 /// Email for the admin user (optional, can be omitted and set later through the website)
160 #[doku(example = "user@example.com")]
162 pub admin_email: Option<String>,
165 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
166 #[serde(deny_unknown_fields)]
167 pub struct PrometheusConfig {
168 // Address that the Prometheus metrics will be served on.
169 #[default(Some(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))))]
170 #[doku(example = "127.0.0.1")]
171 pub bind: Option<IpAddr>,
172 // Port that the Prometheus metrics will be served on.
173 #[default(Some(10002))]
174 #[doku(example = "10002")]
175 pub port: Option<i32>,