summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ef/efitools/package.nix
blob: f3cc209c7d1fa014e5dbd4148de62595e154068a (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
{
  lib,
  stdenv,
  gnu-efi,
  openssl,
  sbsigntool,
  perl,
  perlPackages,
  help2man,
  fetchzip,
  pkgsCross,
  efitools,
  buildPackages,
}:
let
  isCross = !(stdenv.buildPlatform.canExecute stdenv.hostPlatform);
in
stdenv.mkDerivation (finalAttrs: {
  pname = "efitools";
  version = "1.9.2";

  buildInputs = [
    gnu-efi
    openssl
  ];

  nativeBuildInputs = [
    perl
    perlPackages.FileSlurp
    help2man
    openssl
    sbsigntool
  ]
  ++ lib.optionals isCross [
    efitools
  ];

  src = fetchzip {
    url = "https://git.kernel.org/pub/scm/linux/kernel/git/jejb/efitools.git/snapshot/efitools-v${finalAttrs.version}.tar.gz";
    sha256 = "0jabgl2pxvfl780yvghq131ylpf82k7banjz0ksjhlm66ik8gb1i";
  };

  patches = [
    # https://github.com/ncroxon/gnu-efi/issues/7#issuecomment-2122741592
    ./aarch64.patch

    # Fix build with gcc15
    ./remove-redundant-bool.patch

    # https://bugs.debian.org/1122408
    ./objcopy-output-target.patch
  ]
  ++ lib.optionals isCross [
    # Use builder's efitools to create sig lists for host
    ./cross.patch
  ];

  postPatch = ''
    sed -i -e 's#/usr/include/efi#${gnu-efi}/include/efi/#g' Make.rules
    sed -i -e 's#/usr/lib64/gnuefi#${gnu-efi}/lib/#g' Make.rules
    sed -i -e 's#$(DESTDIR)/usr#$(out)#g' Make.rules
    sed -i '$asign-efi-sig-list.o flash-var.o: CFLAGS += -D_GNU_SOURCE' Makefile
    substituteInPlace lib/console.c --replace "EFI_WARN_UNKOWN_GLYPH" "EFI_WARN_UNKNOWN_GLYPH"
    # Fix cross-compilation: use $(AR) and $(NM) variables instead of hardcoded commands
    substituteInPlace Make.rules --replace-fail 'ar rcv' '$(AR) rcv'
    substituteInPlace Make.rules --replace-fail 'nm -D' '$(NM) -D'
    patchShebangs .
  '';

  makeFlags = [
    "ARCH=${stdenv.hostPlatform.parsed.cpu.name}"
    "AR=${stdenv.cc.targetPrefix}ar"
    "NM=${stdenv.cc.targetPrefix}nm"
    "OBJCOPY=${stdenv.cc.targetPrefix}objcopy"
  ]
  ++ lib.optionals isCross [
    "MANPAGES="
  ];

  passthru.tests = {
    cross-aarch64 = pkgsCross.aarch64-multiplatform.efitools;
  };

  meta = {
    description = "Tools for manipulating UEFI secure boot platforms";
    homepage = "https://git.kernel.org/pub/scm/linux/kernel/git/jejb/efitools.git";
    license = lib.licenses.gpl2Only;
    platforms = lib.platforms.linux;
  };
})