From 95cf4c4270262249ad4d2f2ad8d1fe82ca27979d Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Wed, 25 Dec 2024 11:56:27 +0100 Subject: [PATCH] Create helper to build the ebpf programs --- dropworld/default.nix | 16 ---------------- dropworld/{dropworld.c => main.c} | 0 flake.nix | 18 +++++++++++++++--- tcpfilter/default.nix | 16 ---------------- tcpfilter/{tcpfilter.c => main.c} | 0 5 files changed, 15 insertions(+), 35 deletions(-) delete mode 100644 dropworld/default.nix rename dropworld/{dropworld.c => main.c} (100%) delete mode 100644 tcpfilter/default.nix rename tcpfilter/{tcpfilter.c => main.c} (100%) diff --git a/dropworld/default.nix b/dropworld/default.nix deleted file mode 100644 index f102fcc..0000000 --- a/dropworld/default.nix +++ /dev/null @@ -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 - ''; -} diff --git a/dropworld/dropworld.c b/dropworld/main.c similarity index 100% rename from dropworld/dropworld.c rename to dropworld/main.c diff --git a/flake.nix b/flake.nix index 3ad43a4..3b287aa 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "A very basic flake"; + description = "eBPF sandbox"; inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; @@ -9,11 +9,23 @@ outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system: let 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 { packages = { - dropworld = pkgs.callPackage ./dropworld {}; - tcpfilter = pkgs.callPackage ./tcpfilter {}; + dropworld = mkEbpfProg "dropworld" ./dropworld; + tcpfilter = mkEbpfProg "tcpfilter" ./tcpfilter; }; devShells.default = pkgs.mkShell { diff --git a/tcpfilter/default.nix b/tcpfilter/default.nix deleted file mode 100644 index 93140ea..0000000 --- a/tcpfilter/default.nix +++ /dev/null @@ -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 - ''; -} diff --git a/tcpfilter/tcpfilter.c b/tcpfilter/main.c similarity index 100% rename from tcpfilter/tcpfilter.c rename to tcpfilter/main.c