teamspeak5_client: 5.0.0-beta77 -> 6.0.0-beta2; teamspeak refactors (#377748)
[NixPkgs.git] / pkgs / development / libraries / tpm2-tss / default.nix
blobb8b68919c807e291ea3debe1fdf7cbdfe4ac62ea
2   stdenv,
3   lib,
4   fetchFromGitHub,
5   autoreconfHook,
6   autoconf-archive,
7   pkg-config,
8   doxygen,
9   perl,
10   openssl,
11   json_c,
12   curl,
13   libgcrypt,
14   cmocka,
15   uthash,
16   swtpm,
17   iproute2,
18   procps,
19   which,
20   libuuid,
21   libtpms,
23 let
24   # Avoid a circular dependency on Linux systems (systemd depends on tpm2-tss,
25   # tpm2-tss tests depend on procps, procps depends on systemd by default). This
26   # needs to be conditional based on isLinux because procps for other systems
27   # might not support the withSystemd option.
28   procpsWithoutSystemd = procps.override { withSystemd = false; };
29   procps_pkg = if stdenv.hostPlatform.isLinux then procpsWithoutSystemd else procps;
32 stdenv.mkDerivation rec {
33   pname = "tpm2-tss";
34   version = "4.1.3";
36   src = fetchFromGitHub {
37     owner = "tpm2-software";
38     repo = pname;
39     rev = version;
40     hash = "sha256-BP28utEUI9g1VNv3lCXuiKrDtEImFQxxZfIjLiE3Wr8=";
41   };
43   outputs = [
44     "out"
45     "man"
46     "dev"
47   ];
49   nativeBuildInputs = [
50     autoreconfHook
51     autoconf-archive
52     pkg-config
53     doxygen
54     perl
55   ];
57   buildInputs =
58     [
59       openssl
60       json_c
61       curl
62       libgcrypt
63       uthash
64       libuuid
65       libtpms
66     ]
67     # cmocka is checked in the configure script
68     # when unit and/or integration testing is enabled
69     # cmocka doesn't build with pkgsStatic, and we don't need it anyway
70     # when tests are not run
71     ++ lib.optional doInstallCheck cmocka;
73   nativeInstallCheckInputs = lib.optionals doInstallCheck [
74     cmocka
75     which
76     openssl
77     procps_pkg
78     iproute2
79     swtpm
80   ];
82   strictDeps = true;
83   preAutoreconf = "./bootstrap";
85   enableParallelBuilding = true;
87   patches = [
88     # Do not rely on dynamic loader path
89     # TCTI loader relies on dlopen(), this patch prefixes all calls with the output directory
90     ./no-dynamic-loader-path.patch
92     # Configure script expects tools from shadow (e.g. useradd) but they are
93     # actually optional (and we can’t use them in Nix sandbox anyway). Make the
94     # check in configure.ac a warning instead of an error so that we can run
95     # configure phase on platforms that don’t have shadow package (e.g. macOS).
96     # Note that *on platforms* does not mean *for platform* i.e. this is for
97     # cross-compilation, tpm2-tss does not support macOS, see upstream issue:
98     # https://github.com/tpm2-software/tpm2-tss/issues/2629
99     # See also
100     # https://github.com/tpm2-software/tpm2-tss/blob/6c46325b466f35d40c2ed1043bfdfcfb8a367a34/Makefile.am#L880-L898
101     ./no-shadow.patch
102   ];
104   postPatch =
105     ''
106       patchShebangs script
107       substituteInPlace src/tss2-tcti/tctildr-dl.c \
108         --replace-fail '@PREFIX@' $out/lib/
109       substituteInPlace ./test/unit/tctildr-dl.c \
110         --replace-fail '@PREFIX@' $out/lib/
111       substituteInPlace ./bootstrap \
112         --replace-fail 'git describe --tags --always --dirty' 'echo "${version}"'
113       for src in src/tss2-tcti/tcti-libtpms.c test/unit/tcti-libtpms.c; do
114         substituteInPlace "$src" \
115           --replace-fail '"libtpms.so"' '"${libtpms.out}/lib/libtpms.so"' \
116           --replace-fail '"libtpms.so.0"' '"${libtpms.out}/lib/libtpms.so.0"'
117       done
118     ''
119     # tcti tests rely on mocking function calls, which appears not to be supported
120     # on clang
121     + lib.optionalString stdenv.cc.isClang ''
122       sed -i '/TESTS_UNIT / {
123         /test\/unit\/tcti-swtpm/d;
124         /test\/unit\/tcti-mssim/d;
125         /test\/unit\/tcti-device/d
126       }' Makefile-test.am
127     '';
129   configureFlags =
130     lib.optionals doInstallCheck [
131       "--enable-unit"
132       "--enable-integration"
133     ]
134     ++ lib.optionals stdenv.hostPlatform.isDarwin [
135       # sys/prctl.h required
136       "--disable-tcti-cmd"
137       # uchar.h required
138       "--disable-fapi"
139       "--disable-policy"
140     ];
142   postInstall = ''
143     # Do not install the upstream udev rules, they rely on specific
144     # users/groups which aren't guaranteed to exist on the system.
145     rm -R $out/lib/udev
146   '';
148   doCheck = false;
149   doInstallCheck =
150     stdenv.buildPlatform.canExecute stdenv.hostPlatform
151     && !stdenv.hostPlatform.isDarwin
152     # Tests rely on mocking, which can't work with static libs.
153     && !stdenv.hostPlatform.isStatic;
154   # Since we rewrote the load path in the dynamic loader for the TCTI
155   # The various tcti implementation should be placed in their target directory
156   # before we could run tests, so we make turn checkPhase into installCheckPhase
157   installCheckTarget = "check";
159   meta = with lib; {
160     description = "OSS implementation of the TCG TPM2 Software Stack (TSS2)";
161     homepage = "https://github.com/tpm2-software/tpm2-tss";
162     license = licenses.bsd2;
163     platforms = platforms.unix;
164     maintainers = with maintainers; [ baloo ];
165   };