summaryrefslogtreecommitdiffstats
path: root/pkgs/test/buildFHSEnv/default.nix
blob: 4637b8ea2a220de47e3fe9591d34a2c68180fdcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{
  lib,
  buildFHSEnv,
  runCommand,
  stdenv,
  fetchurl,
  dpkg,
  glibc,
  callPackage,
}:

let
  getSharedObjectFromDebian =
    sharedObjectName: src:
    stdenv.mkDerivation {
      name = "${sharedObjectName}-fetcher";
      inherit src;
      nativeBuildInputs = [
        dpkg
      ];
      dontBuild = true;
      dontConfigure = true;
      dontFixup = true;
      installPhase = ''
        echo shared objects found are:
        ls -l usr/lib/*/
        cp usr/lib/*/${sharedObjectName} $out
      '';
    };

  makeSharedObjectTest =
    sharedObject: targetPkgs:
    let
      lddFHSEnv = buildFHSEnv {
        name = "ldd-with-ncurses-FHS-env";
        inherit targetPkgs;
        runScript = "ldd";
      };
      ldd-in-FHS = "${lddFHSEnv}/bin/${lddFHSEnv.name}";
      ldd = "${lib.getBin glibc}/bin/ldd";
      find_libFHSEnv = buildFHSEnv {
        name = "ls-with-ncurses-FHS-env";
        targetPkgs = p: [
          p.ncurses5
        ];
        runScript = "find /lib/ -executable";
      };
      find_lib-in-FHS = "${find_libFHSEnv}/bin/${find_libFHSEnv.name}";
    in
    runCommand "FHS-lib-test"
      {
        meta = {
          # Downloads an x86_64-linux only binary
          platforms = [ "x86_64-linux" ];
        };
      }
      ''
        echo original ldd output is:
        ${ldd} ${sharedObject}
        lddOutput="$(${ldd-in-FHS} ${sharedObject})"
        echo ldd output inside FHS is:
        echo "$lddOutput"
        if echo $lddOutput | grep -q "not found"; then
          echo "shared object could not find all dependencies in the FHS!"
          echo The libraries below where found in the FHS:
          ${find_lib-in-FHS}
          exit 1
        else
          echo $lddOutput > $out
        fi
      '';

in
{
  # This test proves an issue with buildFHSEnv - don't expect it to succeed,
  # this is discussed in https://github.com/NixOS/nixpkgs/pull/279844 .
  libtinfo =
    makeSharedObjectTest
      (getSharedObjectFromDebian "libedit.so.2.0.70" (fetchurl {
        url = "mirror://debian/pool/main/libe/libedit/libedit2_3.1-20221030-2_amd64.deb";
        hash = "sha256-HPFKvycW0yedsS0GV6VzfPcAdKHnHTvfcyBmJePInOY=";
      }))
      (p: [
        p.libtinfo
        p.libbsd
      ]);

  liblzma =
    makeSharedObjectTest
      (getSharedObjectFromDebian "libxml2.so.2.9.14" (fetchurl {
        url = "mirror://debian/pool/main/libx/libxml2/libxml2_2.9.14+dfsg-1.3~deb12u1_amd64.deb";
        hash = "sha256-NbdstwOPwclAIEpPBfM/+3nQJzU85Gk5fZrc+Pmz4ac=";
      }))
      (p: [
        p.xz
        p.zlib
        p.icu72
      ]);
}