From 92b98478a830a7f7e6f65195aa1b2257798fe423 Mon Sep 17 00:00:00 2001 From: nikstur Date: Sun, 28 Jan 2024 01:02:15 +0100 Subject: nixos/etc: fix type checking of build-composefs-dump.py --- nixos/modules/system/etc/build-composefs-dump.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nixos/modules/system') diff --git a/nixos/modules/system/etc/build-composefs-dump.py b/nixos/modules/system/etc/build-composefs-dump.py index 923d40008b63..a1b922d97369 100644 --- a/nixos/modules/system/etc/build-composefs-dump.py +++ b/nixos/modules/system/etc/build-composefs-dump.py @@ -83,8 +83,8 @@ class ComposefsPath: return " ".join(line_list) -def eprint(*args, **kwargs) -> None: - print(args, **kwargs, file=sys.stderr) +def eprint(*args: Any, **kwargs: Any) -> None: + print(*args, **kwargs, file=sys.stderr) def leading_directories(path: str) -> list[str]: -- cgit 1.4.1 From a9161ceb5a3669ced280ce0805ad38470b5904b2 Mon Sep 17 00:00:00 2001 From: nikstur Date: Sun, 28 Jan 2024 01:55:05 +0100 Subject: nixos/etc: remove leading slash from target paths in build-composefs-dump.py This is necessary so that duplicates in the composefs dump are avoided. --- nixos/modules/system/etc/build-composefs-dump.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'nixos/modules/system') diff --git a/nixos/modules/system/etc/build-composefs-dump.py b/nixos/modules/system/etc/build-composefs-dump.py index a1b922d97369..bf4ec791ecf7 100644 --- a/nixos/modules/system/etc/build-composefs-dump.py +++ b/nixos/modules/system/etc/build-composefs-dump.py @@ -58,7 +58,7 @@ class ComposefsPath: ): if path is None: path = attrs["target"] - self.path = "/" + path + self.path = path self.size = size self.filetype = filetype self.mode = mode @@ -87,6 +87,10 @@ def eprint(*args: Any, **kwargs: Any) -> None: print(*args, **kwargs, file=sys.stderr) +def normalize_path(path: str) -> str: + return str("/" + os.path.normpath(path).lstrip("/")) + + def leading_directories(path: str) -> list[str]: """Return the leading directories of path @@ -145,6 +149,10 @@ def main() -> None: paths: dict[str, ComposefsPath] = {} for attrs in config: + # Normalize the target path to work around issues in how targets are + # declared in `environment.etc`. + attrs["target"] = normalize_path(attrs["target"]) + target = attrs["target"] source = attrs["source"] mode = attrs["mode"] -- cgit 1.4.1