nix-required-mounts: support new versions of Nix (#442389)

This commit is contained in:
Connor Baker
2025-09-16 17:47:41 +00:00
committed by GitHub
@@ -61,11 +61,19 @@ def symlink_parents(p: Path) -> List[Path]:
return out
def get_strings(drv_env: dict, name: str) -> List[str]:
def get_required_system_features(parsed_drv: dict) -> List[str]:
# Newer versions of Nix (since https://github.com/NixOS/nix/pull/13263) store structuredAttrs
# in the derivation JSON output.
if "structuredAttrs" in parsed_drv:
return parsed_drv["structuredAttrs"].get("requiredSystemFeatures", [])
# Older versions of Nix store structuredAttrs in the env as a JSON string.
drv_env = parsed_drv.get("env", {})
if "__json" in drv_env:
return list(json.loads(drv_env["__json"]).get(name, []))
else:
return drv_env.get(name, "").split()
return list(json.loads(drv_env["__json"]).get("requiredSystemFeatures", []))
# Without structuredAttrs, requiredSystemFeatures is a space-separated string in env.
return drv_env.get("requiredSystemFeatures", "").split()
def validate_mounts(pattern: Pattern) -> List[Tuple[PathString, PathString, bool]]:
@@ -140,8 +148,7 @@ def entrypoint():
)
parsed_drv = parsed_drv[canon_drv_path]
drv_env = parsed_drv.get("env", {})
required_features = get_strings(drv_env, "requiredSystemFeatures")
required_features = get_required_system_features(parsed_drv)
required_features = list(filter(known_features.__contains__, required_features))
patterns: List[Pattern] = list(