2022-05-18 14:49:53 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
|
|
|
, rustPlatform
|
|
|
|
, fetchFromGitHub
|
|
|
|
, buildPackages
|
2023-05-24 13:37:59 +00:00
|
|
|
, cargo
|
2022-05-18 14:49:53 +00:00
|
|
|
, lzo
|
|
|
|
, openssl
|
|
|
|
, pkg-config
|
|
|
|
, ronn
|
2023-05-24 13:37:59 +00:00
|
|
|
, rustc
|
2022-05-18 14:49:53 +00:00
|
|
|
, zlib
|
2024-07-01 15:47:52 +00:00
|
|
|
, libiconv
|
|
|
|
, darwin
|
|
|
|
, fetchpatch
|
2022-05-18 14:49:53 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "zerotierone";
|
2024-05-15 15:35:15 +00:00
|
|
|
version = "1.14.0";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "zerotier";
|
|
|
|
repo = "ZeroTierOne";
|
|
|
|
rev = version;
|
2024-05-15 15:35:15 +00:00
|
|
|
sha256 = "sha256-YWcqALUB3ZEukL4er2FKcyNdEbuaf//QU5hRbKAfxDA=";
|
2022-05-18 14:49:53 +00:00
|
|
|
};
|
2023-04-29 16:46:19 +00:00
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
in stdenv.mkDerivation {
|
|
|
|
inherit pname version src;
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
cargoDeps = rustPlatform.importCargoLock {
|
|
|
|
lockFile = ./Cargo.lock;
|
|
|
|
outputHashes = {
|
|
|
|
"jwt-0.16.0" = "sha256-P5aJnNlcLe9sBtXZzfqHdRvxNfm6DPBcfcKOVeLZxcM=";
|
2024-05-15 15:35:15 +00:00
|
|
|
"rustfsm-0.1.0" = "sha256-q7J9QgN67iuoNhQC8SDVzUkjCNRXGiNCkE8OsQc5+oI=";
|
2023-04-29 16:46:19 +00:00
|
|
|
};
|
|
|
|
};
|
2024-07-01 15:47:52 +00:00
|
|
|
patches = [
|
|
|
|
# https://github.com/zerotier/ZeroTierOne/pull/2314
|
|
|
|
(fetchpatch {
|
|
|
|
url = "https://github.com/zerotier/ZeroTierOne/commit/f9c6ee0181acb1b77605d9a4e4106ac79aaacca3.patch";
|
|
|
|
hash = "sha256-zw7KmaxiCH99Y0wQtOQM4u0ruxiePhvv/birxMQioJU=";
|
|
|
|
})
|
|
|
|
./0001-darwin-disable-link-time-optimization.patch
|
|
|
|
];
|
2023-04-29 16:46:19 +00:00
|
|
|
postPatch = "cp ${./Cargo.lock} Cargo.lock";
|
|
|
|
|
2024-07-01 15:47:52 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
preConfigure = ''
|
2024-05-15 15:35:15 +00:00
|
|
|
cmp ./Cargo.lock ./rustybits/Cargo.lock || {
|
|
|
|
echo 1>&2 "Please make sure that the derivation's Cargo.lock is identical to ./rustybits/Cargo.lock!"
|
2023-04-29 16:46:19 +00:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2021-04-26 19:14:03 +00:00
|
|
|
patchShebangs ./doc/build.sh
|
|
|
|
substituteInPlace ./doc/build.sh \
|
|
|
|
--replace '/usr/bin/ronn' '${buildPackages.ronn}/bin/ronn' \
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2021-04-26 19:14:03 +00:00
|
|
|
substituteInPlace ./make-linux.mk \
|
2022-06-26 10:26:21 +00:00
|
|
|
--replace '-march=armv6zk' "" \
|
|
|
|
--replace '-mcpu=arm1176jzf-s' ""
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
nativeBuildInputs = [
|
|
|
|
pkg-config
|
|
|
|
ronn
|
2023-04-29 16:46:19 +00:00
|
|
|
rustPlatform.cargoSetupHook
|
2023-05-24 13:37:59 +00:00
|
|
|
cargo
|
|
|
|
rustc
|
2022-05-18 14:49:53 +00:00
|
|
|
];
|
2024-07-01 15:47:52 +00:00
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
buildInputs = [
|
|
|
|
lzo
|
|
|
|
openssl
|
|
|
|
zlib
|
2024-07-01 15:47:52 +00:00
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
libiconv
|
|
|
|
darwin.apple_sdk.frameworks.SystemConfiguration
|
|
|
|
darwin.apple_sdk.frameworks.CoreServices
|
2022-05-18 14:49:53 +00:00
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
# Ensure Rust compiles for the right target
|
|
|
|
env.CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.rustcTarget;
|
|
|
|
|
2024-07-01 15:47:52 +00:00
|
|
|
preBuild = if stdenv.isDarwin then ''
|
|
|
|
makeFlagsArray+=("ARCH_FLAGS=") # disable multi-arch build
|
|
|
|
if ! grep -q MACOS_VERSION_MIN=10.13 make-mac.mk; then
|
|
|
|
echo "You may need to update MACOSX_DEPLOYMENT_TARGET to match the value in make-mac.mk"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
(cd rustybits && MACOSX_DEPLOYMENT_TARGET=10.13 cargo build -p zeroidc --release)
|
|
|
|
|
|
|
|
cp \
|
|
|
|
./rustybits/target/${stdenv.hostPlatform.rust.rustcTarget}/release/libzeroidc.a \
|
|
|
|
./rustybits/target
|
|
|
|
|
|
|
|
# zerotier uses the "FORCE" target as a phony target to force rebuilds.
|
|
|
|
# We don't want to rebuild libzeroidc.a as we build want to build this library ourself for a single architecture
|
|
|
|
touch FORCE
|
|
|
|
'' else ''
|
|
|
|
# Cargo won't compile to target/release but to target/<RUST_TARGET>/release when a target is
|
|
|
|
# explicitly defined. The build-system however expects target/release. Hence we just symlink from
|
|
|
|
# the latter to the former.
|
2024-06-05 15:53:02 +00:00
|
|
|
mkdir -p rustybits/target/release
|
|
|
|
ln -rs \
|
|
|
|
./rustybits/target/${stdenv.hostPlatform.rust.rustcTarget}/release/libzeroidc.a \
|
|
|
|
./rustybits/target/release/
|
|
|
|
'';
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
buildFlags = [ "all" "selftest" ];
|
|
|
|
|
|
|
|
doCheck = stdenv.hostPlatform == stdenv.buildPlatform;
|
|
|
|
checkPhase = ''
|
2022-05-18 14:49:53 +00:00
|
|
|
runHook preCheck
|
2020-04-24 23:36:52 +00:00
|
|
|
./zerotier-selftest
|
2022-05-18 14:49:53 +00:00
|
|
|
runHook postCheck
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2024-07-01 15:47:52 +00:00
|
|
|
installFlags = [
|
|
|
|
# only linux has an install target, we borrow this for macOS as well
|
|
|
|
"-f" "make-linux.mk"
|
|
|
|
"DESTDIR=$$out/upstream"
|
|
|
|
];
|
2022-05-18 14:49:53 +00:00
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
mv $out/upstream/usr/sbin $out/bin
|
|
|
|
|
|
|
|
mkdir -p $man/share
|
|
|
|
mv $out/upstream/usr/share/man $man/share/man
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-05-18 14:49:53 +00:00
|
|
|
rm -rf $out/upstream
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
outputs = [ "out" "man" ];
|
|
|
|
|
2023-04-29 16:46:19 +00:00
|
|
|
passthru.updateScript = ./update.sh;
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Create flat virtual Ethernet networks of almost unlimited size";
|
|
|
|
homepage = "https://www.zerotier.com";
|
|
|
|
license = licenses.bsl11;
|
2024-07-01 15:47:52 +00:00
|
|
|
maintainers = with maintainers; [
|
|
|
|
sjmackenzie zimbatm ehmry obadz danielfullmer
|
|
|
|
mic92 # also can test darwin
|
|
|
|
];
|
|
|
|
platforms = platforms.unix;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|