1 # This is a test for autoPatchelfHook. To test it, we just need a simple binary
2 # which uses the hook. We took the derivation from tonelib-jam, which sounds
3 # like a good candidate with a small closure, and trimmed it down.
12 # This test checks that the behavior of autoPatchelfHook is correct whether
14 # (https://nixos.org/manual/nix/stable/language/advanced-attributes#adv-attr-structuredAttrs)
15 # is set or not. Hence __structuredAttrs is provided as a parameter.
19 let runtimeDependencies = [
24 # A dependency with space only works with __structuredAttrs set to true.
25 ++ lib.lists.optional __structuredAttrs "/some/dep with space";
29 name = "auto-patchelf-test";
32 url = "https://tonelib.net/download/221222/ToneLib-Jam-amd64.deb";
33 sha256 = "sha256-c6At2lRPngQPpE7O+VY/Hsfw+QfIb3COIuHfbqqIEuM=";
37 dpkg -x $curSrc source
53 autoPatchelfIgnoreMissingDeps = [
58 inherit runtimeDependencies;
60 # Additional phase performing the actual test.
62 let allDeps = runtimeDependencies ++ [
67 local binary="$out/bin/ToneLib-Jam"
68 local interpreter=$(patchelf --print-interpreter $binary)
69 local runpath=$(patchelf --print-rpath $binary)
70 local glibcStorePath="${stdenv.cc.libc}"
72 # Check that the glibc path is a prefix of the interpreter. If
73 # autoPatchelfHook ran correctly, the binary should have set the interpreter
74 # to point to the store.
75 echo "[auto-patchelf-hook-test]: Check that the interpreter is in the store"
76 test "''${interpreter#$glibcStorePath}" != "$interpreter"
78 readarray -td':' runpathArray < <(echo -n "$runpath")
80 echo "[auto-patchelf-hook-test]: Check that the runpath has the right number of entries"
81 test "''${#runpathArray[@]}" -eq ${builtins.toString (builtins.length allDeps)}
83 echo "[auto-patchelf-hook-test]: Check that the runpath contains the expected runtime deps"
85 + lib.strings.concatStringsSep "\n"
88 let iAsStr = builtins.toString i; in
90 echo "[auto-patchelf-hook-test]: Check that entry ${iAsStr} is ${path}"
91 test "''${paths[${iAsStr}]}" = "$path"
96 doInstallCheck = true;
97 inherit __structuredAttrs;