about summary refs log tree commit diff
path: root/pkgs/tools/system/osquery/toolchain-bin.nix
blob: dd1ff9264d3c0877d124d18f2bd2ed7cdb474a3d (plain) (blame)
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
{ stdenv, lib, fetchzip, file }:
let

  version = "1.1.0";

  dist = {
    "x86_64-linux" = {
      url = "https://github.com/osquery/osquery-toolchain/releases/download/${version}/osquery-toolchain-${version}-x86_64.tar.xz";
      hash = "sha256-irekR8a0d+T64+ZObgblsLoc4kVBmb6Gv0Qf8dLDCMk=";
    };
    "aarch64-linux" = {
      url = "https://github.com/osquery/osquery-toolchain/releases/download/${version}/osquery-toolchain-${version}-aarch64.tar.xz";
      hash = "sha256-cQlx9AtO6ggIQqHowa+42wQ4YCMCN4Gb+0qqVl2JElw=";
    };
  };

in

stdenv.mkDerivation {

  name = "osquery-toolchain-bin";

  inherit version;

  src = fetchzip dist.${stdenv.hostPlatform.system};

  nativeBuildInputs = [ file ];

  installPhase = ''
    mkdir $out
    cp -r * $out
  '';

  # autoPatchelfHook cannot be used here because of https://github.com/NixOS/nixpkgs/issues/333710
  postFixup = ''
    read -r interpreter < "$NIX_BINTOOLS"/nix-support/dynamic-linker
    for file in $(find "$out"/usr/bin -type f -executable); do
      if [[ $(file "$file") == *ELF*dynamically* ]]; then
        patchelf --interpreter "$interpreter" "$file"
        patchelf --set-rpath "$out/usr/lib" "$file"
      fi
    done
  '';

  meta = with lib; {
    description = "A LLVM-based toolchain for Linux designed to build a portable osquery";
    homepage = "https://github.com/osquery/osquery-toolchain";
    platforms = [ "x86_64-linux" "aarch64-linux" ];
    sourceProvenance = with sourceTypes; [ binaryNativeCode ];
    license = with licenses; [ gpl2Only asl20 ];
    maintainers = with maintainers; [ squalus ];
  };
}