From 8aff4fee3fc075b615ec56d5b638ba74854d9abe Mon Sep 17 00:00:00 2001 From: Pim Kunis Date: Wed, 25 Dec 2024 12:02:54 +0100 Subject: [PATCH] Split flake into parts --- dev-shells.nix | 12 ++++++++++++ flake.nix | 31 ++++--------------------------- packages.nix | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 dev-shells.nix create mode 100644 packages.nix diff --git a/dev-shells.nix b/dev-shells.nix new file mode 100644 index 0000000..b7b4ca3 --- /dev/null +++ b/dev-shells.nix @@ -0,0 +1,12 @@ +{ + flake-utils, + nixpkgs, + ... +}: +flake-utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; +in { + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [bpftools bpftop]; + }; +}) diff --git a/flake.nix b/flake.nix index 3b287aa..677154c 100644 --- a/flake.nix +++ b/flake.nix @@ -6,31 +6,8 @@ flake-utils.url = "github:numtide/flake-utils"; }; - 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 = mkEbpfProg "dropworld" ./dropworld; - tcpfilter = mkEbpfProg "tcpfilter" ./tcpfilter; - }; - - devShells.default = pkgs.mkShell { - buildInputs = with pkgs; [bpftools bpftop]; - }; - } - ); + outputs = inputs @ {flake-utils, ...}: flake-utils.lib.meld inputs [ + ./dev-shells.nix + ./packages.nix + ]; } diff --git a/packages.nix b/packages.nix new file mode 100644 index 0000000..469b334 --- /dev/null +++ b/packages.nix @@ -0,0 +1,24 @@ +{ + flake-utils, + nixpkgs, + ... +}: +flake-utils.lib.eachDefaultSystem (system: let + pkgs = 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 = mkEbpfProg "dropworld" ./dropworld; + tcpfilter = mkEbpfProg "tcpfilter" ./tcpfilter; + }; +})