Create helper to build the ebpf programs
This commit is contained in:
parent
6e8387a0a4
commit
95cf4c4270
5 changed files with 15 additions and 35 deletions
|
@ -1,16 +0,0 @@
|
||||||
{clangStdenv, libbpf, ...}: clangStdenv.mkDerivation {
|
|
||||||
name = "dropworld";
|
|
||||||
src = ./.;
|
|
||||||
hardeningDisable = [ "stackprotector" "zerocallusedregs" ];
|
|
||||||
dontFixup = true;
|
|
||||||
buildInputs = [ libbpf ];
|
|
||||||
|
|
||||||
buildPhase = ''
|
|
||||||
clang -O2 -target bpf -g -c dropworld.c -o dropworld.o
|
|
||||||
'';
|
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
mkdir $out
|
|
||||||
cp dropworld.o $out
|
|
||||||
'';
|
|
||||||
}
|
|
18
flake.nix
18
flake.nix
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
description = "A very basic flake";
|
description = "eBPF sandbox";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
|
||||||
|
@ -9,11 +9,23 @@
|
||||||
outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system:
|
outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = inputs.nixpkgs.legacyPackages.${system};
|
pkgs = inputs.nixpkgs.legacyPackages.${system};
|
||||||
|
|
||||||
|
mkEbpfProg = name: src: pkgs.clangStdenv.mkDerivation {
|
||||||
|
name = "ebpf-${name}";
|
||||||
|
inherit src;
|
||||||
|
hardeningDisable = [ "stackprotector" "zerocallusedregs" ];
|
||||||
|
dontFixup = true;
|
||||||
|
buildInputs = with pkgs; [ libbpf ];
|
||||||
|
|
||||||
|
buildPhase = ''
|
||||||
|
clang -O2 -target bpf -g -c ${src}/main.c -o $out
|
||||||
|
'';
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages = {
|
packages = {
|
||||||
dropworld = pkgs.callPackage ./dropworld {};
|
dropworld = mkEbpfProg "dropworld" ./dropworld;
|
||||||
tcpfilter = pkgs.callPackage ./tcpfilter {};
|
tcpfilter = mkEbpfProg "tcpfilter" ./tcpfilter;
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells.default = pkgs.mkShell {
|
devShells.default = pkgs.mkShell {
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
{clangStdenv, libbpf, ...}: clangStdenv.mkDerivation {
|
|
||||||
name = "tcpfilter";
|
|
||||||
src = ./.;
|
|
||||||
hardeningDisable = [ "stackprotector" "zerocallusedregs" ];
|
|
||||||
dontFixup = true;
|
|
||||||
buildInputs = [ libbpf ];
|
|
||||||
|
|
||||||
buildPhase = ''
|
|
||||||
clang -O2 -target bpf -g -c tcpfilter.c -o tcpfilter.o
|
|
||||||
'';
|
|
||||||
|
|
||||||
installPhase = ''
|
|
||||||
mkdir $out
|
|
||||||
cp tcpfilter.o $out
|
|
||||||
'';
|
|
||||||
}
|
|
Loading…
Reference in a new issue