From 9821c28accf03918f3680626baee264107e8d795 Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Mon, 20 Jan 2025 22:11:21 -0700 Subject: [PATCH 01/12] freebsd stdenv: switch to llvm bintools --- pkgs/stdenv/freebsd/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/stdenv/freebsd/default.nix b/pkgs/stdenv/freebsd/default.nix index c0a6f7e8ea08..7a6cc26a78be 100644 --- a/pkgs/stdenv/freebsd/default.nix +++ b/pkgs/stdenv/freebsd/default.nix @@ -442,7 +442,7 @@ let inherit (prevStage.freebsd) libc; inherit (prevStage) gnugrep coreutils expand-response-params; runtimeShell = shell; - bintools = prevStage.binutils-unwrapped; + bintools = (prevStage.llvmPackages or { }).bintools-unwrapped or prevStage.binutils-unwrapped; propagateDoc = false; nativeTools = false; nativeLibc = false; From 7a0c12bfb5e3b00cbfce045744df720ea746b1c1 Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Mon, 20 Jan 2025 21:58:22 -0700 Subject: [PATCH 02/12] freebsd.libcMinimal: include i18n path; set relevant environment variable in stdenv --- pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix | 7 +++++++ pkgs/stdenv/freebsd/default.nix | 14 +++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix index 39cd09024fae..36b6f24ad1f4 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix @@ -6,6 +6,7 @@ byacc, gencat, csu, + i18n, extraSrc ? [ ], }: @@ -32,6 +33,7 @@ mkDerivation { "etc/group" "etc/master.passwd" "etc/shells" + "include/paths.h" ] ++ extraSrc; outputs = [ @@ -54,8 +56,13 @@ mkDerivation { ]; # this target is only used in the rtld-elf derivation. build it there instead. + # + # WE SHOULD REALLY BE REPLACING /usr/lib/i18n WITH THE libiconvModules DERIVATION + # but this causes some awful dependency loops which basically collapse the entire libc derivation + # instead, set the PATH_I18NMODULE environment variable whenever possible postPatch = '' sed -E -i -e '/BUILD_NOSSP_PIC_ARCHIVE=/d' $BSDSRCDIR/lib/libc/Makefile + substituteInPlace $BSDSRCDIR/include/paths.h --replace '/usr/share/i18n' '${i18n}/share/i18n' ''; preBuild = '' diff --git a/pkgs/stdenv/freebsd/default.nix b/pkgs/stdenv/freebsd/default.nix index 7a6cc26a78be..20fabb8a6bda 100644 --- a/pkgs/stdenv/freebsd/default.nix +++ b/pkgs/stdenv/freebsd/default.nix @@ -449,11 +449,15 @@ let }; }; overrides = overrides prevStage; - preHook = '' - export NIX_ENFORCE_PURITY="''${NIX_ENFORCE_PURITY-1}" - export NIX_ENFORCE_NO_NATIVE="''${NIX_ENFORCE_NO_NATIVE-1}" - export PATH_LOCALE=${prevStage.freebsd.localesReal or prevStage.freebsd.locales}/share/locale - ''; + preHook = + '' + export NIX_ENFORCE_PURITY="''${NIX_ENFORCE_PURITY-1}" + export NIX_ENFORCE_NO_NATIVE="''${NIX_ENFORCE_NO_NATIVE-1}" + export PATH_LOCALE=${prevStage.freebsd.localesReal or prevStage.freebsd.locales}/share/locale + '' + + lib.optionalString (prevStage.freebsd ? libiconvModules) '' + export PATH_I18NMODULE=${prevStage.freebsd.libiconvModules}/lib/i18n + ''; }; in { From 73df73e82916daa835acba640dbea83c980d4427 Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Mon, 20 Jan 2025 21:48:41 -0700 Subject: [PATCH 03/12] auto-patchelf: force --keep-libc for BSD hosts --- pkgs/by-name/au/auto-patchelf/source/auto-patchelf.py | 4 ++++ pkgs/top-level/all-packages.nix | 3 +++ 2 files changed, 7 insertions(+) diff --git a/pkgs/by-name/au/auto-patchelf/source/auto-patchelf.py b/pkgs/by-name/au/auto-patchelf/source/auto-patchelf.py index cafb761ef870..3426752fa55a 100644 --- a/pkgs/by-name/au/auto-patchelf/source/auto-patchelf.py +++ b/pkgs/by-name/au/auto-patchelf/source/auto-patchelf.py @@ -235,6 +235,10 @@ def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: list except ELFError: return [] + # these platforms are packaged in nixpkgs with ld.so in a separate derivation + # than libc.so and friends. keep_libc is mandatory. + keep_libc |= file_osabi in ('ELFOSABI_FREEBSD', 'ELFOSABI_OPENBSD') + rpath = [] if file_is_dynamic_executable: print("setting interpreter of", path) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f174ec6a08d5..101e5f271fd9 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -243,6 +243,9 @@ with pkgs; auto-patchelf bintools ]; + substitutions = { + hostPlatform = stdenv.hostPlatform.config; + }; } ../build-support/setup-hooks/auto-patchelf.sh; appimageTools = callPackage ../build-support/appimage { }; From b9c1cebcfaccf426287ca6de0a37b0015fcf8761 Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Thu, 13 Mar 2025 18:18:46 -0700 Subject: [PATCH 04/12] llvmPackages.tblgen: Fix native FreeBSD build --- pkgs/development/compilers/llvm/common/tblgen.nix | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkgs/development/compilers/llvm/common/tblgen.nix b/pkgs/development/compilers/llvm/common/tblgen.nix index 49cbcb0af2ca..8fdf4f57028e 100644 --- a/pkgs/development/compilers/llvm/common/tblgen.nix +++ b/pkgs/development/compilers/llvm/common/tblgen.nix @@ -7,6 +7,7 @@ ninja, patches ? [ ], python3, + updateAutotoolsGnuConfigScriptsHook, release_version, runCommand, src ? null, @@ -76,6 +77,10 @@ let cmake ninja python3 + + # while this is not an autotools build, it still includes a config.guess + # this is needed until scripts are updated to not use /usr/bin/uname on FreeBSD native + updateAutotoolsGnuConfigScriptsHook ]; cmakeFlags = [ From cb9fd5faaafee327379fbb4ec0a7763d5d48cae5 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Sun, 30 Mar 2025 17:29:32 +0000 Subject: [PATCH 05/12] libarchve: disable another atime test This test relies on atime of files and fails inconsistently on FreeBSD. --- pkgs/by-name/li/libarchive/package.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/by-name/li/libarchive/package.nix b/pkgs/by-name/li/libarchive/package.nix index 526979f9cedb..44e6f482dbe4 100644 --- a/pkgs/by-name/li/libarchive/package.nix +++ b/pkgs/by-name/li/libarchive/package.nix @@ -74,6 +74,7 @@ stdenv.mkDerivation (finalAttrs: { # the filesystem does not necessarily have hardlink capabilities "libarchive/test/test_write_disk_hardlink.c" # access-time-related tests flakey on some systems + "libarchive/test/test_read_disk_directory_traversals.c" "cpio/test/test_option_a.c" "cpio/test/test_option_t.c" ] From 9f3746cb551d72ca54417cbef9fc40a41b5401a7 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Sun, 30 Mar 2025 17:31:08 +0000 Subject: [PATCH 06/12] diffutils: disable atime-based test on FreeBSD This atime-based test fails on some FreeBSD configurations --- pkgs/tools/text/diffutils/default.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/tools/text/diffutils/default.nix b/pkgs/tools/text/diffutils/default.nix index 2d2d34b698b5..3f7429eb749b 100644 --- a/pkgs/tools/text/diffutils/default.nix +++ b/pkgs/tools/text/diffutils/default.nix @@ -44,6 +44,10 @@ stdenv.mkDerivation rec { sed -i -E 's:[[:space:]]test-sigsegv-catch-stackoverflow[12]\$\(EXEEXT\)::g' gnulib-tests/Makefile.in sed -i -E 's:[[:space:]]test-sigaction\$\(EXEEXT\)::g' gnulib-tests/Makefile.in '' + else if stdenv.hostPlatform.isFreeBSD then + '' + sed -i -E 's:test-time::g' gnulib-tests/Makefile.in + '' else null; From 6a1622334177fda077d4f8301ec48a56f9d949d2 Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Thu, 29 May 2025 06:20:59 +0000 Subject: [PATCH 07/12] gdbm: fix freebsd native build Pulls in a patch from freebsd-ports. This patch cannot be made unconditional without a rework since it modifies the base behavior. --- .../gd/gdbm/freebsd-patch-src-lock-c.patch | 37 +++++++++++++++++++ pkgs/by-name/gd/gdbm/package.nix | 17 ++++++--- 2 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 pkgs/by-name/gd/gdbm/freebsd-patch-src-lock-c.patch diff --git a/pkgs/by-name/gd/gdbm/freebsd-patch-src-lock-c.patch b/pkgs/by-name/gd/gdbm/freebsd-patch-src-lock-c.patch new file mode 100644 index 000000000000..4312cf998d60 --- /dev/null +++ b/pkgs/by-name/gd/gdbm/freebsd-patch-src-lock-c.patch @@ -0,0 +1,37 @@ +https://github.com/freebsd/freebsd-ports/blob/e198aef78afa4fd78ddc62fb5d0f7caa1b076bb0/databases/gdbm/files/patch-src_lock.c + +--- a/src/lock.c.orig 2025-03-06 16:24:09 UTC ++++ b/src/lock.c +@@ -73,15 +73,10 @@ try_lock_flock (GDBM_FILE dbf, int nb) + { + return TRY_LOCK_OK; + } +- else if (errno == EWOULDBLOCK) ++ else if (errno == EWOULDBLOCK || errno == EINTR) + { + return TRY_LOCK_FAIL; + } +- else if (errno == EINTR) +- { +- errno = ETIME; +- return TRY_LOCK_FAIL; +- } + #endif + return TRY_LOCK_NEXT; + } +@@ -116,7 +111,6 @@ try_lock_lockf (GDBM_FILE dbf, int nb) + switch (errno) + { + case EINTR: +- errno = ETIME; + case EACCES: + case EAGAIN: + case EDEADLK: +@@ -162,7 +156,6 @@ try_lock_fcntl (GDBM_FILE dbf, int nb) + switch (errno) + { + case EINTR: +- errno = ETIME; + case EACCES: + case EAGAIN: + case EDEADLK: diff --git a/pkgs/by-name/gd/gdbm/package.nix b/pkgs/by-name/gd/gdbm/package.nix index c707a23cfeaf..28cfd69edadb 100644 --- a/pkgs/by-name/gd/gdbm/package.nix +++ b/pkgs/by-name/gd/gdbm/package.nix @@ -1,6 +1,7 @@ { lib, fetchurl, + fetchpatch, stdenv, testers, updateAutotoolsGnuConfigScriptsHook, @@ -15,12 +16,16 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-0C2zxZJu2Hf4gXuBzR+S9T73TKjG21Q/u6AnGzTzk+w="; }; - patches = [ - # Remove on next release. - ./upstream-darwin-clock-nanosleep-fix.patch - ./upstream-lockwait-test-fixes.patch - ./upstream-musl-ssize_t-fix.patch - ]; + patches = + [ + # Remove on next release. + ./upstream-darwin-clock-nanosleep-fix.patch + ./upstream-lockwait-test-fixes.patch + ./upstream-musl-ssize_t-fix.patch + ] + ++ lib.optionals stdenv.hostPlatform.isFreeBSD [ + ./freebsd-patch-src-lock-c.patch + ]; nativeBuildInputs = [ updateAutotoolsGnuConfigScriptsHook ]; From db59d6687804e1f6680853168b2a4fe01288e9fb Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Thu, 29 May 2025 20:31:49 +0000 Subject: [PATCH 08/12] libuv: add more workarounds for tests on FreeBSD --- pkgs/by-name/li/libuv/package.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkgs/by-name/li/libuv/package.nix b/pkgs/by-name/li/libuv/package.nix index ccbcfc939ed6..949fb489eb23 100644 --- a/pkgs/by-name/li/libuv/package.nix +++ b/pkgs/by-name/li/libuv/package.nix @@ -134,6 +134,8 @@ stdenv.mkDerivation (finalAttrs: { # EOPNOTSUPP when performed in jailed build env "tcp_reuseport" "udp_reuseport" + # jailed build env does not have a hostname + "gethostname" # Fails when built on non-nix FreeBSD # https://github.com/libuv/libuv/issues/4606 "fs_event_watch_delete_dir" @@ -142,6 +144,8 @@ stdenv.mkDerivation (finalAttrs: { in lib.optionalString (finalAttrs.finalPackage.doCheck) '' sed '/${tdRegexp}/d' -i test/test-list.h + # https://github.com/libuv/libuv/issues/4794 + substituteInPlace Makefile.am --replace-fail -lutil "-lutil -lm" ''; nativeBuildInputs = [ From 594993063bf2aeb6eafda267b3aa734a9c8f244e Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Thu, 29 May 2025 20:32:49 +0000 Subject: [PATCH 09/12] stdenv/freebsd: isolate bootstrap process more Copying instead of symlinking prevents leakage of the bootstrap FHS into the 0->1 bootstrap stage. The symptom this addresses is libssh2 failing because it can't find libssl, since it is failing to use the ld wrapper. --- pkgs/stdenv/freebsd/default.nix | 3 +++ pkgs/stdenv/freebsd/linkBootstrap.sh | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pkgs/stdenv/freebsd/default.nix b/pkgs/stdenv/freebsd/default.nix index 20fabb8a6bda..a2e6b834aade 100644 --- a/pkgs/stdenv/freebsd/default.nix +++ b/pkgs/stdenv/freebsd/default.nix @@ -62,6 +62,9 @@ let name = attrs.name or (builtins.baseNameOf (builtins.elemAt attrs.paths 0)); src = bootstrapArchive; builder = "${bootstrapArchive}/bin/bash"; + # this script will prefer to link files instead of copying them. + # this prevents clang in particular, but possibly others, from calling readlink(argv[0]) + # and obtaining dependencies, ld(1) in particular, from there instead of $PATH. args = [ ./linkBootstrap.sh ]; PATH = "${bootstrapArchive}/bin"; paths = attrs.paths; diff --git a/pkgs/stdenv/freebsd/linkBootstrap.sh b/pkgs/stdenv/freebsd/linkBootstrap.sh index 19b491d2c3c4..73f984d1f1f0 100644 --- a/pkgs/stdenv/freebsd/linkBootstrap.sh +++ b/pkgs/stdenv/freebsd/linkBootstrap.sh @@ -6,5 +6,9 @@ for path in $paths; do exit 1 fi mkdir -p $out/$(dirname $path) - ln -s $src/$path $out/$path + if [[ -d $src/$path ]]; then + ln -s $src/$path $out/$path + else + cp -RL $src/$path $out/$path + fi done From 3026fd9c90b0275e3aaacca3218363f236abc71a Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Fri, 30 May 2025 02:38:14 +0000 Subject: [PATCH 10/12] stdenv/freebsd: copy clang lib folder out of bootstrap archive Fixes the boot0 build of python --- pkgs/stdenv/freebsd/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/pkgs/stdenv/freebsd/default.nix b/pkgs/stdenv/freebsd/default.nix index a2e6b834aade..abd80b281670 100644 --- a/pkgs/stdenv/freebsd/default.nix +++ b/pkgs/stdenv/freebsd/default.nix @@ -96,6 +96,7 @@ let "bin/clang" "bin/clang++" "bin/cpp" + "lib/clang" ]; # SYNCME: this version number must be synced with the one in make-bootstrap-tools.nix version = "18"; From 3e7fa4878efc84ca3b8e32c6b5c0095e1cc5c918 Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Fri, 30 May 2025 02:38:55 +0000 Subject: [PATCH 11/12] llvm: disable a test that fails in the FreeBSD build jail --- pkgs/development/compilers/llvm/common/llvm/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/compilers/llvm/common/llvm/default.nix b/pkgs/development/compilers/llvm/common/llvm/default.nix index e7d12650fa47..58a7252c8ff3 100644 --- a/pkgs/development/compilers/llvm/common/llvm/default.nix +++ b/pkgs/development/compilers/llvm/common/llvm/default.nix @@ -526,6 +526,8 @@ stdenv.mkDerivation ( optionalString stdenv.hostPlatform.isFreeBSD '' rm test/tools/llvm-libtool-darwin/L-and-l.test rm test/ExecutionEngine/Interpreter/intrinsics.ll + # Fails in sandbox + substituteInPlace unittests/Support/LockFileManagerTest.cpp --replace-fail "Basic" "DISABLED_Basic" '' + '' patchShebangs test/BugPoint/compile-custom.ll.py From 1a7421de5aa9c7d1be002f3e1b2343504ad35160 Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Fri, 30 May 2025 04:31:24 +0000 Subject: [PATCH 12/12] gnupatch: disable a filesystem-dependent test --- pkgs/tools/text/gnupatch/default.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkgs/tools/text/gnupatch/default.nix b/pkgs/tools/text/gnupatch/default.nix index 7d6d5b82e7a6..e370b1cb11f8 100644 --- a/pkgs/tools/text/gnupatch/default.nix +++ b/pkgs/tools/text/gnupatch/default.nix @@ -3,6 +3,7 @@ stdenv, fetchurl, ed, + autoreconfHook, }: stdenv.mkDerivation rec { @@ -14,6 +15,13 @@ stdenv.mkDerivation rec { hash = "sha256-+Hzuae7CtPy/YKOWsDCtaqNBXxkqpffuhMrV4R9/WuM="; }; + # This test is filesystem-dependent - observed failing on ZFS + postPatch = lib.optionalString stdenv.hostPlatform.isFreeBSD '' + sed -E -i -e '/bad-filenames/d' tests/Makefile.am + ''; + + nativeBuildInputs = [ autoreconfHook ]; + configureFlags = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ "ac_cv_func_strnlen_working=yes" ];