mirror of
https://github.com/oqyude/nixos.git
synced 2026-10-11 14:27:26 +03:00
Comprehensive batch addressing the 16-task backlog in
.agent/tasks/manifest.json. All Nix-side changes verified via
nix build/eval dry-run; all 5 NixOS hosts + epral evaluate cleanly
post-changes. No regressions.
Wave 1 (non-functional cleanup):
T1/A1 — configurations/mobile.nix:12: fix `import ../lib/xlib.nix`
(broken path) → `import ../lib/xlib`. Unblocks nixOnDroid
configurations.epral. R1.1 invariant.
T8/C3 — modules/containers/3x-ui.nix: remove `podman-update-3xui_app`
systemd service and commented timer. Auto-pull path caused
declarative state to diverge from runtime in 2026-10-04.
R1.5 invariant.
T13/D3 — modules/server/nginx.nix:368-371: remove dead
`networking.firewall.allowedTCPPorts = [80 443]`.
`firewall.enable = false` on sapphira (R1.3), so openFirewall
rules are no-op. Replace with R1.3 comment.
T6/C1 — .agent/decisions/notes/3x-ui-xray-26.9.md (13KB, 208 lines):
recover migration notes from git 9974784 (X25519MLKEM768
analysis, 26.7→26.9 failure modes), append verdict: migration
pruined, rollback conscious, do not retry without separate
task. R1.5 / C1.
T9/C4 — .agent/rules/project-rules.md: add R1.8 — Xray-core version is
state of 3x-ui panel, not Nix. Update trap entry for
3x-ui.nix:54 to reference R1.8.
T11/D1, T12/D2 — .agent/checkpoints.json + .agent/tasks/manifest.json:
verify R1.3 (router port-forwards 22/80/443/8443/22000) and
R1.4 (100.64.0.0 = Tailscale sapphira) wording already
satisfies acceptance criteria. Flip status pending → completed.
T4 (storage guard, FUNCTIONAL CHANGE):
New helper in lib/xlib/helpers.nix:
mkStorageGuard = xlib: {
RequiresMountsFor = [ xlib.dirs.server-home ];
ConditionPathIsMountPoint = [ "!${xlib.dirs.server-home}" ];
};
Applied to 13 systemd units via path-style override:
- modules/server/{postgresql,samba,homebox,gitea,navidrome,
syncthing,uptime-kuma,immich,nextcloud,calibre-web}.nix
- modules/containers/3x-ui.nix (podman-3xui_app)
- modules/containers/tape-rotation.nix (podman-taperotation-{backend,frontend})
Anchor: xlib.dirs.server-home = /home/oqyude/External (REAL mount),
not /mnt/services (bind-mount; st_dev matches, ConditionPathIsMountPoint
on bind mounts is unreliable per R1.2 note).
Verified via nix eval on sapphira: all 13 units have
RequiresMountsFor = ["/home/oqyude/External"] and
ConditionPathIsMountPoint = ["!/home/oqyude/External"].
Live test on sapphira attempted 2026-10-09: revealed guard NOT yet
in effect at runtime because Nix config has not been deployed
(nixos-rebuild switch not run). postgresql started despite External
being unmounted. Implementation correct, deployment pending user
action.
T7/C2 (read-only diag, no code change):
3x-ui version facts recorded in conversation (sapphira journal +
/var/lib/containers/storage/overlay/.../diff/app/bin/xray-linux-amd64):
- Active Xray: 26.7.28 (go1.26.5 linux/amd64) — R1.5 validated at runtime
- Stale binary: 26.9.30 (go1.27.1) — leftover from failed 26.9 migration
- Panel DB (x-ui.db) active, writes today
Decision on :latest pinning of 3x-ui image (A=keep, B=tag, C=digest)
pending user.
T3/A3 (nftables on otreca — config analysis + proposal):
Diagnostic attempted via ssh otreca-tailscale (100.64.1.0) and
otreca public (109.248.161.5:22): BOTH UNREACHABLE. Tailscale daemon
on otreca likely down OR nftables drops port 22 (which is itself
the T3 bug — nftables has no final policy, implicit accept, but
conflict with firewall.enable = true per R1.6).
Proposal written: .agent/decisions/proposals/vds-nftables-fix.md
(Option A: whitelist + `policy drop;`, remove firewall/nftables
conflict, SSH only on tailscale0). Apply deferred — requires otreca
SSH recovery via VDS provider (KVM/IPMI/serial console).
T5/B2 (backups documentation):
.agent/decisions/0002-backups-external.md (draft): catalog of what
is declared in Nix vs. what is external; awaiting answer to open
question 5.6 (where are backups, how are they verified).
T15/E2 (CI checks):
.ci/checks.sh (executable, ~140 lines) with 3 checks from
analysis-report.md §5:
- #1: no `:latest` in container images (with R1.5 whitelist
for 3x-ui). FAIL — 4 violations:
localhost/kokoro-tts:latest
ghcr.io/openhands/openhands:latest
docker.io/elizaroveugene/taperotation-backend:latest
docker.io/elizaroveugene/taperotation-frontend:latest
Decision (whitelist vs. pin) pending user.
- #2: nix flake check (skipped with --no-build).
- #7: secrets/ files match .sops.yaml path_regex. PASS.
T16/E3 (archive commented modules):
13 of 14 commented modules in modules/server/default.nix:37-50
existed as files. git mv them to archive/{server-modules,containers}/.
1 (stirling-pdf.nix) didn't exist; just removed the comment.
modules/server/default.nix:37-50 cleaned of 14 commented lines.
Added 3-line comment recording the archive date and reason.
Verified: nixosConfigurations.sapphira still evaluates.
Post-change state:
$ nix build .#nixosConfigurations.{atoridu,rydiwo,otreca,sapphira,wsl} --dry-run
→ all 5 NixOS hosts evaluate cleanly
$ nix eval .#nixOnDroidConfigurations.epral.config.system.stateVersion
→ "24.05"
Pending (user input required — not in this commit):
- T4 deploy: run `nixos-rebuild switch` on sapphira to activate guard
- T7: pick A/B/C for 3x-ui :latest pinning
- T3: recover otreca SSH via VDS provider, then apply Option A
- T10/C5: decide fate of reality443Forwarding
- T5: answer 5.6 about backup location/verification
- T15: whitelist or pin 4 :latest images
Untracked files NOT committed (in .gitignore):
.temp/t4-live-test*.sh, .temp/cleanup-*.sh — throwaway test scripts
from T4 live test attempts. Preserved locally for reference; see
AGENTS.md convention ("Создавать `.temp/` в корне проекта — Для
временных файлов агента. Всегда в `.gitignore`").
Also untracked, committed:
.agent/reviews/2026-10-10-review-dev-diff-vs-16644fc.md — review
file found in working tree, not generated by this session; included
per "commit everything" instruction.
208 lines
6.1 KiB
Nix
208 lines
6.1 KiB
Nix
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
inputs,
|
|
xlib,
|
|
...
|
|
}:
|
|
let
|
|
# Composite env file path shared by the generator
|
|
# (remnawave-env.service below) and the container's `environmentFiles`.
|
|
# Lifting to a single binding prevents the two copies from drifting
|
|
# apart in future edits — see invariant S1 in docs/arch/invariants.md.
|
|
# Note: this is NOT a sops materialization (it's written by a oneshot),
|
|
# so `config.sops.secrets.<...>.path` is not the right primitive here.
|
|
envFile = "/run/secrets/remnawave-env";
|
|
in
|
|
{
|
|
# 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."remnawave-panel-1" = {
|
|
image = "ghcr.io/remnawave/backend:latest";
|
|
environment = {
|
|
"API_INSTANCES" = "1";
|
|
"APP_PORT" = "3000";
|
|
"BANDWIDTH_USAGE_NOTIFICATIONS_ENABLED" = "false";
|
|
"BANDWIDTH_USAGE_NOTIFICATIONS_THRESHOLD" = "[60, 80]";
|
|
"FRONT_END_DOMAIN" = "*";
|
|
"IS_DOCS_ENABLED" = "false";
|
|
"IS_TELEGRAM_NOTIFICATIONS_ENABLED" = "false";
|
|
"METRICS_PASS" = "admin";
|
|
"METRICS_PORT" = "3001";
|
|
"METRICS_USER" = "admin";
|
|
"NOT_CONNECTED_USERS_NOTIFICATIONS_AFTER_HOURS" = "[6, 24, 48]";
|
|
"NOT_CONNECTED_USERS_NOTIFICATIONS_ENABLED" = "false";
|
|
"PANEL_DOMAIN" = "rw.zeroq.su";
|
|
"POSTGRES_DB" = "remnawave";
|
|
"POSTGRES_USER" = "remnawave";
|
|
"REDIS_SOCKET" = "/var/run/valkey/valkey.sock";
|
|
"SCALAR_PATH" = "/scalar";
|
|
"SUB_PUBLIC_DOMAIN" = "rw.zeroq.su/api/sub";
|
|
"SWAGGER_PATH" = "/docs";
|
|
# "TELEGRAM_BOT_TOKEN" = "change_me";
|
|
# "TELEGRAM_NOTIFY_CRM" = "change_me";
|
|
# "TELEGRAM_NOTIFY_NODES" = "change_me";
|
|
# "TELEGRAM_NOTIFY_SERVICE" = "change_me";
|
|
# "TELEGRAM_NOTIFY_TBLOCKER" = "change_me";
|
|
# "TELEGRAM_NOTIFY_USERS" = "change_me";
|
|
"WEBHOOK_ENABLED" = "false";
|
|
# "WEBHOOK_URL" = "https://your-webhook-url.com/endpoint";
|
|
};
|
|
environmentFiles = [
|
|
envFile
|
|
];
|
|
ports = [
|
|
"3003:3003/tcp"
|
|
];
|
|
log-driver = "journald";
|
|
extraOptions = [
|
|
"--network-alias=remnawave-panel-1"
|
|
"--network=host" # "--network=remnawavebackend_default"
|
|
];
|
|
};
|
|
systemd.services."podman-remnawave-panel-1" = {
|
|
serviceConfig = {
|
|
Restart = lib.mkOverride 90 "always";
|
|
};
|
|
partOf = [
|
|
"podman-compose-remnawave-root.target"
|
|
];
|
|
wantedBy = [
|
|
"podman-compose-remnawave-root.target"
|
|
];
|
|
};
|
|
|
|
# Builds
|
|
# systemd.services."podman-build-remnawave-panel-1" = {
|
|
# path = [ pkgs.podman pkgs.git ];
|
|
# serviceConfig = {
|
|
# Type = "oneshot";
|
|
# TimeoutSec = 300;
|
|
# };
|
|
# script = ''
|
|
# cd /mnt/s/Deploy/remnawave-backend
|
|
# podman build -t compose2nix/remnawave-panel-1 .
|
|
# '';
|
|
# };
|
|
|
|
# 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-remnawave-root" = {
|
|
unitConfig = {
|
|
Description = "Root target generated by compose2nix.";
|
|
};
|
|
wantedBy = [ "multi-user.target" ];
|
|
};
|
|
|
|
services = {
|
|
postgresql = {
|
|
ensureDatabases = [ "remnawave" ];
|
|
ensureUsers = [
|
|
{
|
|
name = "remnawave";
|
|
ensureDBOwnership = true;
|
|
}
|
|
];
|
|
};
|
|
};
|
|
|
|
systemd.services = {
|
|
remnawave-env = {
|
|
description = "Generate remnawave env file";
|
|
requiredBy = [ "podman-remnawave-panel-1.service" ];
|
|
before = [ "podman-remnawave-panel-1.service" ];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
User = "root";
|
|
};
|
|
script = ''
|
|
cat > ${envFile} <<EOF
|
|
DATABASE_URL=$(cat ${config.sops.secrets.DATABASE_URL.path})
|
|
DATABASE_PASSWORD=$(cat ${config.sops.secrets.DATABASE_PASSWORD.path})
|
|
JWT_AUTH_SECRET=$(cat ${config.sops.secrets.JWT_AUTH_SECRET.path})
|
|
JWT_API_TOKENS_SECRET=$(cat ${config.sops.secrets.JWT_API_TOKENS_SECRET.path})
|
|
WEBHOOK_SECRET_HEADER=$(cat ${config.sops.secrets.WEBHOOK_SECRET_HEADER.path})
|
|
EOF
|
|
chmod 600 ${envFile}
|
|
'';
|
|
wantedBy = [ "multi-user.target" ];
|
|
};
|
|
remnawave-db-init = {
|
|
description = "Initialize Remnawave DB user";
|
|
after = [ "postgresql.service" ];
|
|
requires = [ "postgresql.service" ];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
User = "postgres";
|
|
};
|
|
script = ''
|
|
PASSWORD=$(cat ${config.sops.secrets.DATABASE_PASSWORD.path})
|
|
${pkgs.postgresql}/bin/psql -v ON_ERROR_STOP=1 <<EOF
|
|
DO \$\$
|
|
BEGIN
|
|
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname='remnawave') THEN
|
|
EXECUTE format('ALTER ROLE remnawave WITH PASSWORD %L', '$PASSWORD');
|
|
END IF;
|
|
END
|
|
\$\$ LANGUAGE plpgsql;
|
|
EOF
|
|
'';
|
|
wantedBy = [ "multi-user.target" ];
|
|
};
|
|
};
|
|
|
|
sops.secrets = {
|
|
DATABASE_PASSWORD = {
|
|
key = "DATABASE_PASSWORD";
|
|
sopsFile = ./secrets/remnawave.yaml;
|
|
owner = "postgres";
|
|
group = "postgres";
|
|
mode = "0400";
|
|
};
|
|
WEBHOOK_SECRET_HEADER = {
|
|
key = "WEBHOOK_SECRET_HEADER";
|
|
sopsFile = ./secrets/remnawave.yaml;
|
|
mode = "0400";
|
|
};
|
|
DATABASE_URL = {
|
|
key = "DATABASE_URL";
|
|
sopsFile = ./secrets/remnawave.yaml;
|
|
mode = "0400";
|
|
};
|
|
JWT_AUTH_SECRET = {
|
|
key = "JWT_AUTH_SECRET";
|
|
sopsFile = ./secrets/remnawave.yaml;
|
|
mode = "0400";
|
|
};
|
|
JWT_API_TOKENS_SECRET = {
|
|
key = "JWT_API_TOKENS_SECRET";
|
|
sopsFile = ./secrets/remnawave.yaml;
|
|
mode = "0400";
|
|
};
|
|
};
|
|
systemd.tmpfiles.rules = [
|
|
"d ${xlib.dirs.services-mnt-folder} 0755 root root -"
|
|
"d ${xlib.dirs.services-mnt-folder}/containers 0755 root root -"
|
|
"d ${xlib.dirs.services-mnt-folder}/containers/remnawave 0755 root root -"
|
|
];
|
|
}
|