19 pname = "zerotierone";
22 src = fetchFromGitHub {
26 hash = "sha256-YWcqALUB3ZEukL4er2FKcyNdEbuaf//QU5hRbKAfxDA=";
29 in stdenv.mkDerivation {
30 inherit pname version src;
32 cargoDeps = rustPlatform.importCargoLock {
33 lockFile = ./Cargo.lock;
35 "jwt-0.16.0" = "sha256-P5aJnNlcLe9sBtXZzfqHdRvxNfm6DPBcfcKOVeLZxcM=";
36 "rustfsm-0.1.0" = "sha256-q7J9QgN67iuoNhQC8SDVzUkjCNRXGiNCkE8OsQc5+oI=";
40 # https://github.com/zerotier/ZeroTierOne/pull/2314
42 url = "https://github.com/zerotier/ZeroTierOne/commit/f9c6ee0181acb1b77605d9a4e4106ac79aaacca3.patch";
43 hash = "sha256-zw7KmaxiCH99Y0wQtOQM4u0ruxiePhvv/birxMQioJU=";
45 ./0001-darwin-disable-link-time-optimization.patch
48 cp ${./Cargo.lock} Cargo.lock
49 cp ${./Cargo.lock} rustybits/Cargo.lock
54 cmp ./Cargo.lock ./rustybits/Cargo.lock || {
55 echo 1>&2 "Please make sure that the derivation's Cargo.lock is identical to ./rustybits/Cargo.lock!"
59 patchShebangs ./doc/build.sh
60 substituteInPlace ./doc/build.sh \
61 --replace '/usr/bin/ronn' '${buildPackages.ronn}/bin/ronn' \
63 substituteInPlace ./make-linux.mk \
64 --replace '-march=armv6zk' "" \
65 --replace '-mcpu=arm1176jzf-s' ""
71 rustPlatform.cargoSetupHook
80 ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
82 darwin.apple_sdk.frameworks.SystemConfiguration
83 darwin.apple_sdk.frameworks.CoreServices
86 enableParallelBuilding = true;
88 # Ensure Rust compiles for the right target
89 env.CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.rustcTarget;
91 preBuild = if stdenv.hostPlatform.isDarwin then ''
92 makeFlagsArray+=("ARCH_FLAGS=") # disable multi-arch build
93 if ! grep -q MACOS_VERSION_MIN=10.13 make-mac.mk; then
94 echo "You may need to update MACOSX_DEPLOYMENT_TARGET to match the value in make-mac.mk"
97 (cd rustybits && MACOSX_DEPLOYMENT_TARGET=10.13 cargo build -p zeroidc --release)
100 ./rustybits/target/${stdenv.hostPlatform.rust.rustcTarget}/release/libzeroidc.a \
103 # zerotier uses the "FORCE" target as a phony target to force rebuilds.
104 # We don't want to rebuild libzeroidc.a as we build want to build this library ourself for a single architecture
107 # Cargo won't compile to target/release but to target/<RUST_TARGET>/release when a target is
108 # explicitly defined. The build-system however expects target/release. Hence we just symlink from
109 # the latter to the former.
110 mkdir -p rustybits/target/release
112 ./rustybits/target/${stdenv.hostPlatform.rust.rustcTarget}/release/libzeroidc.a \
113 ./rustybits/target/release/
116 buildFlags = [ "all" "selftest" ];
118 doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
126 # only linux has an install target, we borrow this for macOS as well
128 "DESTDIR=$$out/upstream"
132 mv $out/upstream/usr/sbin $out/bin
135 mv $out/upstream/usr/share/man $man/share/man
140 outputs = [ "out" "man" ];
142 passthru.updateScript = ./update.sh;
145 description = "Create flat virtual Ethernet networks of almost unlimited size";
146 homepage = "https://www.zerotier.com";
147 license = licenses.bsl11;
148 maintainers = with maintainers; [
149 sjmackenzie zimbatm ehmry obadz danielfullmer
150 mic92 # also can test darwin
152 platforms = platforms.unix;