Merge pull request 'clan-cli: fix bubblewrap not finding bash when IN_NIX_SANDBOX=1 if prev environment doesn't have it in PATH' (#3503) from Qubasa/clan-core:fix_bubblewrap_bash_path into main

Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3503
This commit is contained in:
Luis Hebendanz
2025-05-05 21:07:22 +00:00
2 changed files with 22 additions and 10 deletions

View File

@@ -1,4 +1,8 @@
from clan_cli.cmd import run
import os
import shutil
from pathlib import Path
from clan_cli.cmd import Log, RunOpts, run
from clan_cli.nix import nix_shell
_works: bool | None = None
@@ -12,6 +16,11 @@ def bubblewrap_works() -> bool:
def _bubblewrap_works() -> bool:
real_bash_path = Path("bash")
if os.environ.get("IN_NIX_SANDBOX"):
bash_executable_path = Path(str(shutil.which("bash")))
real_bash_path = bash_executable_path.resolve()
# fmt: off
cmd = nix_shell(
[
@@ -30,13 +39,10 @@ def _bubblewrap_works() -> bool:
"--gid", "1000",
"--",
# do nothing, just test if bash executes
"bash", "-c", ":"
str(real_bash_path), "-c", ":"
],
)
# fmt: on
try:
run(cmd)
except Exception:
return False
else:
return True
res = run(cmd, RunOpts(log=Log.BOTH, check=False))
return res.returncode == 0

View File

@@ -1,6 +1,7 @@
import argparse
import logging
import os
import shutil
import sys
from dataclasses import dataclass, field
from functools import cached_property
@@ -86,6 +87,11 @@ class Generator:
def bubblewrap_cmd(generator: str, tmpdir: Path) -> list[str]:
test_store = nix_test_store()
real_bash_path = Path("bash")
if os.environ.get("IN_NIX_SANDBOX"):
bash_executable_path = Path(str(shutil.which("bash")))
real_bash_path = bash_executable_path.resolve()
# fmt: off
return nix_shell(
[
@@ -109,8 +115,8 @@ def bubblewrap_cmd(generator: str, tmpdir: Path) -> list[str]:
"--uid", "1000",
"--gid", "1000",
"--",
"bash", "-c", generator
],
str(real_bash_path), "-c", generator
]
)
# fmt: on