nixpkgs/pkgs/tools/security/swtpm/default.nix
Artturin e0464e4788 treewide: replace stdenv.is with stdenv.hostPlatform.is
In preparation for the deprecation of `stdenv.isX`.

These shorthands are not conducive to cross-compilation because they
hide the platforms.

Darwin might get cross-compilation for which the continued usage of `stdenv.isDarwin` will get in the way

One example of why this is bad and especially affects compiler packages
https://www.github.com/NixOS/nixpkgs/pull/343059

There are too many files to go through manually but a treewide should
get users thinking when they see a `hostPlatform.isX` in a place where it
doesn't make sense.

```
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv.is" "stdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenv'.is" "stdenv'.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "clangStdenv.is" "clangStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "gccStdenv.is" "gccStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "stdenvNoCC.is" "stdenvNoCC.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "inherit (stdenv) is" "inherit (stdenv.hostPlatform) is"
fd --type f "\.nix" | xargs sd --fixed-strings "buildStdenv.is" "buildStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "effectiveStdenv.is" "effectiveStdenv.hostPlatform.is"
fd --type f "\.nix" | xargs sd --fixed-strings "originalStdenv.is" "originalStdenv.hostPlatform.is"
```
2024-09-25 00:04:37 +03:00

107 lines
2.6 KiB
Nix

{ lib
, stdenv
, fetchFromGitHub
, autoreconfHook
, pkg-config
, libtasn1, openssl, fuse, glib, libseccomp, json-glib
, libtpms
, unixtools, expect, socat
, gnutls
, perl
# Tests
, python3, which
, nixosTests
}:
stdenv.mkDerivation (finalAttrs: {
pname = "swtpm";
version = "0.8.2";
src = fetchFromGitHub {
owner = "stefanberger";
repo = "swtpm";
rev = "v${finalAttrs.version}";
hash = "sha256-48/BOzGPoKr/BGEXFo3FXWr6ZoPB+ixZIvv78g6L294=";
};
nativeBuildInputs = [
pkg-config unixtools.netstat expect socat
perl # for pod2man
python3
autoreconfHook
];
nativeCheckInputs = [
which
];
buildInputs = [
libtpms
openssl libtasn1
glib json-glib
gnutls
] ++ lib.optionals stdenv.hostPlatform.isLinux [
fuse
libseccomp
];
configureFlags = [
"--localstatedir=/var"
] ++ lib.optionals stdenv.hostPlatform.isLinux [
"--with-cuse"
];
postPatch = ''
patchShebangs tests/*
# Makefile tries to create the directory /var/lib/swtpm-localca, which fails
substituteInPlace samples/Makefile.am \
--replace 'install-data-local:' 'do-not-execute:'
# Use the correct path to the certtool binary
# instead of relying on it being in the environment
substituteInPlace src/swtpm_localca/swtpm_localca.c \
--replace \
'# define CERTTOOL_NAME "gnutls-certtool"' \
'# define CERTTOOL_NAME "${gnutls}/bin/certtool"' \
--replace \
'# define CERTTOOL_NAME "certtool"' \
'# define CERTTOOL_NAME "${gnutls}/bin/certtool"'
substituteInPlace tests/common --replace \
'CERTTOOL=gnutls-certtool;;' \
'CERTTOOL=certtool;;'
# Fix error on macOS:
# stat: invalid option -- '%'
# This is caused by the stat program not being the BSD version,
# as is expected by the test
substituteInPlace tests/common --replace \
'if [[ "$(uname -s)" =~ (Linux|CYGWIN_NT-) ]]; then' \
'if [[ "$(uname -s)" =~ (Linux|Darwin|CYGWIN_NT-) ]]; then'
# Otherwise certtool seems to pick up the system language on macOS,
# which might cause a test to fail
substituteInPlace tests/test_swtpm_setup_create_cert --replace \
'$CERTTOOL' \
'LC_ALL=C.UTF-8 $CERTTOOL'
'';
doCheck = true;
enableParallelBuilding = true;
outputs = [ "out" "man" ];
passthru.tests = { inherit (nixosTests) systemd-cryptenroll; };
meta = with lib; {
description = "Libtpms-based TPM emulator";
homepage = "https://github.com/stefanberger/swtpm";
license = licenses.bsd3;
maintainers = [ maintainers.baloo ];
mainProgram = "swtpm";
platforms = platforms.all;
};
})