sparse-v2/flake.nix
2025-01-20 14:40:29 -05:00

106 lines
3.0 KiB
Nix

{
description = "Sparse C2 framework";
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";
libpcap-src = {
url = "git+https://github.com/the-tcpdump-group/libpcap";
flake = false;
};
libnl-src = {
url = "git+https://github.com/thom311/libnl";
flake = false;
};
winpcap-libs = {
url = "https://www.winpcap.org/install/bin/WpdPack_4_1_2.zip";
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, 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) ];
};
system-libs = import ./system-libs.nix {
inherit pkgs libnl-src libpcap-src winpcap-installer
freebsd-libs-packed;
};
inherit (system-libs)
bsd-toolchain winpcap-drivers freebsd-libs libnl libpcap-linux
libpcap-freebsd;
buildTools = with pkgs; [
mold
lld
zig
clang
glibc
pkgsCross.x86_64-freebsd.buildPackages.clang
pkgsCross.mingwW64.stdenv.cc
pkgsCross.mingwW64.windows.pthreads
];
devShellTools = with pkgs; [ rust-analyzer ];
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-default";
packages = buildTools ++ devShellTools;
SPARSE_BUILD_WINPCAP_LIBS = "${winpcap-libs}/Lib";
SPARSE_BUILD_WINPCAP_DRIVERS = "${winpcap-drivers}/npf.sys";
SPARSE_BUILD_LIBPCAP_LINUX = libpcap-linux;
SPARSE_BUILD_LIBPCAP_FREEBSD = libpcap-freebsd;
SPARSE_BUILD_LIBNL = libnl;
FREEBSD_LIBS = freebsd-libs;
RUSTFLAGS = "-Ctarget-feature=+crt-static";
};
};
});
}