diff --git a/lib/systems/default.nix b/lib/systems/default.nix index 83ed32ed3275b47..a4e547d0d7d5c4a 100644 --- a/lib/systems/default.nix +++ b/lib/systems/default.nix @@ -78,6 +78,8 @@ let && final.parsed.kernel == platform.parsed.kernel; isCompatible = _: throw "2022-05-23: isCompatible has been removed in favor of canExecute, refer to the 22.11 changelog for details"; # Derived meta-data + useLLVM = final.isFreeBSD; + libc = /**/ if final.isDarwin then "libSystem" else if final.isMinGW then "msvcrt" diff --git a/pkgs/os-specific/bsd/freebsd/default.nix b/pkgs/os-specific/bsd/freebsd/default.nix index 1f321f032516fdf..6186d6b5866a429 100644 --- a/pkgs/os-specific/bsd/freebsd/default.nix +++ b/pkgs/os-specific/bsd/freebsd/default.nix @@ -1,77 +1,73 @@ -{ stdenv, lib, stdenvNoCC -, makeScopeWithSplicing', generateSplicesForMkScope -, buildPackages -, fetchgit, fetchzip -}: - +{ stdenv, lib, config, newScope, buildPackages, pkgsHostHost, makeSetupHook, substituteAll, runtimeShell, ... }: let - inherit (buildPackages.buildPackages) rsync; - versions = builtins.fromJSON (builtins.readFile ./versions.json); - - version = "13.1.0"; - branch = "release/${version}"; - -in makeScopeWithSplicing' { - otherSplices = generateSplicesForMkScope "freebsd"; - f = (self: lib.packagesFromDirectoryRecursive { +in lib.makeScope newScope (self: +let + byName = lib.packagesFromDirectoryRecursive { callPackage = self.callPackage; directory = ./pkgs; - } // { - sourceData = versions.${branch}; - - ports = fetchzip { - url = "https://cgit.freebsd.org/ports/snapshot/ports-dde3b2b456c3a4bdd217d0bf3684231cc3724a0a.tar.gz"; - sha256 = "BpHqJfnGOeTE7tkFJBx0Wk8ryalmf4KNTit/Coh026E="; - }; - - # Why do we have splicing and yet do `nativeBuildInputs = with self; ...`? - # See note in ../netbsd/default.nix. - - compatIfNeeded = lib.optional (!stdenvNoCC.hostPlatform.isFreeBSD) self.compat; - - freebsd-lib = import ./lib { inherit version; }; - - # Overridden arguments avoid cross package-set splicing issues, - # otherwise would just use implicit - # `lib.packagesFromDirectoryRecursive` auto-call. - - compat = self.callPackage ./pkgs/compat/package.nix { - inherit stdenv; - inherit (buildPackages.freebsd) makeMinimal boot-install; - }; - - csu = self.callPackage ./pkgs/csu.nix { - inherit (buildPackages.freebsd) makeMinimal install gencat; - inherit (self) include; - }; - - include = self.callPackage ./pkgs/include/package.nix { - inherit (buildPackages.freebsd) makeMinimal install rpcgen; - }; - - install = self.callPackage ./pkgs/install.nix { - inherit (buildPackages.freebsd) makeMinimal; - inherit (self) mtree libnetbsd; - }; - - libc = self.callPackage ./pkgs/libc/package.nix { - inherit (buildPackages.freebsd) makeMinimal install gencat rpcgen; - inherit (self) csu include; - }; - - libnetbsd = self.callPackage ./pkgs/libnetbsd/package.nix { - inherit (buildPackages.freebsd) makeMinimal; - }; - - mkDerivation = self.callPackage ./pkgs/mkDerivation.nix { - inherit stdenv; - inherit (buildPackages.freebsd) makeMinimal install tsort; - }; - - makeMinimal = self.callPackage ./pkgs/makeMinimal.nix { - inherit (self) make; - }; - - }); -} + }; + mkTerminate = terminate: target: if terminate <= 0 then throw "Cannot recurse deeper than three levels into FreeBSD scopes" else target; +in byName // (with self; { inherit stdenv; + compatIsNeeded = !self.stdenv.hostPlatform.isFreeBSD; + + # build a self which is parameterized with whatever the targeted version is + # so e.g. pkgsCross.x86_64-freebsd.freebsd.branches."releng/14.0".buildFreebsd will get you + # freebsd.branches."releng/14.0" + buildFreebsd = mkTerminate terminate buildPackages.freebsd.overrideScope (_: _: ({ inherit hostBranch; terminate = terminate - 1; } // lib.optionalAttrs (stdenv.hostPlatform == buildPackages.stdenv.hostPlatform && stdenv.targetPlatform == buildPackages.stdenv.targetPlatform) { inherit buildFreebsd; })); + branches = mkTerminate terminate lib.flip lib.mapAttrs versions (branch: _: self.overrideScope (_: _: { hostBranch = branch; terminate = terminate - 1; })); + + packages13 = mkTerminate terminate self.overrideScope (_: _: { hostBranch = "release/13.2.0"; terminate = terminate - 1; }); + packages14 = mkTerminate terminate self.overrideScope (_: _: { hostBranch = "release/14.0.0"; terminate = terminate - 1; }); + packagesGit = mkTerminate terminate self.overrideScope (_: _: { hostBranch = "main"; terminate = terminate - 1; }); + terminate = 3; + + hostBranch = let + supportedBranches = builtins.attrNames (lib.filterAttrs (k: v: v.supported) versions); + fallbackBranch = let + branchRegex = "releng/.*"; + candidateBranches = builtins.filter (name: builtins.match branchRegex name != null) supportedBranches; + in + lib.last (lib.naturalSort candidateBranches); + envBranch = builtins.getEnv "NIXPKGS_FREEBSD_BRANCH"; + selectedBranch = + if config.freebsdBranch != null then + config.freebsdBranch + else if envBranch != "" then + envBranch + else null; + chosenBranch = if selectedBranch != null then selectedBranch else fallbackBranch; + in + if versions ? ${chosenBranch} then chosenBranch else throw '' + Unknown FreeBSD branch ${chosenBranch}! + FreeBSD branches normally look like one of: + * `release/..0` for tagged releases without security updates + * `releng/.` for release update branches with security updates + * `stable/` for stable versions working towards the next minor release + * `main` for the latest development version + + Set one with the NIXPKGS_FREEBSD_BRANCH environment variable or by setting `nixpkgs.config.freebsdBranch`. + ''; + + sourceData = versions.${hostBranch}; + versionData = sourceData.version; + hostVersion = versionData.revision; + + hostArchBsd = { + x86_64 = "amd64"; + aarch64 = "arm64"; + i486 = "i386"; + i586 = "i386"; + i686 = "i386"; + }.${self.stdenv.hostPlatform.parsed.cpu.name} or self.stdenv.hostPlatform.parsed.cpu.name; + + patchesRoot = ./patches/${hostVersion}; + + compatIfNeeded = lib.optional compatIsNeeded compat; + + # for cross-compiling or bootstrapping + install-wrapper = builtins.readFile ./install-wrapper.sh; + boot-install = buildPackages.writeShellScriptBin "boot-install" (install-wrapper + '' + ${xinstallBootstrap}/bin/xinstall "''${args[@]}" + ''); +})) diff --git a/pkgs/os-specific/bsd/freebsd/install-wrapper.sh b/pkgs/os-specific/bsd/freebsd/install-wrapper.sh new file mode 100644 index 000000000000000..91a7a2679f2095e --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/install-wrapper.sh @@ -0,0 +1,30 @@ +set -eu + +args=() +declare -i path_args=0 + +while (( $# )); do + if (( $# == 1 )); then + if (( path_args > 1)) || [[ "$1" = */ ]]; then + mkdir -p "$1" + else + mkdir -p "$(dirname "$1")" + fi + fi + case $1 in + -C) ;; + -o | -g) shift ;; + -s) ;; + -m | -l) + # handle next arg so not counted as path arg + args+=("$1" "$2") + shift + ;; + -*) args+=("$1") ;; + *) + path_args+=1 + args+=("$1") + ;; + esac + shift +done diff --git a/pkgs/os-specific/bsd/freebsd/patches/14.0/bmake-no-compiler-rt.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/bmake-no-compiler-rt.patch new file mode 100644 index 000000000000000..f43d87c01e549df --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/patches/14.0/bmake-no-compiler-rt.patch @@ -0,0 +1,11 @@ +--- a/share/mk/src.libnames.mk 2023-12-21 23:56:50.767042385 -0800 ++++ b/share/mk/src.libnames.mk 2023-12-21 23:56:39.671089506 -0800 +@@ -392,7 +392,7 @@ + _DP_ztest= geom m nvpair umem zpool pthread avl zfs_core spl zutil zfs uutil icp + # The libc dependencies are not strictly needed but are defined to make the + # assert happy. +-_DP_c= compiler_rt ++_DP_c= + # Use libssp_nonshared only on i386 and power*. Other archs emit direct calls + # to __stack_chk_fail, not __stack_chk_fail_local provided by libssp_nonshared. + .if ${MK_SSP} != "no" && \ diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/compat/compat-fix-typedefs-locations.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/compat-fix-typedefs-locations.patch similarity index 100% rename from pkgs/os-specific/bsd/freebsd/pkgs/compat/compat-fix-typedefs-locations.patch rename to pkgs/os-specific/bsd/freebsd/patches/14.0/compat-fix-typedefs-locations.patch diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/compat/compat-install-dirs.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/compat-install-dirs.patch similarity index 93% rename from pkgs/os-specific/bsd/freebsd/pkgs/compat/compat-install-dirs.patch rename to pkgs/os-specific/bsd/freebsd/patches/14.0/compat-install-dirs.patch index 9bb2bea32ee9886..4bc21cf8eb14774 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/compat/compat-install-dirs.patch +++ b/pkgs/os-specific/bsd/freebsd/patches/14.0/compat-install-dirs.patch @@ -2,12 +2,11 @@ diff --git a/tools/build/Makefile b/tools/build/Makefile index 948a5f9dfdb..592af84eeae 100644 --- a/tools/build/Makefile +++ b/tools/build/Makefile -@@ -327,15 +327,15 @@ host-symlinks: +@@ -327,14 +327,14 @@ host-symlinks: # and cross-tools stages. We do this here using mkdir since mtree may not exist # yet (this happens if we are crossbuilding from Linux/Mac). INSTALLDIR_LIST= \ - bin \ -- lib/casper \ - lib/geom \ - usr/include/casper \ - usr/include/private/ucl \ @@ -16,7 +15,6 @@ index 948a5f9dfdb..592af84eeae 100644 - usr/libdata/pkgconfig \ - usr/libexec + ${BINDIR} \ -+ ${LIBDIR}/casper \ + ${LIBDIR}/geom \ + ${INCLUDEDIR}/casper \ + ${INCLUDEDIR}/private/ucl \ diff --git a/pkgs/os-specific/bsd/freebsd/patches/14.0/install-bootstrap-Makefile.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/install-bootstrap-Makefile.patch new file mode 100644 index 000000000000000..d28105544582811 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/patches/14.0/install-bootstrap-Makefile.patch @@ -0,0 +1,11 @@ +--- a/usr.bin/xinstall/Makefile 2023-09-23 19:18:49.165192183 -0700 ++++ b/usr.bin/xinstall/Makefile 2023-12-06 17:06:57.836888028 -0700 +@@ -14,7 +14,7 @@ + CFLAGS+= -I${SRCTOP}/lib/libnetbsd + + LIBADD= md +-CFLAGS+= -DWITH_MD5 -DWITH_RIPEMD160 ++CFLAGS= -I${BSDSRCDIR}/contrib/libc-vis -I${BSDSRCDIR}/lib/libnetbsd + + .ifdef BOOTSTRAPPING + # For the bootstrap we disable copy_file_range() diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libc/libc-msun-arch-subdir.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/libc-msun-arch-subdir.patch similarity index 100% rename from pkgs/os-specific/bsd/freebsd/pkgs/libc/libc-msun-arch-subdir.patch rename to pkgs/os-specific/bsd/freebsd/patches/14.0/libc-msun-arch-subdir.patch diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libc/libc-no-force--lcompiler-rt.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/libc-no-force--lcompiler-rt.patch similarity index 100% rename from pkgs/os-specific/bsd/freebsd/pkgs/libc/libc-no-force--lcompiler-rt.patch rename to pkgs/os-specific/bsd/freebsd/patches/14.0/libc-no-force--lcompiler-rt.patch diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libnetbsd/libnetbsd-do-install.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/libnetbsd-do-install.patch similarity index 100% rename from pkgs/os-specific/bsd/freebsd/pkgs/libnetbsd/libnetbsd-do-install.patch rename to pkgs/os-specific/bsd/freebsd/patches/14.0/libnetbsd-do-install.patch diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libc/librpcsvc-include-subdir.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/librpcsvc-include-subdir.patch similarity index 100% rename from pkgs/os-specific/bsd/freebsd/pkgs/libc/librpcsvc-include-subdir.patch rename to pkgs/os-specific/bsd/freebsd/patches/14.0/librpcsvc-include-subdir.patch diff --git a/pkgs/os-specific/bsd/freebsd/patches/14.0/mtree-Makefile.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/mtree-Makefile.patch new file mode 100644 index 000000000000000..2a6e560d1d28716 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/patches/14.0/mtree-Makefile.patch @@ -0,0 +1,13 @@ +--- a/contrib/mtree/Makefile 2023-12-04 23:02:13.919144141 -0700 ++++ b/contrib/mtree/Makefile 2023-12-04 23:02:58.371810109 -0700 +@@ -10,8 +10,8 @@ + SRCS= compare.c crc.c create.c excludes.c misc.c mtree.c spec.c specspec.c \ + verify.c getid.c pack_dev.c only.c + .if (${HOSTPROG:U} == "") +-DPADD+= ${LIBUTIL} +-LDADD+= -lutil ++LIBADD+= ${LIBUTIL} ++#LIBADD+= -lutil + .endif + + CPPFLAGS+= -I${NETBSDSRCDIR}/sbin/mknod diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/include/no-perms-BSD.include.dist.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/no-perms-BSD.include.dist.patch similarity index 100% rename from pkgs/os-specific/bsd/freebsd/pkgs/include/no-perms-BSD.include.dist.patch rename to pkgs/os-specific/bsd/freebsd/patches/14.0/no-perms-BSD.include.dist.patch diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/rpcgen-glibc-hack.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/rpcgen-glibc-hack.patch similarity index 100% rename from pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/rpcgen-glibc-hack.patch rename to pkgs/os-specific/bsd/freebsd/patches/14.0/rpcgen-glibc-hack.patch diff --git a/pkgs/os-specific/bsd/freebsd/patches/14.0/rtld-no-force--lcompiler-rt.patch b/pkgs/os-specific/bsd/freebsd/patches/14.0/rtld-no-force--lcompiler-rt.patch new file mode 100644 index 000000000000000..45f0d0c51eec0d4 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/patches/14.0/rtld-no-force--lcompiler-rt.patch @@ -0,0 +1,10 @@ +--- a/libexec/rtld-elf/Makefile ++++ b/libexec/rtld-elf/Makefile +@@ -86,7 +86,6 @@ + + # Some of the required math functions (div & mod) are implemented in + # libcompiler_rt on some architectures. +-LIBADD+= compiler_rt + + .include + ${PROG_FULL}: ${VERSION_MAP} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/bmakeMinimal.nix b/pkgs/os-specific/bsd/freebsd/pkgs/bmakeMinimal.nix new file mode 100644 index 000000000000000..cd0916e881a4daf --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/bmakeMinimal.nix @@ -0,0 +1,69 @@ +{ lib, stdenv, mkDerivation, bsdSetupHook, freebsdSetupHook, patchesRoot, hostVersion }: +mkDerivation { + path = "contrib/bmake"; + extraPaths = [ "share/mk" ] + ++ lib.optional (!stdenv.hostPlatform.isFreeBSD) "tools/build/mk"; + + buildInputs = []; + nativeBuildInputs = [ bsdSetupHook freebsdSetupHook ]; + + skipIncludesPhase = true; + + makeFlags = []; + + patches = [ + /${patchesRoot}/bmake-no-compiler-rt.patch + ]; + + postPatch = '' + patchShebangs configure + # make needs this to pick up our sys make files + export NIX_CFLAGS_COMPILE+=" -D_PATH_DEFSYSPATH=\"$out/share/mk\"" + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace $BSDSRCDIR/share/mk/bsd.sys.mk \ + --replace '-Wl,--fatal-warnings' "" \ + --replace '-Wl,--warn-shared-textrel' "" + '' + lib.optionalString (stdenv.targetPlatform.isFreeBSD && hostVersion != "13.2") '' + substituteInPlace $BSDSRCDIR/share/mk/local.sys.dirdeps.env.mk \ + --replace 'MK_host_egacy= yes' 'MK_host_egacy= no' + ''; + + configureFlags = ["--with-filemon=no"]; + + buildPhase = '' + runHook preBuild + + sh ./make-bootstrap.sh + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + install -D bmake "$out/bin/bmake" + ln -s "$out/bin/bmake" "$out/bin/make" + mkdir -p "$out/share" + cp -r "$BSDSRCDIR/share/mk" "$out/share/mk" + find "$out/share/mk" -type f -print0 | + while IFS= read -r -d "" f; do + substituteInPlace "$f" --replace 'usr/' "" + done + substituteInPlace "$out/share/mk/bsd.symver.mk" \ + --replace '/share/mk' "$out/share/mk" + + runHook postInstall + ''; + + postInstall = lib.optionalString (!stdenv.targetPlatform.isFreeBSD) '' + boot_mk="$BSDSRCDIR/tools/build/mk" + cp "$boot_mk"/Makefile.boot* "$out/share/mk" + replaced_mk="$out/share/mk.orig" + mkdir "$replaced_mk" + mv "$out"/share/mk/bsd.{lib,prog}.mk "$replaced_mk" + for m in bsd.{lib,prog}.mk; do + cp "$boot_mk/$m" "$out/share/mk" + substituteInPlace "$out/share/mk/$m" --replace '../../../share/mk' '../mk.orig' + done + ''; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/compat/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/compat/package.nix index 5e4528fbf46a1bd..7f4c7948ec93776 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/compat/package.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/compat/package.nix @@ -1,16 +1,8 @@ -{ lib, stdenv, mkDerivation -, bsdSetupHook, freebsdSetupHook -, makeMinimal, boot-install -, which -, freebsd-lib -, expat, zlib, -}: - -let - inherit (freebsd-lib) mkBsdArch; +{ mkDerivation, lib, hostArchBsd, buildPackages, buildFreebsd, patchesRoot, hostVersion, pkgsHostHost }: +let stdenv = pkgsHostHost.stdenv; in - -mkDerivation rec { +assert stdenv.hostPlatform == stdenv.buildPlatform; +mkDerivation { pname = "compat"; path = "tools/build"; extraPaths = [ @@ -30,6 +22,9 @@ mkDerivation rec { # Take only individual headers, or else we will clobber native libc, etc. "sys/rpc/types.h" + ] ++ lib.optionals (hostVersion == "14.0") [ + "sys/sys/bitcount.h" + ] ++ [ # Listed in Makekfile as INC "include/mpool.h" @@ -43,6 +38,11 @@ mkDerivation rec { "include/nl_types.h" "include/elf.h" "sys/sys/ctf.h" + ] ++ lib.optionals (hostVersion == "14.0") [ + "include/bitstring.h" + "sys/sys/bitstring.h" + "sys/sys/nv_namespace.h" + ] ++ [ # Listed in Makekfile as SYSINC @@ -58,7 +58,7 @@ mkDerivation rec { "sys/sys/elf64.h" "sys/sys/elf_common.h" "sys/sys/elf_generic.h" - "sys/${mkBsdArch stdenv}/include" + "sys/${hostArchBsd}/include" ] ++ lib.optionals stdenv.hostPlatform.isx86 [ "sys/x86/include" ] ++ [ @@ -70,6 +70,12 @@ mkDerivation rec { "sys/sys/font.h" "sys/sys/consio.h" "sys/sys/fnv_hash.h" + #"sys/sys/cdefs.h" + #"sys/sys/param.h" + "sys/sys/_null.h" + #"sys/sys/types.h" + "sys/sys/_pthreadtypes.h" + "sys/sys/_stdint.h" "sys/crypto/chacha20/_chacha.h" "sys/crypto/chacha20/chacha.h" @@ -82,18 +88,22 @@ mkDerivation rec { "lib/libcapsicum" "lib/libcasper" + "lib/libmd" + + # idk bro + "sys/sys/kbio.h" ]; patches = [ - ./compat-install-dirs.patch - ./compat-fix-typedefs-locations.patch + /${patchesRoot}/compat-install-dirs.patch + /${patchesRoot}/compat-fix-typedefs-locations.patch ]; preBuild = '' NIX_CFLAGS_COMPILE+=' -I../../include -I../../sys' - cp ../../sys/${mkBsdArch stdenv}/include/elf.h ../../sys/sys - cp ../../sys/${mkBsdArch stdenv}/include/elf.h ../../sys/sys/${mkBsdArch stdenv} + cp ../../sys/${hostArchBsd}/include/elf.h ../../sys/sys + cp ../../sys/${hostArchBsd}/include/elf.h ../../sys/sys/${hostArchBsd} '' + lib.optionalString stdenv.hostPlatform.isx86 '' cp ../../sys/x86/include/elf.h ../../sys/x86 ''; @@ -109,24 +119,42 @@ mkDerivation rec { ''; nativeBuildInputs = [ - bsdSetupHook freebsdSetupHook - makeMinimal - boot-install + buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook + buildFreebsd.bmakeMinimal - which + buildPackages.which + buildPackages.expat + buildPackages.zlib ]; - buildInputs = [ expat zlib ]; + buildInputs = []; makeFlags = [ "STRIP=-s" # flag to install, not command "MK_WERROR=no" "HOST_INCLUDE_ROOT=${lib.getDev stdenv.cc.libc}/include" - "INSTALL=boot-install" ]; - preIncludes = '' - mkdir -p $out/{0,1}-include + installPhase = '' + mkdir -p $out/{0,1}-include $out/lib $out/share/man $out/bin $out/include cp --no-preserve=mode -r cross-build/include/common/* $out/0-include + cp libegacy.a $out/lib + cp *.3.gz $out/share/man + for grp in $(make $makeFlags -V INCSGROUPS); do + DIR=$(make $makeFlags -V ''${grp}DIR) + mkdir -p $DIR + for inc in $(make $makeFlags -V ''$grp); do + found=0 + for makedir in / . $(make $makeFlags -V .PATH); do + if [ -e "$makedir/$inc" ]; then + found=$(($found+1)) + cp "$makedir/$inc" $DIR + fi + done + if [ "$found" = "0" ]; then + echo "Could not find header $inc during install" + fi + done + done '' + lib.optionalString stdenv.hostPlatform.isLinux '' cp --no-preserve=mode -r cross-build/include/linux/* $out/1-include '' + lib.optionalString stdenv.hostPlatform.isDarwin '' diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/csu.nix b/pkgs/os-specific/bsd/freebsd/pkgs/csu.nix index 0b17cb1c8481db7..a3bbd9a6ec20a03 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/csu.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/csu.nix @@ -1,23 +1,17 @@ -{ lib, mkDerivation -, bsdSetupHook, freebsdSetupHook -, makeMinimal -, install -, flex, byacc, gencat -, include -}: - +{ mkDerivation, buildPackages, buildFreebsd, include, lib }: mkDerivation { + isStatic = true; path = "lib/csu"; extraPaths = [ "lib/Makefile.inc" "lib/libc/include/libc_private.h" ]; nativeBuildInputs = [ - bsdSetupHook freebsdSetupHook - makeMinimal - install + buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook + buildFreebsd.bmakeMinimal + buildFreebsd.install - flex byacc gencat + buildPackages.flex buildPackages.byacc buildFreebsd.gencat ]; buildInputs = [ include ]; MK_TESTS = "no"; diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/filterSource.nix b/pkgs/os-specific/bsd/freebsd/pkgs/filterSource.nix new file mode 100644 index 000000000000000..746c9cb76903e3c --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/filterSource.nix @@ -0,0 +1,11 @@ +{ lib, pkgsBuildBuild, runCommand, writeText, source }: +{ pname, path, extraPaths ? [] }: +let + sortedPaths = lib.naturalSort ([ path ] ++ extraPaths); + filterText = writeText "${pname}-src-include" + (lib.concatMapStringsSep "\n" (path: "/${path}") sortedPaths); +in runCommand "${pname}-filtered-src" { + nativeBuildInputs = [ (pkgsBuildBuild.rsync.override { enableZstd = false; enableXXHash = false; }) ]; +} '' + rsync -a -r --files-from=${filterText} ${source}/ $out +'' diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/freebsdSetupHook/setup-hook.sh b/pkgs/os-specific/bsd/freebsd/pkgs/freebsdSetupHook/setup-hook.sh index 929782954ba778a..96a3d14c80f7b0c 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/freebsdSetupHook/setup-hook.sh +++ b/pkgs/os-specific/bsd/freebsd/pkgs/freebsdSetupHook/setup-hook.sh @@ -5,7 +5,18 @@ setFreeBSDSrcTop() { addFreeBSDMakeFlags() { makeFlags="SBINDIR=${!outputBin}/bin $makeFlags" makeFlags="LIBEXECDIR=${!outputLib}/libexec $makeFlags" + makeFlags="LIBDATADIR=${!outputLib}/data $makeFlags" makeFlags="INCLUDEDIR=${!outputDev}/include $makeFlags" + makeFlags="CONFDIR=${!outputBin}/etc $makeFlags" + makeFlags="MANDIR=${!outputMan}/share/man/man $makeFlags" + + if [ -n "$debug" ]; then + makeFlags="DEBUGFILEDIR=${debug}/lib/debug $makeFlags" + else + makeFlags="DEBUGFILEDIR=${out}/lib/debug $makeFlags" + fi + + echo $makeFlags } postUnpackHooks+=(setFreeBSDSrcTop) diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/gencat.nix b/pkgs/os-specific/bsd/freebsd/pkgs/gencat.nix index e9ae9f27cc05b37..7738109552d41ca 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/gencat.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/gencat.nix @@ -1,5 +1,4 @@ { mkDerivation }: - mkDerivation { path = "usr.bin/gencat"; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/include/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/include/package.nix index 73fa887c5123143..6902ab65f1809d4 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/include/package.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/include/package.nix @@ -1,12 +1,7 @@ -{ lib, mkDerivation -, buildPackages -, bsdSetupHook, freebsdSetupHook -, makeMinimal -, install -, mandoc, groff, rsync /*, nbperf*/, rpcgen -}: - +{ mkDerivation, buildPackages, buildFreebsd, lib, hostVersion, patchesRoot }: mkDerivation { + isStatic = true; + inherit hostVersion; path = "include"; extraPaths = [ @@ -15,18 +10,16 @@ mkDerivation { "sys" ]; - nativeBuildInputs = [ - bsdSetupHook freebsdSetupHook - makeMinimal - install - mandoc groff rsync /*nbperf*/ rpcgen - - # HACK use NetBSD's for now - buildPackages.netbsd.mtree + nativeBuildInputs = [ + buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook + buildFreebsd.bmakeMinimal + buildFreebsd.install + buildPackages.mandoc buildPackages.groff /*nbperf*/ buildFreebsd.rpcgen + buildFreebsd.mtree ]; patches = [ - ./no-perms-BSD.include.dist.patch + /${patchesRoot}/no-perms-BSD.include.dist.patch ]; # The makefiles define INCSDIR per subdirectory, so we have to set @@ -37,6 +30,7 @@ mkDerivation { sed -i -E \ -e 's_/usr/include_''${INCSDIR0}_' \ {} \; + sed -E -i -e "/_PATH_LOGIN/d" $BSDSRCDIR/include/paths.h ''; makeFlags = [ diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/install.nix b/pkgs/os-specific/bsd/freebsd/pkgs/install.nix index 3db6cd3633d49f6..28b0448d3d1a244 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/install.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/install.nix @@ -1,36 +1,28 @@ -{ lib, stdenv, mkDerivation, writeShellScript -, freebsd-lib -, mtree -, bsdSetupHook, freebsdSetupHook -, makeMinimal, mandoc, groff -, boot-install, install -, compatIfNeeded, libmd, libnetbsd -}: - -# HACK: to ensure parent directories exist. This emulates GNU -# install’s -D option. No alternative seems to exist in BSD install. -let - binstall = writeShellScript "binstall" (freebsd-lib.install-wrapper + '' - - @out@/bin/xinstall "''${args[@]}" - ''); -in mkDerivation { +{ install-wrapper, mkDerivation, mtree, buildPackages, buildFreebsd, compatIfNeeded, lib, stdenv, libmd, libnetbsd }: +let binstall = buildPackages.writeShellScript "binstall" (install-wrapper + '' + @out@/bin/xinstall "''${args[@]}" +''); in mkDerivation { path = "usr.bin/xinstall"; extraPaths = [ mtree.path ]; nativeBuildInputs = [ - bsdSetupHook freebsdSetupHook - makeMinimal mandoc groff + buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook + buildFreebsd.bmakeMinimal buildPackages.mandoc buildPackages.groff # TODO bmake?? (if stdenv.hostPlatform == stdenv.buildPlatform - then boot-install - else install) + then buildFreebsd.boot-install + else buildFreebsd.install) + buildPackages.libmd + buildFreebsd.libnetbsd ]; skipIncludesPhase = true; - buildInputs = compatIfNeeded ++ [ libmd libnetbsd ]; + buildInputs = compatIfNeeded ++ [libmd libnetbsd]; makeFlags = [ "STRIP=-s" # flag to install, not command "MK_WERROR=no" "TESTSDIR=${builtins.placeholder "test"}" - ] ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) "INSTALL=boot-install"; + ] ++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform) [ + "BOOTSTRAPPING=1" + "INSTALL=boot-install" + ]; postInstall = '' install -D -m 0550 ${binstall} $out/bin/binstall substituteInPlace $out/bin/binstall --subst-var out diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libc/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libc/package.nix index 0225d44be4c3b08..13459de7531b4aa 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libc/package.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libc/package.nix @@ -1,17 +1,10 @@ -{ lib, stdenv, mkDerivation - -, bsdSetupHook, freebsdSetupHook -, makeMinimal -, install -, flex, byacc, gencat, rpcgen - -, csu, include -}: - -mkDerivation rec { +{ stdenv, mkDerivation, csu, include, buildPackages, buildFreebsd, lib, hostVersion, patchesRoot }: +mkDerivation { + isStatic = true; pname = "libc"; path = "lib/libc"; extraPaths = [ + "lib/libc_nonshared" "etc/group" "etc/master.passwd" "etc/shells" @@ -27,12 +20,18 @@ mkDerivation rec { "contrib/gdtoa" "contrib/libc-pwcache" "contrib/libc-vis" + ] ++ lib.optionals (hostVersion == "13.2") [ "contrib/tzcode/stdtime" + ] ++ lib.optionals (hostVersion == "14.0") [ + "contrib/tzcode" + ] ++ [ # libthr "lib/libthr" "lib/libthread_db" "libexec/rtld-elf" + "lib/csu/common/crtbrand.S" + "lib/csu/common/notes.h" # librpcsvc "lib/librpcsvc" @@ -44,36 +43,86 @@ mkDerivation rec { "lib/libcrypt" "lib/libmd" "sys/crypto/sha2" + "sys/crypto/skein" + + # libgcc and friends + "lib/libgcc_eh" + "lib/libgcc_s" + "lib/libcompiler_rt" + "contrib/llvm-project/libunwind" + "contrib/llvm-project/compiler-rt" + #"contrib/llvm-project/libcxx" + + # terminfo + "lib/ncurses" + "contrib/ncurses" + "lib/Makefile.inc" + ] ++ lib.optionals (stdenv.hostPlatform.isx86_32) [ + "lib/libssp_nonshared" + ] ++ [ + "lib/libexecinfo" + "contrib/libexecinfo" + + "lib/libkvm" + "sys" # ummmmmmmmmm libkvm wants arch-specific headers from the kernel tree + + "lib/libmemstat" + + "lib/libprocstat" + "sys/contrib/openzfs" + "sys/contrib/pcg-c" + "sys/opencrypto" + "sys/contrib/ck" + "sys/crypto" + + "lib/libdevstat" + + "lib/libelf" + "contrib/elftoolchain" + + "lib/libiconv_modules" + "share/i18n" + "include/paths.h" + + "lib/libdl" ]; patches = [ # Hack around broken propogating MAKEFLAGS to submake, just inline logic - ./libc-msun-arch-subdir.patch + /${patchesRoot}/libc-msun-arch-subdir.patch # Don't force -lcompiler-rt, we don't actually call it that - ./libc-no-force--lcompiler-rt.patch + /${patchesRoot}/libc-no-force--lcompiler-rt.patch + /${patchesRoot}/rtld-no-force--lcompiler-rt.patch # Fix extra include dir to get rpcsvc headers. - ./librpcsvc-include-subdir.patch + /${patchesRoot}/librpcsvc-include-subdir.patch ]; postPatch = '' substituteInPlace $COMPONENT_PATH/Makefile --replace '.include ' "" + + substituteInPlace $BSDSRCDIR/include/paths.h \ + --replace '/usr/lib/i18n' '${builtins.placeholder "out"}/lib/i18n' \ + --replace '/usr/share/i18n' '${builtins.placeholder "out"}/share/i18n' ''; nativeBuildInputs = [ - bsdSetupHook freebsdSetupHook - makeMinimal - install + buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook + buildFreebsd.bmakeMinimal + buildFreebsd.install - flex byacc gencat rpcgen + buildPackages.flex buildPackages.byacc buildFreebsd.gencat buildFreebsd.rpcgen + buildFreebsd.mkcsmapper buildFreebsd.mkesdb ]; buildInputs = [ include csu ]; - env.NIX_CFLAGS_COMPILE = "-B${csu}/lib"; - - # Suppress lld >= 16 undefined version errors - # https://github.com/freebsd/freebsd-src/commit/2ba84b4bcdd6012e8cfbf8a0d060a4438623a638 - env.NIX_LDFLAGS = lib.optionalString (stdenv.targetPlatform.linker == "lld") "--undefined-version"; + env.NIX_CFLAGS_COMPILE = toString [ + "-B${csu}/lib" + # These are supposed to have _RTLD_COMPAT_LIB_SUFFIX so we can get things like "lib32" + # but that's unnecessary + "-DSTANDARD_LIBRARY_PATH=\"${builtins.placeholder "out"}/lib\"" + "-D_PATH_RTLD=\"${builtins.placeholder "out"}/libexec/ld-elf.so.1\"" + ]; makeFlags = [ "STRIP=-s" # flag to install, not command @@ -84,7 +133,7 @@ mkDerivation rec { MK_SYMVER = "yes"; MK_SSP = "yes"; MK_NLS = "yes"; - MK_ICONV = "no"; # TODO make srctop + MK_ICONV = "yes"; MK_NS_CACHING = "yes"; MK_INET6_SUPPORT = "yes"; MK_HESIOD = "yes"; @@ -96,6 +145,18 @@ mkDerivation rec { MK_MALLOC_PRODUCTION = "yes"; MK_TESTS = "no"; + MACHINE_ABI = ""; + MK_DETECT_TZ_CHANGES = "no"; + MK_MACHDEP_OPTIMIZATIONS = "yes"; + MK_ASAN = "no"; + MK_UBSAN = "no"; + + NO_FSCHG = "yes"; + + preBuild = lib.optionalString (stdenv.hostPlatform.isx86_32) '' + make -C $BSDSRCDIR/lib/libssp_nonshared $makeFlags + make -C $BSDSRCDIR/lib/libssp_nonshared $makeFlags install + ''; postInstall = '' pushd ${include} @@ -108,14 +169,29 @@ mkDerivation rec { find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \; popd - sed -i -e 's| [^ ]*/libc_nonshared.a||' $out/lib/libc.so + mkdir $BSDSRCDIR/lib/libcompiler_rt/i386 + make -C $BSDSRCDIR/lib/libcompiler_rt $makeFlags + make -C $BSDSRCDIR/lib/libcompiler_rt $makeFlags install - $CC -nodefaultlibs -lgcc -shared -o $out/lib/libgcc_s.so + make -C $BSDSRCDIR/lib/libgcc_eh $makeFlags + make -C $BSDSRCDIR/lib/libgcc_eh $makeFlags install + + ln -s $BSDSRCDIR/lib/libc/libc.so.7 $BSDSRCDIR/lib/libc/libc.so # not sure + mkdir $BSDSRCDIR/lib/libgcc_s/i386 + make -C $BSDSRCDIR/lib/libgcc_s $makeFlags + make -C $BSDSRCDIR/lib/libgcc_s $makeFlags install NIX_CFLAGS_COMPILE+=" -B$out/lib" NIX_CFLAGS_COMPILE+=" -I$out/include" NIX_LDFLAGS+=" -L$out/lib" + make -C $BSDSRCDIR/lib/libc_nonshared $makeFlags + make -C $BSDSRCDIR/lib/libc_nonshared $makeFlags install + + mkdir $BSDSRCDIR/lib/libmd/sys + make -C $BSDSRCDIR/lib/libmd $makeFlags + make -C $BSDSRCDIR/lib/libmd $makeFlags install + make -C $BSDSRCDIR/lib/libthr $makeFlags make -C $BSDSRCDIR/lib/libthr $makeFlags install @@ -133,7 +209,55 @@ mkDerivation rec { make -C $BSDSRCDIR/lib/libcrypt $makeFlags make -C $BSDSRCDIR/lib/libcrypt $makeFlags install + + make -C $BSDSRCDIR/lib/libelf $makeFlags + make -C $BSDSRCDIR/lib/libelf $makeFlags install + + make -C $BSDSRCDIR/lib/libexecinfo $makeFlags + make -C $BSDSRCDIR/lib/libexecinfo $makeFlags install + + make -C $BSDSRCDIR/lib/libkvm $makeFlags + make -C $BSDSRCDIR/lib/libkvm $makeFlags install + + make -C $BSDSRCDIR/lib/libmemstat $makeFlags + make -C $BSDSRCDIR/lib/libmemstat $makeFlags install + + make -C $BSDSRCDIR/lib/libprocstat $makeFlags + make -C $BSDSRCDIR/lib/libprocstat $makeFlags install + + make -C $BSDSRCDIR/lib/libdevstat $makeFlags + make -C $BSDSRCDIR/lib/libdevstat $makeFlags install + + make -C $BSDSRCDIR/lib/libiconv_modules $makeFlags + make -C $BSDSRCDIR/lib/libiconv_modules $makeFlags SHLIBDIR=${builtins.placeholder "out"}/lib/i18n install + + make -C $BSDSRCDIR/lib/libdl $makeFlags + make -C $BSDSRCDIR/lib/libdl $makeFlags install + + make -C $BSDSRCDIR/share/i18n $makeFlags + make -C $BSDSRCDIR/share/i18n $makeFlags ESDBDIR=${builtins.placeholder "out"}/share/i18n/esdb CSMAPPERDIR=${builtins.placeholder "out"}/share/i18n/csmapper install + + '' + lib.optionalString stdenv.hostPlatform.isx86_32 '' + $CC -c $BSDSRCDIR/contrib/llvm-project/compiler-rt/lib/builtins/udivdi3.c -o $BSDSRCDIR/contrib/llvm-project/compiler-rt/lib/builtins/udivdi3.o + ORIG_NIX_LDFLAGS="$NIX_LDFLAGS" + NIX_LDFLAGS+=" $BSDSRCDIR/contrib/llvm-project/compiler-rt/lib/builtins/udivdi3.o" + '' + '' + make -C $BSDSRCDIR/libexec/rtld-elf $makeFlags + make -C $BSDSRCDIR/libexec/rtld-elf $makeFlags install + rm -f $out/libexec/ld-elf.so.1 + mv $out/bin/ld-elf.so.1 $out/libexec ''; + # libc should not be allowed to refer to anything other than itself + postFixup = '' + find $out -type f | xargs -n1 ${buildPackages.patchelf}/bin/patchelf --shrink-rpath --allowed-rpath-prefixes $out || true + ''; + + meta.platforms = lib.platforms.freebsd; + + # definitely a bad idea to enable stack protection on the stack protection initializers + hardeningDisable = [ "stackprotector" ]; + + outputs = [ "out" "man" "debug" ]; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libnetbsd/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libnetbsd/package.nix index 4011e4d8a649086..d2aa1385bbb6528 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libnetbsd/package.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libnetbsd/package.nix @@ -1,26 +1,18 @@ -{ lib, stdenv -, mkDerivation -, bsdSetupHook, freebsdSetupHook, makeMinimal, mandoc, groff -, boot-install, install -, compatIfNeeded -}: - +{ mkDerivation, buildPackages, buildFreebsd, stdenv, lib, patchesRoot }: mkDerivation { path = "lib/libnetbsd"; nativeBuildInputs = [ - bsdSetupHook freebsdSetupHook - makeMinimal mandoc groff + buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook + buildFreebsd.bmakeMinimal buildPackages.mandoc buildPackages.groff # TODO bmake??? (if stdenv.hostPlatform == stdenv.buildPlatform - then boot-install - else install) + then buildFreebsd.boot-install + else buildFreebsd.install) ]; - patches = lib.optionals (!stdenv.hostPlatform.isFreeBSD) [ - ./libnetbsd-do-install.patch - #./libnetbsd-define-__va_list.patch + patches = [ + /${patchesRoot}/libnetbsd-do-install.patch ]; makeFlags = [ "STRIP=-s" # flag to install, not command "MK_WERROR=no" ] ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) "INSTALL=boot-install"; - buildInputs = compatIfNeeded; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/lorder.nix b/pkgs/os-specific/bsd/freebsd/pkgs/lorder.nix index d1fd86ab5e46399..145c3ca33ba9b12 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/lorder.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/lorder.nix @@ -1,8 +1,5 @@ -{ mkDerivation -, bsdSetupHook, freebsdSetupHook -}: - -mkDerivation rec { +{ mkDerivation, freebsdSetupHook, buildPackages, buildFreebsd }: +mkDerivation { path = "usr.bin/lorder"; noCC = true; dontBuild = true; @@ -12,9 +9,7 @@ mkDerivation rec { chmod +x "$out/bin/lorder" mv "lorder.1" "$man/share/man" ''; - nativeBuildInputs = [ - bsdSetupHook freebsdSetupHook - ]; + nativeBuildInputs = [ buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook ]; buildInputs = []; outputs = [ "out" "man" ]; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/mkDerivation.nix b/pkgs/os-specific/bsd/freebsd/pkgs/mkDerivation.nix index 79428626b8ec256..bf3c6666d9459b9 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/mkDerivation.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/mkDerivation.nix @@ -1,54 +1,32 @@ -{ lib, stdenv, stdenvNoCC -, compatIfNeeded -, runCommand, rsync -, freebsd-lib -, source -, bsdSetupHook, freebsdSetupHook -, makeMinimal -, install, tsort, lorder, mandoc, groff -}: - +{ lib, crossLibcStdenv, stdenv, hostVersion, buildPackages, buildFreebsd, hostArchBsd, compatIfNeeded, filterSource }: lib.makeOverridable (attrs: let - stdenv' = if attrs.noCC or false then stdenvNoCC else stdenv; + # the use of crossLibcStdenv in the isStatic case is kind of a misnomer but I think it works + stdenv' = if (attrs.isStatic or false) then crossLibcStdenv else stdenv; in stdenv'.mkDerivation (rec { - pname = "${attrs.pname or (baseNameOf attrs.path)}-freebsd"; - inherit (freebsd-lib) version; - src = runCommand "${pname}-filtered-src" { - nativeBuildInputs = [ rsync ]; - } '' - for p in ${lib.concatStringsSep " " ([ attrs.path ] ++ attrs.extraPaths or [])}; do - set -x - path="$out/$p" - mkdir -p "$(dirname "$path")" - src_path="${source}/$p" - if [[ -d "$src_path" ]]; then src_path+=/; fi - rsync --chmod="+w" -r "$src_path" "$path" - set +x - done - ''; - - extraPaths = [ ]; + pname = "${attrs.pname or (baseNameOf attrs.path)}"; + version = hostVersion; + src = filterSource { inherit pname; inherit (attrs) path; extraPaths = attrs.extraPaths or []; }; nativeBuildInputs = [ - bsdSetupHook freebsdSetupHook - makeMinimal - install tsort lorder mandoc groff #statHook - ]; + buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook + buildFreebsd.bmakeMinimal # TODO bmake?? + buildFreebsd.install buildFreebsd.tsort buildFreebsd.lorder buildPackages.mandoc buildPackages.groff #statHook + ] ++ attrs.extraNativeBuildInputs or []; buildInputs = compatIfNeeded; HOST_SH = stdenv'.shell; # Since STRIP below is the flag - STRIPBIN = "${stdenv.cc.bintools.targetPrefix}strip"; + STRIPBIN = "${stdenv'.cc.bintools.targetPrefix}strip"; makeFlags = [ "STRIP=-s" # flag to install, not command - ] ++ lib.optional (!stdenv.hostPlatform.isFreeBSD) "MK_WERROR=no"; + ] ++ lib.optional (!stdenv'.hostPlatform.isFreeBSD) "MK_WERROR=no"; # amd64 not x86_64 for this on unlike NetBSD - MACHINE_ARCH = freebsd-lib.mkBsdArch stdenv'; + MACHINE_ARCH = hostArchBsd; - MACHINE = freebsd-lib.mkBsdArch stdenv'; + MACHINE = hostArchBsd; MACHINE_CPUARCH = MACHINE_ARCH; @@ -57,10 +35,10 @@ in stdenv'.mkDerivation (rec { strictDeps = true; meta = with lib; { - maintainers = with maintainers; [ ericson2314 ]; + maintainers = with maintainers; [ rhelmot artemist ]; platforms = platforms.unix; license = licenses.bsd2; - }; + } // attrs.meta or {}; } // lib.optionalAttrs stdenv'.hasCC { # TODO should CC wrapper set this? CPP = "${stdenv'.cc.targetPrefix}cpp"; @@ -75,4 +53,8 @@ in stdenv'.mkDerivation (rec { } // lib.optionalAttrs (attrs.headersOnly or false) { installPhase = "includesPhase"; dontBuild = true; -} // attrs)) +} // attrs // lib.optionalAttrs (stdenv'.cc.isClang or false && attrs.clangFixup or false) { + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -D_VA_LIST -D_VA_LIST_DECLARED -Dva_list=__builtin_va_list -D_SIZE_T_DECLARED -D_SIZE_T -Dsize_t=__SIZE_TYPE__ -D_WCHAR_T" + '' + (attrs.preBuild or ""); +})) diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/mkcsmapper.nix b/pkgs/os-specific/bsd/freebsd/pkgs/mkcsmapper.nix new file mode 100644 index 000000000000000..6bae9268d68f4af --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/mkcsmapper.nix @@ -0,0 +1,17 @@ +{ stdenv, mkDerivation, buildPackages, buildFreebsd }: +mkDerivation { + path = "usr.bin/mkcsmapper"; + + extraPaths = [ "lib/libc/iconv" "lib/libiconv_modules/mapper_std" ]; + + BOOTSTRAPPING = !stdenv.hostPlatform.isFreeBSD; + + nativeBuildInputs = [ + buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook + buildFreebsd.bmakeMinimal + buildFreebsd.install buildFreebsd.tsort buildFreebsd.lorder buildPackages.mandoc buildPackages.groff #statHook + + buildPackages.byacc + buildPackages.flex + ]; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/mkesdb.nix b/pkgs/os-specific/bsd/freebsd/pkgs/mkesdb.nix new file mode 100644 index 000000000000000..1ff808f06fc5306 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/mkesdb.nix @@ -0,0 +1,17 @@ +{ stdenv, mkDerivation, buildPackages, buildFreebsd }: +mkDerivation { + path = "usr.bin/mkesdb"; + + extraPaths = [ "lib/libc/iconv" ]; + + BOOTSTRAPPING = !stdenv.hostPlatform.isFreeBSD; + + nativeBuildInputs = [ + buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook + buildFreebsd.bmakeMinimal + buildFreebsd.install buildFreebsd.tsort buildFreebsd.lorder buildPackages.mandoc buildPackages.groff #statHook + + buildPackages.byacc + buildPackages.flex + ]; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/mtree.nix b/pkgs/os-specific/bsd/freebsd/pkgs/mtree.nix index 23a4672069e6abb..3aa6a15bf889355 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/mtree.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/mtree.nix @@ -1,6 +1,17 @@ -{ mkDerivation, mknod }: - +{ mkDerivation, patchesRoot, libnetbsd, libmd, compatIfNeeded, compatIsNeeded, lib, libutil, stdenv }: mkDerivation { path = "contrib/mtree"; - extraPaths = [ mknod.path ]; + extraPaths = [ "contrib/mknod" ]; + buildInputs = compatIfNeeded ++ [libmd libnetbsd] ++ lib.optional (stdenv.isFreeBSD) libutil; + + patches = [ /${patchesRoot}/mtree-Makefile.patch ]; + + postPatch = '' + ln -s $BSDSRCDIR/contrib/mknod/*.c $BSDSRCDIR/contrib/mknod/*.h $BSDSRCDIR/contrib/mtree + ''; + + clangFixup = true; + preBuild = '' + export NIX_LDFLAGS="$NIX_LDFLAGS -lmd -lnetbsd ${if compatIsNeeded then "-legacy" else ""} ${if stdenv.isFreeBSD then "-lutil" else ""}" + ''; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/package.nix index 56141255af5e184..58fa1744fed592b 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/package.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/package.nix @@ -1,6 +1,5 @@ -{ lib, mkDerivation, stdenv }: - -mkDerivation rec { +{ mkDerivation, lib, stdenv, patchesRoot }: +mkDerivation { path = "usr.bin/rpcgen"; patches = lib.optionals (stdenv.hostPlatform.libc == "glibc") [ # `WUNTRACED` is defined privately `bits/waitflags.h` in glibc. @@ -17,6 +16,6 @@ mkDerivation rec { # # This hacks around this by manually including `WUNTRACED` until # the problem is fixed properly in glibc. - ./rpcgen-glibc-hack.patch + /${patchesRoot}/rpcgen-glibc-hack.patch ]; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/source.nix b/pkgs/os-specific/bsd/freebsd/pkgs/source.nix index 5e31f900e8216e3..fb06451fc7cf31c 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/source.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/source.nix @@ -4,7 +4,7 @@ # If you want you could fetchgit from "https://git.FreeBSD.org/src.git" instead. # The update script still pulls directly from git.freebsd.org fetchFromGitHub { - name = "src"; # Want to rename this next rebuild + name = "freebsd-src"; owner = "freebsd"; repo = "freebsd-src"; inherit (sourceData) rev hash; diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/sys/sys-gnu-date.patch b/pkgs/os-specific/bsd/freebsd/pkgs/sys/sys-gnu-date.patch deleted file mode 100644 index 2356446baf853ea..000000000000000 --- a/pkgs/os-specific/bsd/freebsd/pkgs/sys/sys-gnu-date.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh -index c594724d814..d5287c7b992 100644 ---- a/sys/conf/newvers.sh -+++ b/sys/conf/newvers.sh -@@ -177,7 +177,7 @@ u=${USER:-root} - d=$(pwd) - h=${HOSTNAME:-$(hostname)} - if [ -n "$SOURCE_DATE_EPOCH" ]; then -- if ! t=$(date -r $SOURCE_DATE_EPOCH 2>/dev/null); then -+ if ! t=$(date -d @$SOURCE_DATE_EPOCH 2>/dev/null); then - echo "Invalid SOURCE_DATE_EPOCH" >&2 - exit 1 - fi diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/sys/sys-no-explicit-intrinsics-dep.patch b/pkgs/os-specific/bsd/freebsd/pkgs/sys/sys-no-explicit-intrinsics-dep.patch deleted file mode 100644 index edf44de5bb0d79a..000000000000000 --- a/pkgs/os-specific/bsd/freebsd/pkgs/sys/sys-no-explicit-intrinsics-dep.patch +++ /dev/null @@ -1,45 +0,0 @@ -diff --git a/sys/modules/aesni/Makefile b/sys/modules/aesni/Makefile -index cb8c744adde..1c327331890 100644 ---- a/sys/modules/aesni/Makefile -+++ b/sys/modules/aesni/Makefile -@@ -1,7 +1,6 @@ - # $FreeBSD$ - - .PATH: ${SRCTOP}/sys/crypto/aesni --.PATH: ${SRCTOP}/contrib/llvm-project/clang/lib/Headers - - KMOD= aesni - SRCS= aesni.c -@@ -40,8 +39,8 @@ intel_sha256.o: intel_sha256.c - aesni_ghash.o: aesni.h - aesni_wrap.o: aesni.h - aesni_ccm.o: aesni.h --intel_sha1.o: sha_sse.h immintrin.h shaintrin.h tmmintrin.h xmmintrin.h --intel_sha256.o: sha_sse.h immintrin.h shaintrin.h tmmintrin.h xmmintrin.h -+intel_sha1.o: sha_sse.h -+intel_sha256.o: sha_sse.h - - .include - -diff --git a/sys/modules/blake2/Makefile b/sys/modules/blake2/Makefile -index e4b3fb9f126..5bfd9c2ae02 100644 ---- a/sys/modules/blake2/Makefile -+++ b/sys/modules/blake2/Makefile -@@ -3,7 +3,6 @@ - .PATH: ${SRCTOP}/sys/contrib/libb2 - .PATH: ${SRCTOP}/sys/crypto/blake2 - .PATH: ${SRCTOP}/sys/opencrypto --.PATH: ${SRCTOP}/contrib/llvm-project/clang/lib/Headers - - KMOD = blake2 - -@@ -64,8 +63,7 @@ ${src:S/.c/.o/}: ${src} - -D_MM_MALLOC_H_INCLUDED -Wno-unused-function ${.IMPSRC} - ${CTFCONVERT_CMD} - --${src:S/.c/.o/}: intrin.h emmintrin.h tmmintrin.h smmintrin.h immintrin.h \ -- x86intrin.h ${SRCS:M*.h} -+${src:S/.c/.o/}: ${SRCS:M*.h} - .endfor - - # FreeBSD-specific sources: diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/tsort.nix b/pkgs/os-specific/bsd/freebsd/pkgs/tsort.nix index cdc1b27ce8fed6a..ea7624b9e661703 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/tsort.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/tsort.nix @@ -1,12 +1,15 @@ -{ mkDerivation -, bsdSetupHook, freebsdSetupHook -, makeMinimal, install, mandoc, groff -}: - +{ mkDerivation, buildPackages, buildFreebsd, lib, hostVersion }: mkDerivation { path = "usr.bin/tsort"; - nativeBuildInputs = [ - bsdSetupHook freebsdSetupHook - makeMinimal install mandoc groff + extraPaths = []; + makeFlags = [ + "STRIP=-s" # flag to install, not command + ] ++ lib.optionals (hostVersion == "14.0") [ + "TESTSDIR=${builtins.placeholder "test"}" ]; + nativeBuildInputs = [ + buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook + buildFreebsd.bmakeMinimal buildFreebsd.install buildPackages.mandoc buildPackages.groff # TODO bmake??? + ]; + outputs = [ "out" ] ++ lib.optionals (hostVersion == "14.0") [ "test" ]; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/xinstallBootstrap.nix b/pkgs/os-specific/bsd/freebsd/pkgs/xinstallBootstrap.nix new file mode 100644 index 000000000000000..2202e228f1eba42 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/xinstallBootstrap.nix @@ -0,0 +1,32 @@ +{ install-wrapper, mkDerivation, patchesRoot, buildPackages, buildFreebsd, compatIfNeeded, libmd }: +let + binstall = buildPackages.writeShellScript "binstall" (install-wrapper + ''@out@/bin/xinstall "''${args[@]}"''); +in mkDerivation { + pname = "xinstall-bootstrap"; + path = "usr.bin/xinstall"; + extraPaths = [ "contrib/mtree" "contrib/libc-vis" "lib/libnetbsd" ]; + nativeBuildInputs = [ + buildPackages.bsdSetupHook buildFreebsd.freebsdSetupHook + buildFreebsd.bmakeMinimal buildPackages.mandoc buildPackages.groff + ]; + patches = [ /${patchesRoot}/install-bootstrap-Makefile.patch ]; + postPatch = '' + ln -s $BSDSRCDIR/contrib/mtree/getid.c $BSDSRCDIR/usr.bin/xinstall/ + ln -s $BSDSRCDIR/contrib/mtree/mtree.h $BSDSRCDIR/usr.bin/xinstall/ + ln -s $BSDSRCDIR/contrib/mtree/extern.h $BSDSRCDIR/usr.bin/xinstall/ + ''; + skipIncludesPhase = true; + buildInputs = compatIfNeeded ++ [libmd]; + buildPhase = '' + make -C $BSDSRCDIR/usr.bin/xinstall STRIP=-s MK_WERROR=no TESTDIR=${builtins.placeholder "test"} BOOTSTRAPPING=1 + ''; + installPhase = '' + mkdir -p $out/bin + cp $BSDSRCDIR/usr.bin/xinstall/xinstall $out/bin/xinstall + cp ${binstall} $out/bin/binstall + chmod +x $out/bin/binstall + substituteInPlace $out/bin/binstall --subst-var out + ln -s ./binstall $out/bin/install + ''; + outputs = [ "out" ]; +} diff --git a/pkgs/os-specific/bsd/setup-hook.sh b/pkgs/os-specific/bsd/setup-hook.sh index e0afefcd73f7110..f9453708ab5db01 100644 --- a/pkgs/os-specific/bsd/setup-hook.sh +++ b/pkgs/os-specific/bsd/setup-hook.sh @@ -49,7 +49,6 @@ addMakeFlags() { makeFlags="LIBDIR=${!outputLib}/lib $makeFlags" makeFlags="SHLIBDIR=${!outputLib}/lib $makeFlags" makeFlags="SHAREDIR=${!outputLib}/share $makeFlags" - makeFlags="MANDIR=${!outputMan}/share/man $makeFlags" makeFlags="INFODIR=${!outputInfo}/share/info $makeFlags" makeFlags="DOCDIR=${!outputDoc}/share/doc $makeFlags" makeFlags="LOCALEDIR=${!outputLib}/share/locale $makeFlags" diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 7f79bb0112cfea5..220559cceacf0c4 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -197,7 +197,7 @@ with pkgs; pythonInterpreter = "${python3.withPackages (ps: [ ps.pyelftools ])}/bin/python"; autoPatchelfScript = ../build-support/setup-hooks/auto-patchelf.py; }; - meta.platforms = lib.platforms.linux; + meta.platforms = lib.platforms.linux ++ lib.platforms.freebsd; } ../build-support/setup-hooks/auto-patchelf.sh; tomato-c = callPackage ../applications/misc/tomato-c { }; @@ -16451,7 +16451,7 @@ with pkgs; # assumption is that or any later version is good. choose = platform: /**/ if platform.isDarwin then 16 - else if platform.isFreeBSD then 12 + else if platform.isFreeBSD then 16 else if platform.isAndroid then 12 else if platform.isLinux then 17 else if platform.isWasm then 16 @@ -22728,7 +22728,7 @@ with pkgs; # We also provide `libiconvReal`, which will always be a standalone libiconv, # just in case you want it regardless of platform. libiconv = - if lib.elem stdenv.hostPlatform.libc [ "glibc" "musl" "nblibc" "wasilibc" ] + if lib.elem stdenv.hostPlatform.libc [ "glibc" "musl" "nblibc" "wasilibc" "fblibc" ] then libcIconv (if stdenv.hostPlatform != stdenv.buildPlatform then libcCross else stdenv.cc.libc) @@ -41112,8 +41112,8 @@ with pkgs; name = "bsd-setup-hook"; } ../os-specific/bsd/setup-hook.sh; - freebsd = callPackage ../os-specific/bsd/freebsd { }; - freebsdCross = callPackage ../os-specific/bsd/freebsd { + freebsd = callPackages ../os-specific/bsd/freebsd { }; + freebsdCross = callPackages ../os-specific/bsd/freebsd { stdenv = crossLibcStdenv; }; diff --git a/pkgs/top-level/config.nix b/pkgs/top-level/config.nix index 3418a44e0f1327a..807f847b01a1eaf 100644 --- a/pkgs/top-level/config.nix +++ b/pkgs/top-level/config.nix @@ -69,6 +69,14 @@ let feature = "set `__contentAddressed` to true by default"; }; + freebsdBranch = mkMassRebuild { + type = types.nullOr types.str; + default = null; + description = '' + Default FreeBSD release to use for FreeBSD packages + ''; + }; + allowAliases = mkOption { type = types.bool; default = true; diff --git a/pkgs/top-level/stage.nix b/pkgs/top-level/stage.nix index 3b84026b469639b..e8d4cd4a4724503 100644 --- a/pkgs/top-level/stage.nix +++ b/pkgs/top-level/stage.nix @@ -57,9 +57,7 @@ in , # Non-GNU/Linux OSes are currently "impure" platforms, with their libc # outside of the store. Thus, GCC, GFortran, & co. must always look for files # in standard system directories (/usr/include, etc.) - noSysDirs ? stdenv.buildPlatform.system != "x86_64-freebsd" - && stdenv.buildPlatform.system != "i686-freebsd" - && stdenv.buildPlatform.system != "x86_64-solaris" + noSysDirs ? stdenv.buildPlatform.system != "x86_64-solaris" && stdenv.buildPlatform.system != "x86_64-kfreebsd-gnu" , # The configuration attribute set