216 lines
6.8 KiB
Nix
216 lines
6.8 KiB
Nix
{
|
|
description = "Sparse C2 framework";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
|
|
|
rust-overlay = {
|
|
url = "github:oxalica/rust-overlay";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
crane.url = "github:ipetkov/crane";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
advisory-db = {
|
|
url = "github:rustsec/advisory-db";
|
|
flake = false;
|
|
};
|
|
|
|
libcap-src = {
|
|
url = "git+https://git.kernel.org/pub/scm/libs/libcap/libcap.git";
|
|
flake = false;
|
|
};
|
|
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;
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils, crane, rust-overlay, advisory-db
|
|
, libcap-src, 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 libcap-src libpcap-src winpcap-installer
|
|
freebsd-libs-packed;
|
|
};
|
|
inherit (system-libs)
|
|
freebsd-toolchain winpcap-drivers freebsd-libs libnl libcap
|
|
libpcap-linux-gnu libpcap-linux-musl libpcap-freebsd;
|
|
|
|
buildTools = with pkgs; rec {
|
|
base = [
|
|
# Tools for local compilation
|
|
lld
|
|
zig
|
|
clang
|
|
libclang
|
|
mold
|
|
|
|
# Tools for building the web UI
|
|
cargo-leptos
|
|
wasm-bindgen-cli
|
|
dart-sass
|
|
binaryen
|
|
sqlx-cli
|
|
];
|
|
linux = buildTools.base ++ [ glibc ];
|
|
freebsd = buildTools.base
|
|
++ [ pkgsCross.x86_64-freebsd.buildPackages.clang ];
|
|
windows = buildTools.base ++ [
|
|
pkgsCross.mingwW64.stdenv.cc
|
|
pkgsCross.mingwW64.windows.pthreads
|
|
];
|
|
|
|
all = buildTools.linux ++ buildTools.freebsd ++ buildTools.windows;
|
|
};
|
|
|
|
devShellTools = with pkgs; [
|
|
# Language servers
|
|
rust-analyzer
|
|
zls
|
|
|
|
# Debuggers
|
|
gdb
|
|
pwndbg
|
|
gdbgui
|
|
|
|
# Cargo lint tools
|
|
taplo
|
|
cargo-deny
|
|
|
|
# Docs
|
|
man-pages
|
|
man-pages-posix
|
|
];
|
|
|
|
craneLib = (crane.mkLib pkgs).overrideToolchain (p:
|
|
p.rust-bin.nightly.latest.default.override {
|
|
extensions = [ "rust-src" ];
|
|
targets = [
|
|
"x86_64-unknown-linux-gnu"
|
|
"x86_64-unknown-linux-musl"
|
|
"x86_64-pc-windows-gnu"
|
|
"x86_64-unknown-freebsd"
|
|
"wasm32-unknown-unknown"
|
|
];
|
|
});
|
|
|
|
buildEnvironment = {
|
|
SPARSE_BUILD_WINPCAP_LINK_INFO = "${winpcap-libs}/Lib";
|
|
SPARSE_BUILD_WINPCAP_DRIVERS = "${winpcap-drivers}";
|
|
SPARSE_BUILD_LIBPCAP_LINUX_GNU = libpcap-linux-gnu;
|
|
SPARSE_BUILD_LIBPCAP_LINUX_MUSL = libpcap-linux-musl;
|
|
SPARSE_BUILD_LIBPCAP_FREEBSD = libpcap-freebsd;
|
|
SPARSE_BUILD_LIBNL = libnl;
|
|
SPARSE_BUILD_LIBCAP = libcap;
|
|
|
|
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
|
|
|
|
FREEBSD_LIBS = freebsd-libs;
|
|
GLIBC_LIBS = pkgs.glibc;
|
|
GLIBC_LIBS_STATIC = pkgs.glibc.static;
|
|
};
|
|
|
|
outputs = import ./packages.nix ({
|
|
inherit pkgs buildTools buildEnvironment craneLib advisory-db
|
|
winpcap-libs;
|
|
} // system-libs);
|
|
|
|
setup-zig-freebsd = pkgs.writeScriptBin "setup-zig-freebsd" ''
|
|
set -eux
|
|
|
|
cp ${outputs.packages.freebsd-zig-libc} $(${pkgs.git}/bin/git rev-parse --show-toplevel)/unix-loader/freebsd.txt
|
|
'';
|
|
|
|
setup-dev-environment = pkgs.writeScriptBin "setup-dev-environment" ''
|
|
set -eux
|
|
|
|
${setup-zig-freebsd}/bin/setup-zig-freebsd
|
|
|
|
mkdir -p target/x86_64-{unknown-{linux-musl,freebsd},pc-windows-gnu}/debug
|
|
touch target/x86_64-unknown-{linux-musl,freebsd}/debug/sparse-unix-{beacon,installer}
|
|
touch target/x86_64-pc-windows-gnu/debug/sparse{-windows-installer.exe,_windows_beacon.dll}
|
|
'';
|
|
in {
|
|
packages = outputs.packages;
|
|
checks = outputs.checks;
|
|
|
|
devShells = {
|
|
default = craneLib.devShell (buildEnvironment // {
|
|
name = "sparse-default";
|
|
|
|
packages = buildTools.linux ++ devShellTools
|
|
++ [ setup-zig-freebsd setup-dev-environment ];
|
|
|
|
# Added to make development easier
|
|
SPARSE_INSTALLER_LINUX =
|
|
"../../target/x86_64-unknown-linux-musl/debug/sparse-unix-installer";
|
|
SPARSE_INSTALLER_FREEBSD =
|
|
"../../target/x86_64-unknown-freebsd/debug/sparse-unix-installer";
|
|
SPARSE_INSTALLER_WINDOWS =
|
|
"../../target/x86_64-pc-windows-gnu/debug/sparse-windows-installer.exe";
|
|
|
|
SPARSE_BEACON_LINUX =
|
|
"../../target/x86_64-unknown-linux-musl/debug/sparse-unix-beacon";
|
|
SPARSE_BEACON_FREEBSD =
|
|
"../../target/x86_64-unknown-freebsd/debug/sparse-unix-beacon";
|
|
SPARSE_BEACON_WINDOWS =
|
|
"../../../target/x86_64-pc-windows-gnu/debug/sparse-windows-beacon.dll";
|
|
|
|
shellHook = ''
|
|
export DATABASE_URL="sqlite://$(${pkgs.git}/bin/git rev-parse --show-toplevel)/sparse-server/db.sqlite"
|
|
'';
|
|
});
|
|
|
|
linux = craneLib.devShell (buildEnvironment // {
|
|
name = "sparse-linux";
|
|
|
|
packages = buildTools.linux ++ devShellTools
|
|
++ [ setup-zig-freebsd setup-dev-environment ]
|
|
++ (with pkgs; [ musl ]);
|
|
});
|
|
|
|
windows = craneLib.devShell (buildEnvironment // {
|
|
name = "sparse-windows";
|
|
|
|
packages = buildTools.windows ++ devShellTools
|
|
++ [ setup-zig-freebsd setup-dev-environment ];
|
|
|
|
# No point adding above environment variables, since web server can't
|
|
# be built with windows tools available
|
|
|
|
OPENSSL_DIR = system-libs.win-openssl;
|
|
});
|
|
|
|
freebsd = craneLib.devShell (buildEnvironment // {
|
|
name = "sparse-freebsd";
|
|
|
|
packages = buildTools.freebsd ++ devShellTools
|
|
++ [ setup-zig-freebsd setup-dev-environment ];
|
|
});
|
|
};
|
|
});
|
|
}
|