archinstall_adapter: pass --config/--creds via synthetic sys.argv (env vars don't work)

ArchConfigHandler reads --config and --creds from sys.argv via argparse at
construction time; it ignores ARCHINSTALL_CONFIG/ARCHINSTALL_CREDS env
vars (confirmed in archinstall 4.3 lib/args.py:_parse_args). Setting those
env vars was a no-op, so handler.config.disk_config was always None when
the wrapper stripped our args off the real argv.

Fix: build a synthetic argv [prog, --config <path>, --creds <path>] and
swap it into sys.argv just for the ArchConfigHandler() call, then
restore. Drops the unused 'import os' now that the env var lines are
gone.
This commit is contained in:
Ryan Hughes committed 2026-05-21 19:53:27 -04:00
1 parent c1828b13ad
commit b568b0b796
1 file changed
+20 -6
@@ -35,7 +35,6 @@ correctly, on its first install.
from __future__ import annotations
import os
from contextlib import contextmanager
from pathlib import Path
from typing import Iterator
@@ -54,11 +53,26 @@ from archinstall.lib.models.users import User
def load_arch_config(config_path: Path, creds_path: Path) -> ArchConfigHandler:
"""Build an ArchConfigHandler from on-disk JSON. archinstall reads the
paths via env vars, so we set them before instantiating the handler."""
os.environ["ARCHINSTALL_CONFIG"] = str(config_path)
os.environ["ARCHINSTALL_CREDS"] = str(creds_path)
return ArchConfigHandler()
"""Build an ArchConfigHandler from on-disk JSON.
archinstall's ArchConfigHandler reads --config / --creds from sys.argv
via argparse at construction time (lib/args.py:_parse_args). It does
NOT consult env vars for these paths. We can't pass them on our real
argv because the wrapper strips them before exec'ing Python (so other
archinstall arg-parsing code doesn't choke on our flags), so we hand
archinstall a synthetic argv just for this call.
"""
import sys
saved_argv = sys.argv
sys.argv = [
saved_argv[0] if saved_argv else "omarchy-install",
"--config", str(config_path),
"--creds", str(creds_path),
]
try:
return ArchConfigHandler()
finally:
sys.argv = saved_argv
def make_mirror_handler(offline: bool = True) -> MirrorListHandler: