2024-01-20 11:25:09 -08:00
|
|
|
{ config, lib, pkgs, ... }@toplevel:
|
|
|
|
|
|
|
|
with lib;
|
2024-01-24 19:33:59 -08:00
|
|
|
let cfg = config.services.lemmyContainer;
|
2024-01-20 11:25:09 -08:00
|
|
|
|
|
|
|
in {
|
2024-01-20 11:37:14 -08:00
|
|
|
options.services.lemmyContainer = with types; {
|
2024-01-20 11:25:09 -08:00
|
|
|
enable = mkEnableOption "Enable Lemmy server in a Podman container.";
|
|
|
|
|
|
|
|
hostname = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Host of the Lemmy server.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = port;
|
|
|
|
description = "Port on which to listen for requests.";
|
|
|
|
default = 1234;
|
|
|
|
};
|
|
|
|
|
|
|
|
site-name = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Name of the Lemmy site.";
|
|
|
|
};
|
|
|
|
|
|
|
|
admin-password-file = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Path to a file containing the administrator password.";
|
|
|
|
};
|
2024-01-20 11:34:58 -08:00
|
|
|
|
|
|
|
smtp = {
|
|
|
|
host = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "SMTP server hostname.";
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2024-01-20 11:56:19 -08:00
|
|
|
type = port;
|
2024-01-20 11:34:58 -08:00
|
|
|
description = "SMTP server port.";
|
|
|
|
default = 25;
|
|
|
|
};
|
|
|
|
};
|
2024-01-22 15:07:40 -08:00
|
|
|
|
|
|
|
server-package = mkOption {
|
|
|
|
type = package;
|
|
|
|
description = "Package to use for the server.";
|
|
|
|
default = pkgs.lemmy-server;
|
|
|
|
};
|
2024-01-24 19:33:59 -08:00
|
|
|
|
|
|
|
state-directory = mkOption {
|
|
|
|
type = str;
|
|
|
|
description = "Path at which to store server state.";
|
|
|
|
};
|
2024-01-20 11:25:09 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2024-01-24 19:40:27 -08:00
|
|
|
systemd.tmpfiles.rules = [
|
2024-01-24 22:14:06 -08:00
|
|
|
"d ${cfg.state-directory}/postgres 0700 root root - -"
|
|
|
|
"d ${cfg.state-directory}/pictrs 0700 root root - -"
|
2024-01-24 19:40:27 -08:00
|
|
|
];
|
|
|
|
|
2024-01-24 19:33:59 -08:00
|
|
|
containers.lemmy = {
|
|
|
|
autoStart = true;
|
|
|
|
privateNetwork = true;
|
|
|
|
forwardPorts = [{
|
|
|
|
protocol = "tcp";
|
|
|
|
hostPort = cfg.port;
|
|
|
|
containerPort = 80;
|
|
|
|
}];
|
2024-01-25 09:29:05 -08:00
|
|
|
## Does ephemeral mean read-only?
|
|
|
|
# ephemeral = true;
|
2024-01-24 19:33:59 -08:00
|
|
|
bindMounts = {
|
|
|
|
"/var/lib/postgres/data" = {
|
|
|
|
hostPath = "${cfg.state-directory}/postgres";
|
|
|
|
};
|
2024-01-24 19:40:27 -08:00
|
|
|
"/var/lib/private" = { hostPath = "${cfg.state-directory}/pictrs"; };
|
2024-01-24 19:33:59 -08:00
|
|
|
"${cfg.admin-password-file}" = {
|
|
|
|
isReadOnly = true;
|
|
|
|
hostPath = cfg.admin-password-file;
|
|
|
|
};
|
|
|
|
};
|
2024-01-24 23:08:30 -08:00
|
|
|
additionalCapabilities = [ "CAP_SYS_ADMIN" ];
|
2024-01-24 19:33:59 -08:00
|
|
|
config = {
|
|
|
|
boot.tmp.useTmpfs = true;
|
2024-01-24 22:04:18 -08:00
|
|
|
system.nssModules = mkForce [ ];
|
2024-01-24 19:33:59 -08:00
|
|
|
services = {
|
|
|
|
nscd.enable = false;
|
|
|
|
postgresql.enable = true;
|
|
|
|
pict-rs.enable = true;
|
|
|
|
lemmy = {
|
|
|
|
enable = true;
|
|
|
|
database.createLocally = true;
|
|
|
|
adminPasswordFile = cfg.admin-password-file;
|
|
|
|
nginx.enable = true;
|
|
|
|
server.package = cfg.server-package;
|
|
|
|
settings = {
|
|
|
|
email = {
|
|
|
|
smtp_server = cfg.smtp.host;
|
|
|
|
smtp_port = cfg.smtp.port;
|
|
|
|
smtp_from_address = "noreply@${cfg.hostname}";
|
|
|
|
};
|
|
|
|
hostname = cfg.hostname;
|
|
|
|
setup.site_name = cfg.site-name;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
nginx = {
|
|
|
|
recommendedGzipSettings = true;
|
|
|
|
recommendedOptimisation = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
commonHttpConfig = ''
|
|
|
|
log_format with_response_time '$remote_addr - $remote_user [$time_local] '
|
|
|
|
'"$request" $status $body_bytes_sent '
|
|
|
|
'"$http_referer" "$http_user_agent" '
|
|
|
|
'"$request_time" "$upstream_response_time"';
|
|
|
|
access_log /var/log/nginx/access.log with_response_time;
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-01-20 11:25:09 -08:00
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
virtualHosts."${cfg.hostname}" = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://127.0.0.1:${toString cfg.port}/";
|
|
|
|
proxyWebsockets = true;
|
|
|
|
recommendedProxySettings = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|