summaryrefslogtreecommitdiffstats
path: root/pkgs/tools/security/ghidra/with-extensions.nix
blob: 5f7f035d9fa6700d38ef076351233835fc67ee5f (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
{
  lib,
  stdenv,
  callPackage,
  symlinkJoin,
  makeBinaryWrapper,
  desktopToDarwinBundle,
  ghidra,
}:

let
  ghidra-extensions = callPackage ./extensions.nix { inherit ghidra; };
  allExtensions = lib.filterAttrs (n: pkg: lib.isDerivation pkg) ghidra-extensions;

  /*
    Make Ghidra with additional extensions
    Example:
      pkgs.ghidra.withExtensions (p: with p; [
        ghostrings
      ]);
      => /nix/store/3yn0rbnz5mbrxf0x70jbjq73wgkszr5c-ghidra-with-extensions-10.2.2
  */
  withExtensions =
    f:
    (symlinkJoin {
      name = "${ghidra.pname}-with-extensions-${lib.getVersion ghidra}";
      paths = (f allExtensions);
      nativeBuildInputs = [
        makeBinaryWrapper
      ]
      ++ lib.optional stdenv.hostPlatform.isDarwin desktopToDarwinBundle;
      postBuild = ''
        # Prevent attempted creation of plugin lock files in the Nix store.
        touch $out/lib/ghidra/Ghidra/.dbDirLock

        makeWrapper '${ghidra}/bin/ghidra' "$out/bin/ghidra" \
          --set NIX_GHIDRAHOME "$out/lib/ghidra/Ghidra"
        makeWrapper '${ghidra}/bin/ghidra-analyzeHeadless' "$out/bin/ghidra-analyzeHeadless" \
          --set NIX_GHIDRAHOME "$out/lib/ghidra/Ghidra"
        ln -s ${ghidra}/share $out/share
      ''
      + lib.optionalString stdenv.hostPlatform.isDarwin ''
        convertDesktopFiles $prefix
      '';
      inherit (ghidra) meta;
    });
in
withExtensions