20 pname = "zerotierone";
23 src = fetchFromGitHub {
27 hash = "sha256-YWcqALUB3ZEukL4er2FKcyNdEbuaf//QU5hRbKAfxDA=";
32 inherit pname version src;
34 cargoDeps = rustPlatform.importCargoLock {
35 lockFile = ./Cargo.lock;
37 "jwt-0.16.0" = "sha256-P5aJnNlcLe9sBtXZzfqHdRvxNfm6DPBcfcKOVeLZxcM=";
38 "rustfsm-0.1.0" = "sha256-q7J9QgN67iuoNhQC8SDVzUkjCNRXGiNCkE8OsQc5+oI=";
42 # https://github.com/zerotier/ZeroTierOne/pull/2314
44 url = "https://github.com/zerotier/ZeroTierOne/commit/f9c6ee0181acb1b77605d9a4e4106ac79aaacca3.patch";
45 hash = "sha256-zw7KmaxiCH99Y0wQtOQM4u0ruxiePhvv/birxMQioJU=";
47 ./0001-darwin-disable-link-time-optimization.patch
50 cp ${./Cargo.lock} Cargo.lock
51 cp ${./Cargo.lock} rustybits/Cargo.lock
55 cmp ./Cargo.lock ./rustybits/Cargo.lock || {
56 echo 1>&2 "Please make sure that the derivation's Cargo.lock is identical to ./rustybits/Cargo.lock!"
60 patchShebangs ./doc/build.sh
61 substituteInPlace ./doc/build.sh \
62 --replace '/usr/bin/ronn' '${buildPackages.ronn}/bin/ronn' \
64 substituteInPlace ./make-linux.mk \
65 --replace '-march=armv6zk' "" \
66 --replace '-mcpu=arm1176jzf-s' ""
72 rustPlatform.cargoSetupHook
83 ++ lib.optionals stdenv.hostPlatform.isDarwin [
85 darwin.apple_sdk.frameworks.SystemConfiguration
86 darwin.apple_sdk.frameworks.CoreServices
89 enableParallelBuilding = true;
91 # Ensure Rust compiles for the right target
92 env.CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.rustcTarget;
95 if stdenv.hostPlatform.isDarwin then
97 makeFlagsArray+=("ARCH_FLAGS=") # disable multi-arch build
98 if ! grep -q MACOS_VERSION_MIN=10.13 make-mac.mk; then
99 echo "You may need to update MACOSX_DEPLOYMENT_TARGET to match the value in make-mac.mk"
102 (cd rustybits && MACOSX_DEPLOYMENT_TARGET=10.13 cargo build -p zeroidc --release)
105 ./rustybits/target/${stdenv.hostPlatform.rust.rustcTarget}/release/libzeroidc.a \
108 # zerotier uses the "FORCE" target as a phony target to force rebuilds.
109 # We don't want to rebuild libzeroidc.a as we build want to build this library ourself for a single architecture
114 # Cargo won't compile to target/release but to target/<RUST_TARGET>/release when a target is
115 # explicitly defined. The build-system however expects target/release. Hence we just symlink from
116 # the latter to the former.
117 mkdir -p rustybits/target/release
119 ./rustybits/target/${stdenv.hostPlatform.rust.rustcTarget}/release/libzeroidc.a \
120 ./rustybits/target/release/
128 doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
136 # only linux has an install target, we borrow this for macOS as well
139 "DESTDIR=$$out/upstream"
143 mv $out/upstream/usr/sbin $out/bin
146 mv $out/upstream/usr/share/man $man/share/man
156 passthru.updateScript = ./update.sh;
159 description = "Create flat virtual Ethernet networks of almost unlimited size";
160 homepage = "https://www.zerotier.com";
161 license = licenses.bsl11;
162 maintainers = with maintainers; [
168 mic92 # also can test darwin
170 platforms = platforms.unix;