173 lines
4.8 KiB
Nix
173 lines
4.8 KiB
Nix
{
|
|
description = "Sparse C2 framework";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
|
|
rust-overlay = {
|
|
url = "github:oxalica/rust-overlay";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
crane = {
|
|
url = "github:ipetkov/crane";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
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 = {
|
|
url = "git+https://github.com/thom311/libnl";
|
|
flake = false;
|
|
};
|
|
winpcap = {
|
|
url = "https://www.winpcap.org/install/bin/WpdPack_4_1_2.zip";
|
|
flake = false;
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, flake-utils, crane, fenix, rust-overlay
|
|
, libpcap-src, libnl, winpcap }:
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
let
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
overlays = [ (import rust-overlay) fenix.overlays.default ];
|
|
};
|
|
|
|
buildTools = with pkgs; [
|
|
autoconf
|
|
automake
|
|
bison
|
|
cmake
|
|
flex
|
|
libtool
|
|
libpcap
|
|
musl
|
|
pkg-config
|
|
];
|
|
|
|
windowsBuildTools = buildTools ++ (with pkgs; [
|
|
pkgsCross.mingwW64.stdenv.cc
|
|
pkgsCross.mingwW64.windows.pthreads
|
|
]);
|
|
|
|
toolchain =
|
|
pkgs.pkgsMusl.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
|
|
|
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
|
|
|
|
src = craneLib.cleanCargoSource (craneLib.path ./.);
|
|
|
|
commonArgs = {
|
|
inherit src;
|
|
|
|
strictDeps = false;
|
|
|
|
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
|
|
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
|
|
|
|
SPARSE_BUILD_LIBPCAP = "${libpcap-src}";
|
|
SPARSE_BUILD_LIBNL = "${libnl}";
|
|
|
|
nativeBuildInputs = buildTools;
|
|
buildInputs = buildTools;
|
|
|
|
doCheck = false;
|
|
};
|
|
|
|
commonWindowsArgs = commonArgs // {
|
|
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
|
|
|
|
SPARSE_BUILD_WINPCAP = "${winpcap}/Lib";
|
|
|
|
nativeBuildInputs = windowsBuildTools;
|
|
buildInputs = windowsBuildTools;
|
|
};
|
|
|
|
artifacts = craneLib.buildDepsOnly commonArgs;
|
|
windowsArtifacts = craneLib.buildDepsOnly commonWindowsArgs;
|
|
|
|
sparse-05-linux-server = craneLib.buildPackage (commonArgs // {
|
|
inherit artifacts;
|
|
|
|
pname = "sparse-05-linux-server";
|
|
cargoExtraArgs = "-p sparse-05-server --locked";
|
|
});
|
|
|
|
sparse-05-windows-server = craneLib.buildPackage (commonWindowsArgs // {
|
|
artifacts = windowsArtifacts;
|
|
|
|
pname = "sparse-05-windows-server";
|
|
cargoExtraArgs = "-p sparse-05-server --locked";
|
|
});
|
|
|
|
sparse-05-windows-service = craneLib.buildPackage (commonWindowsArgs
|
|
// {
|
|
artifacts = windowsArtifacts;
|
|
|
|
pname = "sparse-05-windows-server";
|
|
cargoExtraArgs = "-p sparse-05-server --locked --features service";
|
|
});
|
|
|
|
sparse-05-client = craneLib.buildPackage (commonArgs // {
|
|
inherit artifacts;
|
|
|
|
SPARSE_WINDOWS_SERVER =
|
|
"${sparse-05-windows-server}/bin/sparse-05-server.exe";
|
|
SPARSE_WINDOWS_SERVICE =
|
|
"${sparse-05-windows-service}/bin/sparse-05-server.exe";
|
|
SPARSE_LINUX_SERVER =
|
|
"${sparse-05-linux-server}/bin/sparse-05-server";
|
|
|
|
pname = "sparse-05-client";
|
|
cargoExtraArgs = "-p sparse-05-client --locked";
|
|
});
|
|
|
|
sparse-c2-linux-beacon = craneLib.buildPackage (commonArgs // {
|
|
inherit artifacts;
|
|
|
|
pname = "sparse-c2-beacon";
|
|
cargoExtraArgs = "-p sparse-c2-beacon --locked";
|
|
});
|
|
|
|
sparse-c2-server = craneLib.buildPackage (commonArgs // {
|
|
inherit artifacts;
|
|
|
|
pname = "sparse-c2-server";
|
|
cargoExtraArgs = "-p sparse-c2-server --locked";
|
|
});
|
|
|
|
sparse-c2-client = craneLib.buildPackage (commonArgs // {
|
|
inherit artifacts;
|
|
|
|
pname = "sparse-c2-client";
|
|
cargoExtraArgs = "-p sparse-c2-client --locked";
|
|
});
|
|
in with pkgs; {
|
|
devShells.default = craneLib.devShell {
|
|
name = "sparse";
|
|
|
|
buildInputs = windowsBuildTools ++ [ rust-analyzer ];
|
|
|
|
SPARSE_BUILD_WINPCAP = "${winpcap}/Lib";
|
|
SPARSE_BUILD_LIBPCAP = "${libpcap-src}";
|
|
SPARSE_BUILD_LIBNL = "${libnl}";
|
|
};
|
|
|
|
packages = {
|
|
inherit sparse-05-linux-server sparse-05-windows-server
|
|
sparse-05-windows-service sparse-05-client;
|
|
|
|
inherit sparse-c2-linux-beacon sparse-c2-server sparse-c2-client;
|
|
|
|
default = sparse-05-client;
|
|
};
|
|
});
|
|
}
|