1 { stdenv, lib, fetchFromGitHub
2 , autoreconfHook, autoconf-archive, pkg-config, doxygen, perl
3 , openssl, json_c, curl, libgcrypt
4 , cmocka, uthash, swtpm, iproute2, procps, which
8 # Avoid a circular dependency on Linux systems (systemd depends on tpm2-tss,
9 # tpm2-tss tests depend on procps, procps depends on systemd by default). This
10 # needs to be conditional based on isLinux because procps for other systems
11 # might not support the withSystemd option.
12 procpsWithoutSystemd = procps.override { withSystemd = false; };
13 procps_pkg = if stdenv.hostPlatform.isLinux then procpsWithoutSystemd else procps;
16 stdenv.mkDerivation rec {
20 src = fetchFromGitHub {
21 owner = "tpm2-software";
24 hash = "sha256-BP28utEUI9g1VNv3lCXuiKrDtEImFQxxZfIjLiE3Wr8=";
27 outputs = [ "out" "man" "dev" ];
30 autoreconfHook autoconf-archive pkg-config doxygen perl
34 openssl json_c curl libgcrypt uthash libuuid
36 # cmocka is checked in the configure script
37 # when unit and/or integration testing is enabled
38 # cmocka doesn't build with pkgsStatic, and we don't need it anyway
39 # when tests are not run
40 ++ lib.optional doInstallCheck cmocka;
42 nativeInstallCheckInputs = [
43 cmocka which openssl procps_pkg iproute2 swtpm
47 preAutoreconf = "./bootstrap";
49 enableParallelBuilding = true;
52 # Do not rely on dynamic loader path
53 # TCTI loader relies on dlopen(), this patch prefixes all calls with the output directory
54 ./no-dynamic-loader-path.patch
56 # Configure script expects tools from shadow (e.g. useradd) but they are
57 # actually optional (and we can’t use them in Nix sandbox anyway). Make the
58 # check in configure.ac a warning instead of an error so that we can run
59 # configure phase on platforms that don’t have shadow package (e.g. macOS).
60 # Note that *on platforms* does not mean *for platform* i.e. this is for
61 # cross-compilation, tpm2-tss does not support macOS, see upstream issue:
62 # https://github.com/tpm2-software/tpm2-tss/issues/2629
64 # https://github.com/tpm2-software/tpm2-tss/blob/6c46325b466f35d40c2ed1043bfdfcfb8a367a34/Makefile.am#L880-L898
70 substituteInPlace src/tss2-tcti/tctildr-dl.c \
71 --replace '@PREFIX@' $out/lib/
72 substituteInPlace ./test/unit/tctildr-dl.c \
73 --replace '@PREFIX@' $out/lib/
74 substituteInPlace ./bootstrap \
75 --replace 'git describe --tags --always --dirty' 'echo "${version}"'
78 configureFlags = lib.optionals doInstallCheck [
80 "--enable-integration"
84 # Do not install the upstream udev rules, they rely on specific
85 # users/groups which aren't guaranteed to exist on the system.
90 doInstallCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
91 # Since we rewrote the load path in the dynamic loader for the TCTI
92 # The various tcti implementation should be placed in their target directory
93 # before we could run tests, so we make turn checkPhase into installCheckPhase
94 installCheckTarget = "check";
97 description = "OSS implementation of the TCG TPM2 Software Stack (TSS2)";
98 homepage = "https://github.com/tpm2-software/tpm2-tss";
99 license = licenses.bsd2;
100 platforms = platforms.linux;
101 maintainers = with maintainers; [ baloo ];