feat: initial commit with build system

This commit is contained in:
Andrew Rioux
2025-01-19 20:46:46 -05:00
parent 8c4c6674a1
commit 6b33f1a5ba
12 changed files with 277 additions and 101 deletions
+63 -40
View File
@@ -3,78 +3,101 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
libpcap-src = {
url = "git+https://github.com/the-tcpdump-group/libpcap";
flake = false;
};
libnl = {
libnl-src = {
url = "git+https://github.com/thom311/libnl";
flake = false;
};
winpcap = {
winpcap-libs = {
url = "https://www.winpcap.org/install/bin/WpdPack_4_1_2.zip";
flake = false;
};
#freebsd = {
# url =
# "https://download.freebsd.org/releases/ISO-IMAGES/14.1/FreeBSD-14.1-RELEASE-amd64-dvd1.iso";
# flake = false;
#};
winpcap-installer = {
url = "https://www.winpcap.org/install/bin/WinPcap_4_1_3.exe";
flake = false;
};
freebsd-libs-packed = {
url = "https://download.freebsd.org/releases/amd64/14.1-RELEASE/base.txz";
flake = false;
};
# command for later:
# echo '000007: 09' | xxd -r - target/x86_64-unknown-freebsd/debug/sparse-beacon
};
outputs = { self, nixpkgs, flake-utils, crane, fenix, rust-overlay
, libpcap-src, libnl, winpcap }:
flake-utils.lib.eachDefaultSystem (system:
outputs = { self, nixpkgs, flake-utils, crane, rust-overlay, libpcap-src
, libnl-src, winpcap-libs, winpcap-installer, freebsd-libs-packed }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) fenix.overlays.default ];
config.allowUnfree = true;
overlays = [ (import rust-overlay) ];
};
linuxBuildTools = with pkgs; [
autoconf
automake
bison
cmake
flex
libtool
libpcap
musl
pkg-config
];
system-libs = import ./system-libs.nix {
inherit pkgs libpcap-src winpcap-installer freebsd-libs-packed;
};
inherit (system-libs)
bsd-toolchain winpcap-drivers freebsd-libs libnl libpcap-linux
libpcap-freebsd;
windowsBuildTools = linuxBuildTools ++ (with pkgs; [
buildTools = with pkgs; [
mold
lld
zig
clang
glibc
pkgsCross.x86_64-freebsd.buildPackages.clang
pkgsCross.mingwW64.stdenv.cc
pkgsCross.mingwW64.windows.pthreads
]);
];
toolchain =
pkgs.pkgsMusl.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
devShellTools = with pkgs; [ rust-analyzer ];
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
craneLib = (crane.mkLib pkgs).overrideToolchain (p:
p.rust-bin.stable.latest.default.override {
targets = [
"x86_64-unknown-linux-gnu"
"x86_64-unknown-linux-musl"
"x86_64-pc-windows-gnu"
"x86_64-unknown-freebsd"
];
});
patch-elf = header: drv: path:
pkgs.stdenv.mkDerivation {
name = "elf-patch-${header}";
buildInputs = with pkgs; [ vim ];
};
patch-freebsd-elf = patch-elf 9;
in {
devShells.default = craneLib.devShell {
name = "sparse";
devShells = {
default = craneLib.devShell {
name = "sparse-default";
buildInputs = windowsBuildTools
++ (with pkgs; [ rust-analyzer packer ]);
packages = buildTools ++ devShellTools;
SPARSE_BUILD_WINPCAP = "${winpcap}/Lib";
SPARSE_BUILD_LIBPCAP = "${libpcap-src}";
SPARSE_BUILD_LIBNL = "${libnl}";
SPARSE_BUILD_WINPCAP_LIBS = "${winpcap-libs}/Lib";
SPARSE_BUILD_WINPCAP_DRIVERS = "${winpcap-drivers}/npf.sys";
SPARSE_BUILD_LIBPCAP = libpcap-src;
SPARSE_BUILD_LIBNL = libnl-src;
FREEBSD_LIBS = freebsd-libs;
RUSTFLAGS = "-Ctarget-feature=+crt-static";
};
};
});
}