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.
13 # This test checks that the behavior of autoPatchelfHook is correct whether
15 # (https://nixos.org/manual/nix/stable/language/advanced-attributes#adv-attr-structuredAttrs)
16 # is set or not. Hence __structuredAttrs is provided as a parameter.
27 # A dependency with space only works with __structuredAttrs set to true.
28 ++ lib.lists.optional __structuredAttrs "/some/dep with space";
32 name = "auto-patchelf-test";
35 url = "https://tonelib.net/download/221222/ToneLib-Jam-amd64.deb";
36 sha256 = "sha256-c6At2lRPngQPpE7O+VY/Hsfw+QfIb3COIuHfbqqIEuM=";
40 dpkg -x $curSrc source
56 autoPatchelfIgnoreMissingDeps = [
61 inherit runtimeDependencies;
63 # Additional phase performing the actual test.
66 allDeps = runtimeDependencies ++ [
71 local binary="$out/bin/ToneLib-Jam"
72 local interpreter=$(patchelf --print-interpreter $binary)
73 local runpath=$(patchelf --print-rpath $binary)
74 local glibcStorePath="${stdenv.cc.libc}"
76 # Check that the glibc path is a prefix of the interpreter. If
77 # autoPatchelfHook ran correctly, the binary should have set the interpreter
78 # to point to the store.
79 echo "[auto-patchelf-hook-test]: Check that the interpreter is in the store"
80 test "''${interpreter#$glibcStorePath}" != "$interpreter"
82 readarray -td':' runpathArray < <(echo -n "$runpath")
84 echo "[auto-patchelf-hook-test]: Check that the runpath has the right number of entries"
85 test "''${#runpathArray[@]}" -eq ${builtins.toString (builtins.length allDeps)}
87 echo "[auto-patchelf-hook-test]: Check that the runpath contains the expected runtime deps"
89 + lib.strings.concatStringsSep "\n" (
93 iAsStr = builtins.toString i;
96 echo "[auto-patchelf-hook-test]: Check that entry ${iAsStr} is ${path}"
97 test "''${paths[${iAsStr}]}" = "$path"
102 doInstallCheck = true;
103 inherit __structuredAttrs;