2021-10-08 15:07:24 +00:00
|
|
|
use doku::Document;
|
|
|
|
use serde::{Deserialize, Serialize};
|
2021-08-04 21:13:51 +00:00
|
|
|
use std::net::{IpAddr, Ipv4Addr};
|
2022-07-11 20:38:37 +00:00
|
|
|
use url::Url;
|
2021-03-01 17:24:11 +00:00
|
|
|
|
2021-10-08 15:07:24 +00:00
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
|
2021-08-04 21:13:51 +00:00
|
|
|
#[serde(default)]
|
2021-03-01 17:24:11 +00:00
|
|
|
pub struct Settings {
|
2021-10-08 15:07:24 +00:00
|
|
|
/// settings related to the postgresql database
|
2022-07-11 20:38:37 +00:00
|
|
|
#[default(Default::default())]
|
2021-08-04 21:13:51 +00:00
|
|
|
pub database: DatabaseConfig,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Settings related to activitypub federation
|
2022-06-13 19:15:04 +00:00
|
|
|
/// Pictrs image server configuration.
|
2022-07-11 20:38:37 +00:00
|
|
|
#[default(Some(Default::default()))]
|
2022-07-14 18:25:10 +00:00
|
|
|
pub(crate) pictrs: Option<PictrsConfig>,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Email sending configuration. All options except login/password are mandatory
|
2021-08-04 21:13:51 +00:00
|
|
|
#[default(None)]
|
2022-07-11 20:38:37 +00:00
|
|
|
#[doku(example = "Some(Default::default())")]
|
2021-08-04 21:13:51 +00:00
|
|
|
pub email: Option<EmailConfig>,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Parameters for automatic configuration of new instance (only used at first start)
|
2021-08-04 21:13:51 +00:00
|
|
|
#[default(None)]
|
2022-07-11 20:38:37 +00:00
|
|
|
#[doku(example = "Some(Default::default())")]
|
2021-08-04 21:13:51 +00:00
|
|
|
pub setup: Option<SetupConfig>,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// the domain name of your instance (mandatory)
|
2021-08-04 21:13:51 +00:00
|
|
|
#[default("unset")]
|
2021-10-08 15:07:24 +00:00
|
|
|
#[doku(example = "example.com")]
|
2021-08-04 21:13:51 +00:00
|
|
|
pub hostname: String,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Address where lemmy should listen for incoming requests
|
2021-08-04 21:13:51 +00:00
|
|
|
#[default(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))]
|
2021-10-08 15:07:24 +00:00
|
|
|
#[doku(as = "String")]
|
2021-08-04 21:13:51 +00:00
|
|
|
pub bind: IpAddr,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Port where lemmy should listen for incoming requests
|
2021-08-04 21:13:51 +00:00
|
|
|
#[default(8536)]
|
|
|
|
pub port: u16,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Whether the site is available over TLS. Needs to be true for federation to work.
|
2021-08-04 21:13:51 +00:00
|
|
|
#[default(true)]
|
|
|
|
pub tls_enabled: bool,
|
2022-02-03 22:54:57 +00:00
|
|
|
/// Set the URL for opentelemetry exports. If you do not have an opentelemetry collector, do not set this option
|
2022-01-06 19:10:20 +00:00
|
|
|
#[default(None)]
|
2022-02-07 15:39:37 +00:00
|
|
|
#[doku(skip)]
|
2022-07-11 20:38:37 +00:00
|
|
|
pub opentelemetry_url: Option<Url>,
|
2023-06-26 08:24:11 +00:00
|
|
|
/// The number of activitypub federation workers that can be in-flight concurrently
|
|
|
|
#[default(0)]
|
|
|
|
pub worker_count: usize,
|
|
|
|
/// The number of activitypub federation retry workers that can be in-flight concurrently
|
|
|
|
#[default(0)]
|
|
|
|
pub retry_count: usize,
|
2023-07-05 11:25:19 +00:00
|
|
|
// Prometheus configuration.
|
|
|
|
#[default(None)]
|
|
|
|
#[doku(example = "Some(Default::default())")]
|
|
|
|
pub prometheus: Option<PrometheusConfig>,
|
2021-03-01 17:24:11 +00:00
|
|
|
}
|
|
|
|
|
2022-06-13 19:15:04 +00:00
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
|
2023-05-12 00:12:12 +00:00
|
|
|
#[serde(default, deny_unknown_fields)]
|
2022-06-13 19:15:04 +00:00
|
|
|
pub struct PictrsConfig {
|
|
|
|
/// Address where pictrs is available (for image hosting)
|
2023-01-20 17:46:49 +00:00
|
|
|
#[default(Url::parse("http://localhost:8080").expect("parse pictrs url"))]
|
|
|
|
#[doku(example = "http://localhost:8080")]
|
2022-07-11 20:38:37 +00:00
|
|
|
pub url: Url,
|
2022-06-13 19:15:04 +00:00
|
|
|
|
|
|
|
/// Set a custom pictrs API key. ( Required for deleting images )
|
2022-07-11 20:38:37 +00:00
|
|
|
#[default(None)]
|
|
|
|
pub api_key: Option<String>,
|
2023-08-31 14:36:39 +00:00
|
|
|
|
|
|
|
/// Cache remote images
|
|
|
|
#[default(true)]
|
|
|
|
pub cache_remote_images: bool,
|
2022-06-13 19:15:04 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 15:07:24 +00:00
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
|
2023-06-09 12:18:22 +00:00
|
|
|
#[serde(default)]
|
2021-03-01 17:24:11 +00:00
|
|
|
pub struct DatabaseConfig {
|
2023-06-09 12:18:22 +00:00
|
|
|
#[serde(flatten, default)]
|
|
|
|
pub connection: DatabaseConnection,
|
|
|
|
|
|
|
|
/// Maximum number of active sql connections
|
|
|
|
#[default(5)]
|
|
|
|
pub pool_size: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
|
|
|
|
#[serde(untagged)]
|
|
|
|
pub enum DatabaseConnection {
|
|
|
|
/// Configure the database by specifying a URI
|
|
|
|
///
|
|
|
|
/// This is the preferred method to specify database connection details since
|
|
|
|
/// it is the most flexible.
|
|
|
|
Uri {
|
|
|
|
/// Connection URI pointing to a postgres instance
|
|
|
|
///
|
|
|
|
/// This example uses peer authentication to obviate the need for creating,
|
|
|
|
/// configuring, and managing passwords.
|
|
|
|
///
|
|
|
|
/// For an explanation of how to use connection URIs, see [here][0] in
|
|
|
|
/// PostgreSQL's documentation.
|
|
|
|
///
|
|
|
|
/// [0]: https://www.postgresql.org/docs/current/libpq-connect.html#id-1.7.3.8.3.6
|
|
|
|
#[doku(example = "postgresql:///lemmy?user=lemmy&host=/var/run/postgresql")]
|
|
|
|
uri: String,
|
|
|
|
},
|
|
|
|
|
|
|
|
/// Configure the database by specifying parts of a URI
|
|
|
|
///
|
|
|
|
/// Note that specifying the `uri` field should be preferred since it provides
|
|
|
|
/// greater control over how the connection is made. This merely exists for
|
|
|
|
/// backwards-compatibility.
|
|
|
|
#[default]
|
|
|
|
Parts(DatabaseConnectionParts),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
|
|
|
|
#[serde(default)]
|
|
|
|
pub struct DatabaseConnectionParts {
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Username to connect to postgres
|
2021-08-04 21:13:51 +00:00
|
|
|
#[default("lemmy")]
|
|
|
|
pub(super) user: String,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Password to connect to postgres
|
2021-08-04 21:13:51 +00:00
|
|
|
#[default("password")]
|
2021-03-01 17:24:11 +00:00
|
|
|
pub password: String,
|
2021-08-04 21:13:51 +00:00
|
|
|
#[default("localhost")]
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Host where postgres is running
|
2021-03-01 17:24:11 +00:00
|
|
|
pub host: String,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Port where postgres can be accessed
|
2021-08-04 21:13:51 +00:00
|
|
|
#[default(5432)]
|
|
|
|
pub(super) port: i32,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Name of the postgres database for lemmy
|
2021-08-04 21:13:51 +00:00
|
|
|
#[default("lemmy")]
|
|
|
|
pub(super) database: String,
|
2021-03-01 17:24:11 +00:00
|
|
|
}
|
|
|
|
|
2022-01-26 16:42:43 +00:00
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone, Document, SmartDefault)]
|
2023-05-12 00:12:12 +00:00
|
|
|
#[serde(deny_unknown_fields)]
|
2021-03-01 17:24:11 +00:00
|
|
|
pub struct EmailConfig {
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Hostname and port of the smtp server
|
|
|
|
#[doku(example = "localhost:25")]
|
2021-03-01 17:24:11 +00:00
|
|
|
pub smtp_server: String,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Login name for smtp server
|
2021-03-01 17:24:11 +00:00
|
|
|
pub smtp_login: Option<String>,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Password to login to the smtp server
|
2021-03-01 17:24:11 +00:00
|
|
|
pub smtp_password: Option<String>,
|
2021-10-08 15:07:24 +00:00
|
|
|
#[doku(example = "noreply@example.com")]
|
|
|
|
/// Address to send emails from, eg "noreply@your-instance.com"
|
2021-03-01 17:24:11 +00:00
|
|
|
pub smtp_from_address: String,
|
2022-01-26 16:42:43 +00:00
|
|
|
/// Whether or not smtp connections should use tls. Can be none, tls, or starttls
|
|
|
|
#[default("none")]
|
|
|
|
#[doku(example = "none")]
|
|
|
|
pub tls_type: String,
|
2021-03-01 17:24:11 +00:00
|
|
|
}
|
|
|
|
|
2021-10-08 15:07:24 +00:00
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
|
2023-05-12 00:12:12 +00:00
|
|
|
#[serde(deny_unknown_fields)]
|
2021-03-01 17:24:11 +00:00
|
|
|
pub struct SetupConfig {
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Username for the admin user
|
|
|
|
#[doku(example = "admin")]
|
2021-03-01 17:24:11 +00:00
|
|
|
pub admin_username: String,
|
2021-12-12 16:42:24 +00:00
|
|
|
/// Password for the admin user. It must be at least 10 characters.
|
2022-06-08 15:44:53 +00:00
|
|
|
#[doku(example = "tf6HHDS4RolWfFhk4Rq9")]
|
2021-03-01 17:24:11 +00:00
|
|
|
pub admin_password: String,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Name of the site (can be changed later)
|
|
|
|
#[doku(example = "My Lemmy Instance")]
|
2021-03-01 17:24:11 +00:00
|
|
|
pub site_name: String,
|
2021-10-08 15:07:24 +00:00
|
|
|
/// Email for the admin user (optional, can be omitted and set later through the website)
|
2022-06-08 15:44:53 +00:00
|
|
|
#[doku(example = "user@example.com")]
|
2021-08-23 09:44:10 +00:00
|
|
|
#[default(None)]
|
|
|
|
pub admin_email: Option<String>,
|
2021-03-01 17:24:11 +00:00
|
|
|
}
|
2023-07-05 11:25:19 +00:00
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)]
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
pub struct PrometheusConfig {
|
|
|
|
// Address that the Prometheus metrics will be served on.
|
|
|
|
#[default(Some(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))))]
|
|
|
|
#[doku(example = "127.0.0.1")]
|
|
|
|
pub bind: Option<IpAddr>,
|
|
|
|
// Port that the Prometheus metrics will be served on.
|
|
|
|
#[default(Some(10002))]
|
|
|
|
#[doku(example = "10002")]
|
|
|
|
pub port: Option<i32>,
|
|
|
|
}
|