mirror of
https://codeberg.org/muon/home.git
synced 2026-03-08 03:25:16 +00:00
186 lines
5.8 KiB
Nix
186 lines
5.8 KiB
Nix
# Auto-generated by compose2nix.
|
|
{
|
|
pkgs,
|
|
lib,
|
|
config,
|
|
...
|
|
}: let
|
|
cfg = config.mods.server.seedbox;
|
|
port = config.mods.server.nginx.ports.stream;
|
|
backend-port = config.mods.server.local.ports.seedbox;
|
|
in
|
|
with lib; {
|
|
options.mods.server.seedbox = {
|
|
enable = mkEnableOption {
|
|
default = false;
|
|
description = "enables seedbox-lite containers";
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
# Runtime
|
|
virtualisation.podman = {
|
|
enable = true;
|
|
autoPrune.enable = true;
|
|
dockerCompat = true;
|
|
};
|
|
|
|
# Enable container name DNS for all Podman networks.
|
|
networking.firewall.interfaces = let
|
|
matchAll =
|
|
if !config.networking.nftables.enable
|
|
then "podman+"
|
|
else "podman*";
|
|
in {
|
|
"${matchAll}".allowedUDPPorts = [53];
|
|
};
|
|
|
|
virtualisation.oci-containers.backend = "podman";
|
|
|
|
# Containers
|
|
virtualisation.oci-containers.containers."seedbox-backend" = {
|
|
image = "localhost/compose2nix/seedbox-backend";
|
|
volumes = [
|
|
"seedbox-lite_seedbox_cache:/app/cache:rw"
|
|
"seedbox-lite_seedbox_data:/app/data:rw"
|
|
];
|
|
ports = [
|
|
"${toString backend-port}:3001/tcp"
|
|
];
|
|
log-driver = "journald";
|
|
extraOptions = [
|
|
"--network-alias=seedbox-backend"
|
|
"--network=seedbox-lite_seedbox-network"
|
|
];
|
|
};
|
|
systemd.services."podman-seedbox-backend" = {
|
|
serviceConfig = {
|
|
Restart = lib.mkOverride 90 "always";
|
|
};
|
|
after = [
|
|
"podman-network-seedbox-lite_seedbox-network.service"
|
|
"podman-volume-seedbox-lite_seedbox_cache.service"
|
|
"podman-volume-seedbox-lite_seedbox_data.service"
|
|
];
|
|
requires = [
|
|
"podman-network-seedbox-lite_seedbox-network.service"
|
|
"podman-volume-seedbox-lite_seedbox_cache.service"
|
|
"podman-volume-seedbox-lite_seedbox_data.service"
|
|
];
|
|
partOf = [
|
|
"podman-compose-seedbox-lite-root.target"
|
|
];
|
|
wantedBy = [
|
|
"podman-compose-seedbox-lite-root.target"
|
|
];
|
|
};
|
|
virtualisation.oci-containers.containers."seedbox-frontend" = {
|
|
image = "localhost/compose2nix/seedbox-frontend";
|
|
ports = [
|
|
"${toString port}:80/tcp"
|
|
];
|
|
dependsOn = [
|
|
"seedbox-backend"
|
|
];
|
|
log-driver = "journald";
|
|
extraOptions = [
|
|
"--network-alias=seedbox-frontend"
|
|
"--network=seedbox-lite_seedbox-network"
|
|
];
|
|
};
|
|
systemd.services."podman-seedbox-frontend" = {
|
|
serviceConfig = {
|
|
Restart = lib.mkOverride 90 "always";
|
|
};
|
|
after = [
|
|
"podman-network-seedbox-lite_seedbox-network.service"
|
|
];
|
|
requires = [
|
|
"podman-network-seedbox-lite_seedbox-network.service"
|
|
];
|
|
partOf = [
|
|
"podman-compose-seedbox-lite-root.target"
|
|
];
|
|
wantedBy = [
|
|
"podman-compose-seedbox-lite-root.target"
|
|
];
|
|
};
|
|
|
|
# Networks
|
|
systemd.services."podman-network-seedbox-lite_seedbox-network" = {
|
|
path = [pkgs.podman];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
RemainAfterExit = true;
|
|
ExecStop = "podman network rm -f seedbox-lite_seedbox-network";
|
|
};
|
|
script = ''
|
|
podman network inspect seedbox-lite_seedbox-network || podman network create seedbox-lite_seedbox-network --driver=bridge
|
|
'';
|
|
partOf = ["podman-compose-seedbox-lite-root.target"];
|
|
wantedBy = ["podman-compose-seedbox-lite-root.target"];
|
|
};
|
|
|
|
# Volumes
|
|
systemd.services."podman-volume-seedbox-lite_seedbox_cache" = {
|
|
path = [pkgs.podman];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
RemainAfterExit = true;
|
|
};
|
|
script = ''
|
|
podman volume inspect seedbox-lite_seedbox_cache || podman volume create seedbox-lite_seedbox_cache --driver=local
|
|
'';
|
|
partOf = ["podman-compose-seedbox-lite-root.target"];
|
|
wantedBy = ["podman-compose-seedbox-lite-root.target"];
|
|
};
|
|
systemd.services."podman-volume-seedbox-lite_seedbox_data" = {
|
|
path = [pkgs.podman];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
RemainAfterExit = true;
|
|
};
|
|
script = ''
|
|
podman volume inspect seedbox-lite_seedbox_data || podman volume create seedbox-lite_seedbox_data --driver=local
|
|
'';
|
|
partOf = ["podman-compose-seedbox-lite-root.target"];
|
|
wantedBy = ["podman-compose-seedbox-lite-root.target"];
|
|
};
|
|
|
|
# Builds
|
|
systemd.services."podman-build-seedbox-backend" = {
|
|
path = [pkgs.podman pkgs.git];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
TimeoutSec = 300;
|
|
};
|
|
script = ''
|
|
cd /home/muon/projects/seedbox-lite/server
|
|
podman build -t compose2nix/seedbox-backend .
|
|
'';
|
|
};
|
|
systemd.services."podman-build-seedbox-frontend" = {
|
|
path = [pkgs.podman pkgs.git];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
TimeoutSec = 300;
|
|
};
|
|
script = ''
|
|
cd /tmp
|
|
git clone https://github.com/hotheadhacker/seedbox-lite.git
|
|
cd seedbox-lite/client
|
|
podman build -t compose2nix/seedbox-frontend --build-arg VITE_API_BASE_URL=http://localhost:${toString backend-port} .
|
|
'';
|
|
};
|
|
|
|
# Root service
|
|
# When started, this will automatically create all resources and start
|
|
# the containers. When stopped, this will teardown all resources.
|
|
systemd.targets."podman-compose-seedbox-lite-root" = {
|
|
unitConfig = {
|
|
Description = "Root target generated by compose2nix.";
|
|
};
|
|
wantedBy = ["multi-user.target"];
|
|
};
|
|
};
|
|
}
|