mirror of
https://github.com/oqyude/nixos.git
synced 2026-10-07 20:47:14 +03:00
122 lines
3.7 KiB
Nix
122 lines
3.7 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
xlib,
|
|
...
|
|
}:
|
|
let
|
|
panel = "${xlib.dirs.services-nodes-folder}/${xlib.device.hostname}/3x-ui";
|
|
certDomain = xlib.services."3x-ui".certDomain or null;
|
|
certMounts =
|
|
if certDomain == null then
|
|
[ ]
|
|
else
|
|
# LE cert mounted read-only so 3x-ui can terminate TLS itself.
|
|
# The 3x-ui settings table must point webCertFile / webKeyFile at
|
|
# /root/cert/fullchain.pem and /root/cert/key.pem.
|
|
map (f: "/var/lib/acme/${certDomain}/${f}:/root/cert/${f}:ro") [
|
|
"fullchain.pem"
|
|
"key.pem"
|
|
];
|
|
basePorts = [
|
|
# Local-only upstreams for the 3x-ui panel and subscription endpoint.
|
|
# The direct Xray inbound remains publicly reachable on 8443.
|
|
"127.0.0.1:2049:2049/tcp"
|
|
"127.0.0.1:2096:2096/tcp"
|
|
"0.0.0.0:8443:8443/tcp"
|
|
];
|
|
# VDS-only: nginx stream forwards host:443 → 127.0.0.1:15380 →
|
|
# container:443, so Xray sees its REALITY inbound on port 443.
|
|
realityPorts = lib.optional xlib.services."3x-ui".reality443Forwarding "127.0.0.1:15380:443/tcp";
|
|
in
|
|
{
|
|
virtualisation = {
|
|
podman = {
|
|
enable = true;
|
|
autoPrune = {
|
|
enable = true;
|
|
flags = [ "--all" ];
|
|
};
|
|
dockerCompat = true;
|
|
};
|
|
oci-containers = {
|
|
backend = "podman";
|
|
containers."3xui_app" = {
|
|
image = "ghcr.io/mhsanaei/3x-ui:latest";
|
|
environment = {
|
|
"XRAY_VMESS_AEAD_FORCED" = "false";
|
|
"XUI_ENABLE_FAIL2BAN" = "true";
|
|
"TZ" = "Europe/Moscow";
|
|
};
|
|
volumes = [
|
|
"${panel}/cert/:/root/cert:rw"
|
|
"${panel}/db/:/etc/x-ui:rw"
|
|
]
|
|
++ certMounts;
|
|
log-driver = "journald";
|
|
# Adding a new inbound through the 3x-ui panel on a port outside
|
|
# the 14380-15379 range requires extending basePorts and rebuilding.
|
|
ports = basePorts ++ realityPorts;
|
|
};
|
|
};
|
|
};
|
|
|
|
systemd = {
|
|
services = {
|
|
"podman-3xui_app" = {
|
|
serviceConfig.Restart = lib.mkOverride 90 "always";
|
|
partOf = [ "podman-compose-3x-ui-root.target" ];
|
|
wantedBy = [ "podman-compose-3x-ui-root.target" ];
|
|
};
|
|
"podman-update-3xui_app" = {
|
|
path = [ pkgs.podman ];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
TimeoutSec = 300;
|
|
};
|
|
script = ''
|
|
podman pull ghcr.io/mhsanaei/3x-ui:latest
|
|
systemctl restart podman-3xui_app.service
|
|
'';
|
|
};
|
|
};
|
|
# Starts/stops together with all 3x-ui compose resources.
|
|
targets."podman-compose-3x-ui-root" = {
|
|
unitConfig.Description = "Root target generated by compose2nix.";
|
|
wantedBy = [ "multi-user.target" ];
|
|
};
|
|
# timers."podman-update-3xui_app" = {
|
|
# wantedBy = [ "timers.target" ];
|
|
# timerConfig = {
|
|
# OnCalendar = "weekly";
|
|
# Persistent = true;
|
|
# };
|
|
# };
|
|
tmpfiles.rules = [
|
|
(xlib.helpers.mkTmpfile "d" xlib.dirs.services-mnt-folder "0755" "root" "root")
|
|
(xlib.helpers.mkTmpfile "d" xlib.dirs.services-nodes-folder "0755" "root" "root")
|
|
(xlib.helpers.mkTmpfile "d" "${xlib.dirs.services-nodes-folder}/${xlib.device.hostname}" "0755"
|
|
"root"
|
|
"root"
|
|
)
|
|
(xlib.helpers.mkTmpfile "d" panel "0755" "root" "root")
|
|
(xlib.helpers.mkTmpfile "d" "${panel}/db" "0755" "root" "root")
|
|
(xlib.helpers.mkTmpfile "d" "${panel}/cert" "0755" "root" "root")
|
|
# Relabel panel dir for SELinux so containers can access it.
|
|
(xlib.helpers.mkTmpfile "Z" panel "0755" "root" "root")
|
|
];
|
|
};
|
|
|
|
# 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 ];
|
|
};
|
|
};
|
|
}
|