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