From 245a3c31474b350accf05be96c24563c02385f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 21 Jun 2024 15:11:15 +0200 Subject: [PATCH 1/2] zerotierone: fix darwin build --- ...arwin-disable-link-time-optimization.patch | 32 +++++++++++++ pkgs/tools/networking/zerotierone/default.nix | 48 ++++++++++++++++--- 2 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 pkgs/tools/networking/zerotierone/0001-darwin-disable-link-time-optimization.patch diff --git a/pkgs/tools/networking/zerotierone/0001-darwin-disable-link-time-optimization.patch b/pkgs/tools/networking/zerotierone/0001-darwin-disable-link-time-optimization.patch new file mode 100644 index 000000000000..475655f94a56 --- /dev/null +++ b/pkgs/tools/networking/zerotierone/0001-darwin-disable-link-time-optimization.patch @@ -0,0 +1,32 @@ +From f71d88a15f537cbc5ea80ad2922c013553a5caab Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= +Date: Fri, 21 Jun 2024 14:43:03 +0200 +Subject: [PATCH 2/2] darwin: disable link-time optimization +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +It's not yet clear to me, but in our build we somehow mix objects with +and without flto. + +Signed-off-by: Jörg Thalheim +--- + make-mac.mk | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/make-mac.mk b/make-mac.mk +index 7af200ad..b388c05a 100644 +--- a/make-mac.mk ++++ b/make-mac.mk +@@ -84,7 +84,7 @@ ifeq ($(ZT_DEBUG),1) + node/Salsa20.o node/SHA512.o node/C25519.o node/Poly1305.o: CFLAGS = -Wall -O2 -g $(INCLUDES) $(DEFS) + else + CFLAGS?=-Ofast -fstack-protector-strong +- CFLAGS+=$(ARCH_FLAGS) -Wall -flto -fPIE -mmacosx-version-min=$(MACOS_VERSION_MIN) -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS) ++ CFLAGS+=$(ARCH_FLAGS) -Wall -fPIE -mmacosx-version-min=$(MACOS_VERSION_MIN) -DNDEBUG -Wno-unused-private-field $(INCLUDES) $(DEFS) + STRIP=strip + EXTRA_CARGO_FLAGS=--release + RUST_VARIANT=release +-- +2.44.1 + diff --git a/pkgs/tools/networking/zerotierone/default.nix b/pkgs/tools/networking/zerotierone/default.nix index fa2c86d6f83a..1b3ef765f4d9 100644 --- a/pkgs/tools/networking/zerotierone/default.nix +++ b/pkgs/tools/networking/zerotierone/default.nix @@ -10,6 +10,9 @@ , ronn , rustc , zlib +, libiconv +, darwin +, fetchpatch }: let @@ -33,8 +36,17 @@ in stdenv.mkDerivation { "rustfsm-0.1.0" = "sha256-q7J9QgN67iuoNhQC8SDVzUkjCNRXGiNCkE8OsQc5+oI="; }; }; + 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 + ]; postPatch = "cp ${./Cargo.lock} Cargo.lock"; + preConfigure = '' cmp ./Cargo.lock ./rustybits/Cargo.lock || { echo 1>&2 "Please make sure that the derivation's Cargo.lock is identical to ./rustybits/Cargo.lock!" @@ -57,10 +69,15 @@ in stdenv.mkDerivation { cargo rustc ]; + buildInputs = [ lzo openssl zlib + ] ++ lib.optionals stdenv.isDarwin [ + libiconv + darwin.apple_sdk.frameworks.SystemConfiguration + darwin.apple_sdk.frameworks.CoreServices ]; enableParallelBuilding = true; @@ -68,10 +85,25 @@ in stdenv.mkDerivation { # Ensure Rust compiles for the right target env.CARGO_BUILD_TARGET = stdenv.hostPlatform.rust.rustcTarget; - # Cargo won't compile to target/release but to 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. - preBuild = '' + 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//release when a target is + # explicitly defined. The build-system however expects target/release. Hence we just symlink from + # the latter to the former. mkdir -p rustybits/target/release ln -rs \ ./rustybits/target/${stdenv.hostPlatform.rust.rustcTarget}/release/libzeroidc.a \ @@ -87,7 +119,11 @@ in stdenv.mkDerivation { runHook postCheck ''; - installFlags = [ "DESTDIR=$$out/upstream" ]; + installFlags = [ + # only linux has an install target, we borrow this for macOS as well + "-f" "make-linux.mk" + "DESTDIR=$$out/upstream" + ]; postInstall = '' mv $out/upstream/usr/sbin $out/bin @@ -107,6 +143,6 @@ in stdenv.mkDerivation { homepage = "https://www.zerotier.com"; license = licenses.bsl11; maintainers = with maintainers; [ sjmackenzie zimbatm ehmry obadz danielfullmer ]; - platforms = platforms.linux; + platforms = platforms.unix; }; } From 37976f9cda005925daf038a9c56c5d597e4a8344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 25 Jun 2024 17:32:05 +0200 Subject: [PATCH 2/2] zerotierone: add myself as maintainer for darwin --- pkgs/tools/networking/zerotierone/default.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgs/tools/networking/zerotierone/default.nix b/pkgs/tools/networking/zerotierone/default.nix index 1b3ef765f4d9..6f34be09b871 100644 --- a/pkgs/tools/networking/zerotierone/default.nix +++ b/pkgs/tools/networking/zerotierone/default.nix @@ -142,7 +142,10 @@ in stdenv.mkDerivation { description = "Create flat virtual Ethernet networks of almost unlimited size"; homepage = "https://www.zerotier.com"; license = licenses.bsl11; - maintainers = with maintainers; [ sjmackenzie zimbatm ehmry obadz danielfullmer ]; + maintainers = with maintainers; [ + sjmackenzie zimbatm ehmry obadz danielfullmer + mic92 # also can test darwin + ]; platforms = platforms.unix; }; }