feat: add custom env support
This commit is contained in:
parent
d09d0960de
commit
2a08830ac0
3 changed files with 17 additions and 41 deletions
|
|
@ -13,16 +13,17 @@ def run_script_rootfs(rootfs: RootFS, input: str, args: list):
|
|||
rootfs.exec(["bash", "-s", *args], text=True, input=input)
|
||||
|
||||
|
||||
def gen_rootfs(system_config: dict, rootfs_path: str) -> RootFS:
|
||||
def gen_rootfs(system_config: dict, rootfs_path: str, env: dict = {}) -> RootFS:
|
||||
"""Generates a rootfs for a given system configuration."""
|
||||
|
||||
rootfs = RootFS(rootfs_path, system_config["distro-config"])
|
||||
rootfs = RootFS(rootfs_path, system_config["distro-config"], env)
|
||||
|
||||
subprocess.run(
|
||||
["bash", "-s"],
|
||||
text=True,
|
||||
input=system_config["distro-config"]["before-stages"],
|
||||
cwd=rootfs_path,
|
||||
env=os.environ.copy() | env,
|
||||
)
|
||||
|
||||
modules = {}
|
||||
|
|
@ -46,6 +47,7 @@ def gen_rootfs(system_config: dict, rootfs_path: str) -> RootFS:
|
|||
text=True,
|
||||
input=system_config["distro-config"]["after-stages"],
|
||||
cwd=str(rootfs_path),
|
||||
env=os.environ.copy() | env,
|
||||
)
|
||||
|
||||
with open(os.path.join(rootfs_path, "usr/system.json"), "w") as system_json_file:
|
||||
|
|
|
|||
|
|
@ -22,6 +22,9 @@ def resolve_config(system_config: dict) -> dict:
|
|||
"override": system_config["override"]
|
||||
if isinstance(system_config.get("override"), list)
|
||||
else [],
|
||||
"env": system_config["env"]
|
||||
if isinstance(system_config.get("env"), dict)
|
||||
else {},
|
||||
"distro-config": system_config["distro-config"],
|
||||
"auto-update": system_config["auto-update"]
|
||||
if isinstance(system_config.get("auto-update"), dict)
|
||||
|
|
@ -63,6 +66,12 @@ def resolve_config(system_config: dict) -> dict:
|
|||
else []
|
||||
)
|
||||
|
||||
base_config["env"] = (
|
||||
base_config["env"] | system_config["env"]
|
||||
if isinstance(system_config.get("env"), dict)
|
||||
else base_config["env"]
|
||||
)
|
||||
|
||||
base_config["auto-update"] = (
|
||||
system_config["auto-update"]
|
||||
if isinstance(system_config.get("auto-update"), dict)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue