Skip to content

Commit

Permalink
Check for $HOME environment variable as well
Browse files Browse the repository at this point in the history
Similar to our check for $USER, let's check for $HOME to allow
setting a custom home directory in weird build environments.
  • Loading branch information
DaanDeMeyer committed Jul 29, 2024
1 parent 33f7123 commit 64745f3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion mkosi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ def home(cls) -> Path:
if cls.invoked_as_root and Path.cwd().is_relative_to("/home") and len(Path.cwd().parents) > 2:
return list(Path.cwd().parents)[-3]

return Path(f"~{cls.name()}").expanduser()
try:
return Path(pwd.getpwuid(cls.uid).pw_dir or "/")
except KeyError:
if not (home := os.getenv("HOME")):
die(f"Could not find home directory for UID {cls.uid}")

return Path(home)

@classmethod
@functools.lru_cache(maxsize=1)
Expand Down

0 comments on commit 64745f3

Please sign in to comment.