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,
50 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
51 #[serde(default, deny_unknown_fields)]
52 pub struct PictrsConfig {
53 /// Address where pictrs is available (for image hosting)
54 #[default(Url::parse("http://localhost:8080").expect("parse pictrs url"))]
55 #[doku(example = "http://localhost:8080")]
58 /// Set a custom pictrs API key. ( Required for deleting images )
60 pub api_key: Option<String>,
63 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
65 pub struct DatabaseConfig {
66 #[serde(flatten, default)]
67 pub connection: DatabaseConnection,
69 /// Maximum number of active sql connections
74 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
76 pub enum DatabaseConnection {
77 /// Configure the database by specifying a URI
79 /// This is the preferred method to specify database connection details since
80 /// it is the most flexible.
82 /// Connection URI pointing to a postgres instance
84 /// This example uses peer authentication to obviate the need for creating,
85 /// configuring, and managing passwords.
87 /// For an explanation of how to use connection URIs, see [here][0] in
88 /// PostgreSQL's documentation.
90 /// [0]: https://www.postgresql.org/docs/current/libpq-connect.html#id-1.7.3.8.3.6
91 #[doku(example = "postgresql:///lemmy?user=lemmy&host=/var/run/postgresql")]
95 /// Configure the database by specifying parts of a URI
97 /// Note that specifying the `uri` field should be preferred since it provides
98 /// greater control over how the connection is made. This merely exists for
99 /// backwards-compatibility.
101 Parts(DatabaseConnectionParts),
104 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
106 pub struct DatabaseConnectionParts {
107 /// Username to connect to postgres
109 pub(super) user: String,
110 /// Password to connect to postgres
111 #[default("password")]
112 pub password: String,
113 #[default("localhost")]
114 /// Host where postgres is running
116 /// Port where postgres can be accessed
118 pub(super) port: i32,
119 /// Name of the postgres database for lemmy
121 pub(super) database: String,
124 #[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
125 #[serde(deny_unknown_fields)]
126 pub struct EmailConfig {
127 /// Hostname and port of the smtp server
128 #[doku(example = "localhost:25")]
129 pub smtp_server: String,
130 /// Login name for smtp server
131 pub smtp_login: Option<String>,
132 /// Password to login to the smtp server
133 pub smtp_password: Option<String>,
134 #[doku(example = "noreply@example.com")]
135 /// Address to send emails from, eg "noreply@your-instance.com"
136 pub smtp_from_address: String,
137 /// Whether or not smtp connections should use tls. Can be none, tls, or starttls
139 #[doku(example = "none")]
140 pub tls_type: String,
143 #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
144 #[serde(deny_unknown_fields)]
145 pub struct SetupConfig {
146 /// Username for the admin user
147 #[doku(example = "admin")]
148 pub admin_username: String,
149 /// Password for the admin user. It must be at least 10 characters.
150 #[doku(example = "tf6HHDS4RolWfFhk4Rq9")]
151 pub admin_password: String,
152 /// Name of the site (can be changed later)
153 #[doku(example = "My Lemmy Instance")]
154 pub site_name: String,
155 /// Email for the admin user (optional, can be omitted and set later through the website)
156 #[doku(example = "user@example.com")]
158 pub admin_email: Option<String>,