self-hosting/modules/stb.nix

85 lines
2.1 KiB
Nix
Raw Permalink Normal View History

2024-12-10 11:39:55 +01:00
{
pkgs,
config,
lib,
...
}:
2021-12-08 01:03:24 +01:00
let
2024-03-26 23:37:53 +01:00
cfg = config.custom.services.stb;
2021-12-08 01:03:24 +01:00
uploadWordpressConfig = pkgs.writeText "upload.ini" ''
file_uploads = On
memory_limit = 64M
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 600
'';
2024-12-10 11:39:55 +01:00
in
{
options.custom.services.stb = {
enable = lib.mkEnableOption "stb";
};
2021-12-08 01:03:24 +01:00
2024-03-26 23:37:53 +01:00
config = lib.mkIf cfg.enable {
2024-12-10 11:39:55 +01:00
virtualisation.podman.defaultNetwork.settings = {
dns_enabled = true;
};
2024-03-26 23:37:53 +01:00
systemd.services.init-stb-network = {
description = "Create the network bridge stb-br for wordpress.";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
2021-12-08 01:03:24 +01:00
2024-03-26 23:37:53 +01:00
serviceConfig.Type = "oneshot";
script =
2024-12-10 11:39:55 +01:00
let
podmancli = "${pkgs.podman}/bin/podman";
in
''
2024-03-26 23:37:53 +01:00
# Put a true at the end to prevent getting non-zero return code, which will
# crash the whole service.
2024-12-10 11:39:55 +01:00
check=$(${podmancli} pod ps | grep "stb" || true)
2024-03-26 23:37:53 +01:00
if [ -z "$check" ]; then
2024-12-10 11:39:55 +01:00
${podmancli} pod create --publish 8180:80 stb
2024-03-26 23:37:53 +01:00
else
2024-12-10 11:39:55 +01:00
echo "stb pod already exists"
2024-03-26 23:37:53 +01:00
fi
'';
2021-12-08 01:03:24 +01:00
};
2024-03-26 23:37:53 +01:00
virtualisation.oci-containers.containers = {
"stb-mariadb" = {
image = "mariadb:10.7";
environment = {
"MYSQL_ROOT_PASSWORD" = "root";
"MYSQL_USER" = "stb";
"MYSQL_PASSWORD" = "stb";
"MYSQL_DATABASE" = "stb";
};
volumes = [ "/var/lib/mariadb/stb:/var/lib/mysql" ];
2024-12-10 11:39:55 +01:00
extraOptions = [ "--pod=stb" ];
2024-03-26 23:37:53 +01:00
autoStart = true;
};
"stb-wordpress" = {
image = "wordpress:5.8-php7.4-apache";
volumes = [
"/nix/var/data/stb-wordpress:/var/www/html"
"${uploadWordpressConfig}:/usr/local/etc/php/conf.d/uploads.ini"
];
2024-12-10 11:39:55 +01:00
extraOptions = [ "--pod=stb" ];
2024-03-26 23:37:53 +01:00
autoStart = true;
};
2021-12-08 01:03:24 +01:00
};
2024-03-26 23:37:53 +01:00
services.nginx.virtualHosts."www.societe-de-tir-bertrix.com" = {
serverAliases = [ "societe-de-tir-bertrix.com" ];
forceSSL = true;
enableACME = true;
2021-12-08 01:03:24 +01:00
2024-12-10 11:39:55 +01:00
locations."/" = {
proxyPass = "http://127.0.0.1:8180";
};
2021-12-08 01:03:24 +01:00
};
};
}