nixpkgs/pkgs/os-specific/linux/opensnitch-ebpf/default.nix
Yueh-Shun Li 91b3db1309 treewide: fix sourceRoot for fetchgit-based src
According to Nixpkgs manual[1] and NixOS 23.11 Release Note[2], the
`sourceRoot` attribute passed to `stdenv.mkDerivation` should be
specified as `"${src.name}"` or `"${src.name}/subdir"` when `src` is
produced using `fetchgit`-based fetchers.

`sourceRoot = "source"` or `sourceRoot = "source/subdir"` is based on
the assumption that the `name` attribute of these pre-unpacked fetchers
are always `"source"`, which is not the case. Expecting constant `name`
also makes the source FODs prone to irrelevent hashes during version
bumps.

[1]: https://nixos.org/manual/nixpkgs/unstable/#var-stdenv-sourceRoot
[2]: https://nixos.org/manual/nixos/stable/release-notes#sec-release-23.11
2024-03-09 07:53:25 +08:00

59 lines
1.3 KiB
Nix

{ lib
, kernel
, stdenv
, clang-tools
, llvmPackages
, elfutils
, flex
, bison
, bc
, opensnitch
}:
stdenv.mkDerivation rec {
pname = "opensnitch_ebpf";
version = "${opensnitch.version}-${kernel.version}";
inherit (opensnitch) src;
sourceRoot = "${src.name}/ebpf_prog";
nativeBuildInputs = with llvmPackages; [
bc
bison
clang
clang-tools
elfutils
flex
libllvm
];
# We set -fno-stack-protector here to work around a clang regression.
# This is fine - bpf programs do not use stack protectors
# https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=opensnitch-ebpf-module&id=984b952a784eb701f691dd9f2d45dfeb8d15053b
env.NIX_CFLAGS_COMPILE = "-fno-stack-protector";
env.KERNEL_DIR="${kernel.dev}/lib/modules/${kernel.modDirVersion}/source";
env.KERNEL_HEADERS="${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
extraConfig =''
CONFIG_UPROBE_EVENTS=y
'';
installPhase = ''
runHook preInstall
for file in opensnitch*.o; do
install -Dm644 "$file" "$out/etc/opensnitchd/$file"
done
runHook postInstall
'';
meta = with lib; {
description = "eBPF process monitor module for OpenSnitch";
homepage = "https://github.com/evilsocket/opensnitch";
license = licenses.gpl3Only;
maintainers = with maintainers; [ onny ];
platforms = platforms.linux;
};
}