nix-required-mounts: restore (optional) symlink support
This commit is contained in:
@@ -26,11 +26,13 @@ in
|
||||
guest = "/run/opengl-driver/lib";
|
||||
}
|
||||
];
|
||||
unsafeFollowSymlinks = true;
|
||||
};
|
||||
users.users.person.isNormalUser = true;
|
||||
systemd.tmpfiles.rules = [
|
||||
"d /supported-feature-files 0755 person users -"
|
||||
"f /usr/lib/imaginary-fhs-drivers/libcuda.so 0444 root root -"
|
||||
"f /usr/lib/libcuda.so 0444 root root - fakeContent"
|
||||
"L /usr/lib/imaginary-fhs-drivers/libcuda.so 0444 root root - /usr/lib/libcuda.so"
|
||||
];
|
||||
};
|
||||
testScript = ''
|
||||
|
||||
@@ -8,9 +8,19 @@ pkgs.runCommandNoCC "${feature}-present"
|
||||
echo "The host declares ${feature} support, but doesn't expose /${feature}-files" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -f /run/opengl-driver/lib/libcuda.so ]] ; then
|
||||
libcudaLocation=/run/opengl-driver/lib/libcuda.so
|
||||
if [[ -e "$libcudaLocation" || -h "$libcudaLocation" ]] ; then
|
||||
true # we're good
|
||||
else
|
||||
echo "The host declares ${feature} support, but it the hook fails to handle the hostPath != guestPath cases" >&2
|
||||
exit 1
|
||||
fi
|
||||
if cat "$libcudaLocation" | xargs test fakeContent = ; then
|
||||
true # we're good
|
||||
else
|
||||
echo "The host declares ${feature} support, but it seems to fail to follow symlinks" >&2
|
||||
echo "The content of /run/opengl-driver/lib/libcuda.so is: $(cat /run/opengl-driver/lib/libcuda.so)" >&2
|
||||
exit 1
|
||||
fi
|
||||
touch $out
|
||||
''
|
||||
|
||||
@@ -143,17 +143,24 @@ def entrypoint():
|
||||
mounts: List[Tuple[PathString, PathString]] = []
|
||||
|
||||
while queue:
|
||||
guest_path, host_path, follow_symlinks = queue.popleft()
|
||||
if (guest_path, host_path) not in unique_mounts:
|
||||
mounts.append((guest_path, host_path))
|
||||
unique_mounts.add((guest_path, host_path))
|
||||
guest_path_str, host_path_str, follow_symlinks = queue.popleft()
|
||||
if (guest_path_str, host_path_str) not in unique_mounts:
|
||||
mounts.append((guest_path_str, host_path_str))
|
||||
unique_mounts.add((guest_path_str, host_path_str))
|
||||
|
||||
if not follow_symlinks:
|
||||
continue
|
||||
|
||||
for parent in symlink_parents(Path(host_path)):
|
||||
parent_str = parent.absolute().as_posix()
|
||||
queue.append((parent_str, parent_str, follow_symlinks))
|
||||
host_path = Path(host_path_str)
|
||||
if not (host_path.is_dir() or host_path.is_symlink()):
|
||||
continue
|
||||
|
||||
# assert host_path_str == guest_path_str, (host_path_str, guest_path_str)
|
||||
|
||||
for child in host_path.iterdir() if host_path.is_dir() else [host_path]:
|
||||
for parent in symlink_parents(child):
|
||||
parent_str = parent.absolute().as_posix()
|
||||
queue.append((parent_str, parent_str, follow_symlinks))
|
||||
|
||||
# the pre-build-hook command
|
||||
if args.issue_command == "always" or (
|
||||
@@ -165,8 +172,8 @@ def entrypoint():
|
||||
print_paths = False
|
||||
|
||||
# arguments, one per line
|
||||
for guest_path, host_path in mounts if print_paths else []:
|
||||
print(f"{guest_path}={host_path}")
|
||||
for guest_path_str, host_path_str in mounts if print_paths else []:
|
||||
print(f"{guest_path_str}={host_path_str}")
|
||||
|
||||
# terminated by an empty line
|
||||
something_to_terminate = args.issue_stop == "conditional" and mounts
|
||||
|
||||
Reference in New Issue
Block a user