172 lines
5.4 KiB
Nix
172 lines
5.4 KiB
Nix
{ pkgs, buildTools, buildEnvironment, craneLib, advisory-db, winpcap-libs
|
|
, winpcap-drivers, freebsd-libs, libnl, libpcap-linux-musl, libpcap-linux-gnu
|
|
, libpcap-freebsd }:
|
|
let
|
|
patch-elf = header: drv: path:
|
|
let hdr = toString header;
|
|
in pkgs.stdenv.mkDerivation {
|
|
name = "elf-patch-${hdr}";
|
|
|
|
buildInputs = with pkgs; [ vim ];
|
|
|
|
src = drv;
|
|
|
|
buildPhase = ''
|
|
mkdir -p $out/$(dirname ${path})
|
|
cp ${drv}/${path} $out/${path}
|
|
echo '000007: ${hdr}' xxd -r - $out/${path}
|
|
'';
|
|
};
|
|
patch-freebsd-elf = patch-elf 9;
|
|
|
|
src = craneLib.cleanCargoSource ./.;
|
|
|
|
commonArgs = buildEnvironment // {
|
|
inherit src;
|
|
strictDeps = true;
|
|
|
|
nativeBuildInputs = buildTools;
|
|
buildInputs = buildTools;
|
|
};
|
|
|
|
fileSetForBeaconCrate = pkgs.lib.fileset.toSource {
|
|
root = ./.;
|
|
fileset = pkgs.lib.fileset.unions [
|
|
./.cargo/config.toml
|
|
./Cargo.toml
|
|
./Cargo.lock
|
|
./build_common.rs
|
|
(craneLib.fileset.commonCargoSources ./sparse-actions)
|
|
(craneLib.fileset.commonCargoSources ./pcap-sys)
|
|
(craneLib.fileset.commonCargoSources ./nl-sys)
|
|
./nl-sys/src/bridge.c
|
|
(craneLib.fileset.commonCargoSources ./packets)
|
|
(craneLib.fileset.commonCargoSources ./sparse-beacon)
|
|
];
|
|
};
|
|
|
|
fileSetForWebCrate = pkgs.lib.fileset.toSource {
|
|
root = ./.;
|
|
fileset = pkgs.lib.fileset.unions [
|
|
./.cargo/config.toml
|
|
./Cargo.toml
|
|
./Cargo.lock
|
|
./build_common.rs
|
|
(craneLib.fileset.commonCargoSources ./pcap-sys)
|
|
(craneLib.fileset.commonCargoSources ./nl-sys)
|
|
./nl-sys/src/bridge.c
|
|
(craneLib.fileset.commonCargoSources ./packets)
|
|
(craneLib.fileset.commonCargoSources ./sparse-actions)
|
|
(craneLib.fileset.commonCargoSources ./sparse-server)
|
|
./sparse-server/style
|
|
./sparse-server/public
|
|
];
|
|
};
|
|
|
|
freebsdArgs = commonArgs // {
|
|
src = fileSetForBeaconCrate;
|
|
# Sigh...
|
|
# For some reason, crane and cargo don't run the build script for FreeBSD
|
|
# It runs it with the dev shell for all 3 targets, and runs it in the
|
|
# nix packages for Linux and Windows... just not FreeBSD
|
|
CARGO_BUILD_RUSTFLAGS =
|
|
"-Ctarget-feature=+crt-static -Clink-args=--target=x86_64-unknown-freebsd -Clink-args=--sysroot=${freebsd-libs} -Clink-args=-L${freebsd-libs}/lib -Clink-args=-L${freebsd-libs}/usr/lib -Clink-args=-L${libpcap-freebsd}/lib";
|
|
|
|
doCheck = false;
|
|
};
|
|
|
|
windowsArgs = commonArgs // {
|
|
src = fileSetForBeaconCrate;
|
|
doCheck = false;
|
|
};
|
|
|
|
linuxCargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
|
|
name = "sparse-deps-linux";
|
|
cargoExtraArgs = "--target=x86_64-unknown-linux-musl --locked";
|
|
});
|
|
freebsdCargoArtifacts = craneLib.buildDepsOnly (freebsdArgs // {
|
|
name = "sparse-deps-freebsd";
|
|
cargoExtraArgs =
|
|
"--target=x86_64-unknown-freebsd --locked -p sparse-beacon";
|
|
});
|
|
windowsCargoArtifacts = craneLib.buildDepsOnly (windowsArgs // {
|
|
name = "sparse-deps-windows";
|
|
cargoExtraArgs = "--target=x86_64-pc-windows-gnu --locked -p sparse-beacon";
|
|
});
|
|
|
|
sparse-beacon-linux = craneLib.buildPackage (commonArgs // {
|
|
cargoArtifacts = linuxCargoArtifacts;
|
|
name = "sparse-beacon-linux";
|
|
cargoExtraArgs = "-p sparse-beacon";
|
|
src = fileSetForBeaconCrate;
|
|
|
|
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
|
|
CARGO_BUILD_RUSTFLAGS = "-Ctarget-feature=+crt-static";
|
|
});
|
|
|
|
sparse-beacon-freebsd-sysv = craneLib.buildPackage (freebsdArgs // {
|
|
cargoArtifacts = freebsdCargoArtifacts;
|
|
name = "sparse-beacon-freebsd";
|
|
cargoExtraArgs = "-p sparse-beacon";
|
|
|
|
nativeBuildInputs = buildTools;
|
|
|
|
CARGO_BUILD_TARGET = "x86_64-unknown-freebsd";
|
|
CARGO_BUILD_RUSTFLAGS = "-Ctarget-feature=+crt-static";
|
|
});
|
|
|
|
sparse-beacon-freebsd =
|
|
patch-freebsd-elf sparse-beacon-freebsd-sysv "bin/sparse-beacon";
|
|
|
|
sparse-beacon-windows = craneLib.buildPackage (windowsArgs // {
|
|
cargoArtifacts = windowsCargoArtifacts;
|
|
name = "sparse-beacon-windows";
|
|
cargoExtraArgs = "-p sparse-beacon";
|
|
|
|
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
|
|
CARGO_BUILD_RUSTFLAGS = "-Ctarget-feature=+crt-static";
|
|
});
|
|
|
|
sparse-server = craneLib.buildPackage (commonArgs // {
|
|
src = fileSetForWebCrate;
|
|
|
|
cargoArtifacts = linuxCargoArtifacts;
|
|
name = "sparse-server-webclient";
|
|
|
|
buildPhaseCargoCommand = ''
|
|
cargo leptos build \
|
|
--release \
|
|
--project=sparse-server
|
|
'';
|
|
doNotPostBuildInstallCargoBinaries = true;
|
|
installPhase = ''
|
|
mkdir -p $out/bin
|
|
|
|
cp target/x86_64-unknown-linux-musl/release/sparse-server $out/bin
|
|
'';
|
|
|
|
SPARSE_BEACON_LINUX = "${sparse-beacon-linux}/bin/sparse-beacon";
|
|
SPARSE_BEACON_WINDOWS = "${sparse-beacon-windows}/bin/sparse-beacon.exe";
|
|
SPARSE_BEACON_FREEBSD = "${sparse-beacon-freebsd}/bin/sparse-beacon";
|
|
});
|
|
|
|
outputs = rec {
|
|
packages = {
|
|
inherit sparse-beacon-linux sparse-beacon-windows sparse-beacon-freebsd
|
|
sparse-server;
|
|
};
|
|
checks = outputs.packages // {
|
|
rs-fmt = craneLib.cargoFmt { inherit src; };
|
|
rs-audit = craneLib.cargoAudit { inherit src advisory-db; };
|
|
rs-toml-fmt = craneLib.taploFmt {
|
|
src = pkgs.lib.sourceFilesBySuffices src [ ".toml" ];
|
|
};
|
|
rs-deny = craneLib.cargoDeny { inherit src; };
|
|
rs-clippy = craneLib.cargoClippy (commonArgs // {
|
|
cargoArtifacts = linuxCargoArtifacts;
|
|
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
|
});
|
|
};
|
|
};
|
|
in outputs
|