freebsd: Cleanup, get ready to support version 14

* Extend libc

Include non-libc core libraries in the libc package. Many of these
mirror libraries present in glibc on linux, such as libgcc, libraries
used for iconv, and libraries used for reading kernel info (libkvm,
libprocstat, libmemstat).

Without this many packages outside the freebsd tree would need to be
modified to include standard dependencies which would already be on
the system for other packages.

* Mark FreeBSD as using LLVM

* Update default LLVM version FreeBSD

* Use patch monolith

The patchesRoot system combined with the fact that each derivation
will Request specific names of patches makes it very annoying to use
other FreeBSD source trees with nixpkgs. This new system allows
providing one Or more entire trees of patches whose contents will be
dynamically Parsed and only the relevant patches will be applied for
any one Derivation.

With this commit, the following knobs are available for specifying the
FreeBSD source:

- overriding `freebsd.versionInfo`, for picking another official
supported FreeBSD release.

- overriding `freebsd.source` for specifying a specific unpatched
FreeBSD source tree.

- overriding `freebsd.patches`, for specifying the patches to apply.

Co-Authored-by: Audrey Dutcher <audrey@rhelmot.io>
Co-Authored-by: John Ericson <John.Ericson@Obsidian.Systems>

+2
lib/systems/default.nix
···
&& 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"
+21 -7
pkgs/os-specific/bsd/freebsd/package-set.nix
···
}
// {
inherit sourceData patchesRoot versionData;
+
patches = ./patches/${self.versionData.revision};
# Keep the crawled portion of Nixpkgs finite.
buildFreebsd = lib.dontRecurseIntoAttrs buildFreebsd;
···
sha256 = "BpHqJfnGOeTE7tkFJBx0Wk8ryalmf4KNTit/Coh026E=";
};
-
compatIfNeeded = lib.optional (!stdenvNoCC.hostPlatform.isFreeBSD) self.compat;
+
compatIsNeeded = !stdenvNoCC.hostPlatform.isFreeBSD;
+
compatIfNeeded = lib.optional self.compatIsNeeded self.compat;
freebsd-lib = import ./lib {
version = lib.concatStringsSep "." (
map toString (
···
compat = self.callPackage ./pkgs/compat/package.nix {
inherit stdenv;
-
inherit (buildFreebsd) makeMinimal boot-install;
+
inherit (buildFreebsd) makeMinimal;
};
csu = self.callPackage ./pkgs/csu.nix {
···
inherit (self) include;
};
-
include = self.callPackage ./pkgs/include/package.nix {
-
inherit (buildFreebsd) makeMinimal install rpcgen;
-
};
+
include = self.callPackage ./pkgs/include/package.nix { inherit (buildFreebsd) rpcgen mtree; };
install = self.callPackage ./pkgs/install.nix {
inherit (buildFreebsd) makeMinimal;
-
inherit (self) mtree libnetbsd;
+
inherit (self) libmd libnetbsd;
};
libc = self.callPackage ./pkgs/libc/package.nix {
···
install
gencat
rpcgen
+
mkcsmapper
+
mkesdb
;
inherit (self) csu include;
};
libnetbsd = self.callPackage ./pkgs/libnetbsd/package.nix { inherit (buildFreebsd) makeMinimal; };
+
libmd = self.callPackage ./pkgs/libmd.nix { inherit (buildFreebsd) makeMinimal; };
+
mkDerivation = self.callPackage ./pkgs/mkDerivation.nix {
inherit stdenv;
-
inherit (buildFreebsd) makeMinimal install tsort;
+
inherit (buildFreebsd)
+
freebsdSetupHook
+
makeMinimal
+
install
+
tsort
+
lorder
+
;
};
makeMinimal = self.callPackage ./pkgs/makeMinimal.nix { inherit (self) make; };
+
+
mtree = self.callPackage ./pkgs/mtree.nix { inherit (self) libnetbsd libmd; };
+
+
tsort = self.callPackage ./pkgs/tsort.nix { inherit (buildFreebsd) makeMinimal install; };
}
+13
pkgs/os-specific/bsd/freebsd/patches/13.1/mtree-Makefile.patch
···
+
--- 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
pkgs/os-specific/bsd/freebsd/patches/13.1/rpcgen-glibc-hack.patch pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/rpcgen-glibc-hack.patch
+17 -7
pkgs/os-specific/bsd/freebsd/pkgs/compat/package.nix
···
lib,
stdenv,
mkDerivation,
-
patchesRoot,
+
versionData,
bsdSetupHook,
freebsdSetupHook,
makeMinimal,
···
inherit (freebsd-lib) mkBsdArch;
in
-
mkDerivation rec {
+
mkDerivation {
pname = "compat";
path = "tools/build";
extraPaths =
···
"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"
···
"lib/libcapsicum"
"lib/libcasper"
-
];
+
"lib/libmd"
-
patches = [
-
/${patchesRoot}/compat-install-dirs.patch
-
/${patchesRoot}/compat-fix-typedefs-locations.patch
-
];
+
# idk bro
+
"sys/sys/kbio.h"
+
];
preBuild =
''
···
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
cp --no-preserve=mode -r cross-build/include/darwin/* $out/1-include
'';
+
+
# Compat is for making other platforms look like FreeBSD (e.g. to
+
# build build-time dependencies for building FreeBSD packages). It is
+
# not needed when building for FreeBSD.
+
meta.broken = stdenv.hostPlatform.isFreeBSD;
}
+1
pkgs/os-specific/bsd/freebsd/pkgs/csu.nix
···
}:
mkDerivation {
+
isStatic = true;
path = "lib/csu";
extraPaths = [
"lib/Makefile.inc"
+6 -17
pkgs/os-specific/bsd/freebsd/pkgs/ctfconvert.nix
···
{
lib,
-
stdenv,
mkDerivation,
-
bsdSetupHook,
-
freebsdSetupHook,
-
makeMinimal,
-
install,
-
mandoc,
-
groff,
compatIfNeeded,
-
libelf,
libdwarf,
zlib,
libspl,
···
];
OPENSOLARIS_USR_DISTDIR = "$(SRCTOP)/cddl/contrib/opensolaris";
OPENSOLARIS_SYS_DISTDIR = "$(SRCTOP)/sys/cddl/contrib/opensolaris";
-
nativeBuildInputs = [
-
bsdSetupHook
-
freebsdSetupHook
-
makeMinimal
-
install
-
mandoc
-
groff
-
# flex byacc file2c
+
makeFlags = [
+
"STRIP=-s"
+
"MK_WERROR=no"
+
"MK_TESTS=no"
];
+
buildInputs = compatIfNeeded ++ [
-
libelf
libdwarf
zlib
libspl
];
+
meta.license = lib.licenses.cddl;
}
+23
pkgs/os-specific/bsd/freebsd/pkgs/filterSource.nix
···
+
{
+
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 ]; } ''
+
rsync -a -r --files-from=${filterText} ${source}/ $out
+
''
+11
pkgs/os-specific/bsd/freebsd/pkgs/freebsdSetupHook/setup-hook.sh
···
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)
+5 -21
pkgs/os-specific/bsd/freebsd/pkgs/include/package.nix
···
{
lib,
mkDerivation,
-
patchesRoot,
buildPackages,
-
bsdSetupHook,
-
freebsdSetupHook,
-
makeMinimal,
-
install,
-
mandoc,
-
groff,
-
rsync, # , nbperf
rpcgen,
+
mtree,
}:
mkDerivation {
+
isStatic = true;
path = "include";
extraPaths = [
···
"sys"
];
-
nativeBuildInputs = [
-
bsdSetupHook
-
freebsdSetupHook
-
makeMinimal
-
install
-
mandoc
-
groff
-
rsync # nbperf
+
extraNativeBuildInputs = [
rpcgen
-
-
# HACK use NetBSD's for now
-
buildPackages.netbsd.mtree
+
mtree
];
-
-
patches = [ /${patchesRoot}/no-perms-BSD.include.dist.patch ];
# The makefiles define INCSDIR per subdirectory, so we have to set
# something else on the command line so those definitions aren't
···
sed -i -E \
-e 's_/usr/include_''${INCSDIR0}_' \
{} \;
+
sed -E -i -e "/_PATH_LOGIN/d" $BSDSRCDIR/include/paths.h
'';
makeFlags = [ "RPCGEN_CPP=${buildPackages.stdenv.cc.cc}/bin/cpp" ];
+12 -8
pkgs/os-specific/bsd/freebsd/pkgs/install.nix
···
mkDerivation,
writeShellScript,
freebsd-lib,
-
mtree,
bsdSetupHook,
freebsdSetupHook,
makeMinimal,
···
in
mkDerivation {
path = "usr.bin/xinstall";
-
extraPaths = [ mtree.path ];
+
extraPaths = [ "contrib/mtree" ];
nativeBuildInputs = [
bsdSetupHook
freebsdSetupHook
···
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";
+
makeFlags =
+
[
+
"STRIP=-s" # flag to install, not command
+
"MK_WERROR=no"
+
"TESTSDIR=${builtins.placeholder "test"}"
+
]
+
++ lib.optionals (stdenv.hostPlatform == stdenv.buildPlatform) [
+
"BOOTSTRAPPING=1"
+
"INSTALL=boot-install"
+
];
postInstall = ''
-
install -D -m 0550 ${binstall} $out/bin/binstall
+
install -C -m 0550 ${binstall} $out/bin/binstall
substituteInPlace $out/bin/binstall --subst-var out
mv $out/bin/install $out/bin/xinstall
ln -s ./binstall $out/bin/install
+200 -72
pkgs/os-specific/bsd/freebsd/pkgs/libc/package.nix
···
{
lib,
+
buildPackages,
stdenv,
mkDerivation,
-
patchesRoot,
bsdSetupHook,
freebsdSetupHook,
···
byacc,
gencat,
rpcgen,
+
mkcsmapper,
+
mkesdb,
csu,
include,
+
versionData,
}:
-
mkDerivation rec {
+
mkDerivation {
+
isStatic = true;
pname = "libc";
path = "lib/libc";
-
extraPaths = [
-
"etc/group"
-
"etc/master.passwd"
-
"etc/shells"
-
"lib/libmd"
-
"lib/libutil"
-
"lib/msun"
-
"sys/kern"
-
"sys/libkern"
-
"sys/sys"
-
"sys/crypto/chacha20"
-
"include/rpcsvc"
-
"contrib/jemalloc"
-
"contrib/gdtoa"
-
"contrib/libc-pwcache"
-
"contrib/libc-vis"
-
"contrib/tzcode/stdtime"
+
extraPaths =
+
[
+
"lib/libc_nonshared"
+
"etc/group"
+
"etc/master.passwd"
+
"etc/shells"
+
"lib/libmd"
+
"lib/libutil"
+
"lib/msun"
+
"sys/kern"
+
"sys/libkern"
+
"sys/sys"
+
"sys/crypto/chacha20"
+
"include/rpcsvc"
+
"contrib/jemalloc"
+
"contrib/gdtoa"
+
"contrib/libc-pwcache"
+
"contrib/libc-vis"
+
"contrib/tzcode/stdtime"
-
# libthr
-
"lib/libthr"
-
"lib/libthread_db"
-
"libexec/rtld-elf"
+
# libthr
+
"lib/libthr"
+
"lib/libthread_db"
+
"libexec/rtld-elf"
+
"lib/csu/common/crtbrand.S"
+
"lib/csu/common/notes.h"
-
# librpcsvc
-
"lib/librpcsvc"
+
# librpcsvc
+
"lib/librpcsvc"
-
# librt
-
"lib/librt"
+
# librt
+
"lib/librt"
-
# libcrypt
-
"lib/libcrypt"
-
"lib/libmd"
-
"sys/crypto/sha2"
-
];
+
# libcrypt
+
"lib/libcrypt"
+
"lib/libmd"
+
"sys/crypto/sha2"
+
"sys/crypto/skein"
-
patches = [
-
# Hack around broken propogating MAKEFLAGS to submake, just inline logic
-
/${patchesRoot}/libc-msun-arch-subdir.patch
+
# 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"
-
# Don't force -lcompiler-rt, we don't actually call it that
-
/${patchesRoot}/libc-no-force--lcompiler-rt.patch
+
# terminfo
+
"lib/ncurses"
+
"contrib/ncurses"
+
"lib/Makefile.inc"
+
]
+
++ lib.optionals (stdenv.hostPlatform.isx86_32) [ "lib/libssp_nonshared" ]
+
++ [
+
"lib/libexecinfo"
+
"contrib/libexecinfo"
-
# Fix extra include dir to get rpcsvc headers.
-
/${patchesRoot}/librpcsvc-include-subdir.patch
-
];
+
"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"
+
];
postPatch = ''
substituteInPlace $COMPONENT_PATH/Makefile --replace '.include <src.opts.mk>' ""
+
+
substituteInPlace $BSDSRCDIR/include/paths.h \
+
--replace '/usr/lib/i18n' '${builtins.placeholder "out"}/lib/i18n' \
+
--replace '/usr/share/i18n' '${builtins.placeholder "out"}/share/i18n'
'';
nativeBuildInputs = [
···
byacc
gencat
rpcgen
+
mkcsmapper
+
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
···
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";
···
MK_MALLOC_PRODUCTION = "yes";
MK_TESTS = "no";
+
MACHINE_ABI = "";
+
MK_DETECT_TZ_CHANGES = "no";
+
MK_MACHDEP_OPTIMIZATIONS = "yes";
+
MK_ASAN = "no";
+
MK_UBSAN = "no";
-
postInstall = ''
-
pushd ${include}
-
find . -type d -exec mkdir -p $out/\{} \;
-
find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
-
popd
+
NO_FSCHG = "yes";
-
pushd ${csu}
-
find . -type d -exec mkdir -p $out/\{} \;
-
find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
-
popd
+
preBuild = lib.optionalString (stdenv.hostPlatform.isx86_32) ''
+
make -C $BSDSRCDIR/lib/libssp_nonshared $makeFlags
+
make -C $BSDSRCDIR/lib/libssp_nonshared $makeFlags install
+
'';
-
sed -i -e 's| [^ ]*/libc_nonshared.a||' $out/lib/libc.so
+
postInstall =
+
''
+
pushd ${include}
+
find . -type d -exec mkdir -p $out/\{} \;
+
find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
+
popd
-
$CC -nodefaultlibs -lgcc -shared -o $out/lib/libgcc_s.so
+
pushd ${csu}
+
find . -type d -exec mkdir -p $out/\{} \;
+
find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
+
popd
-
NIX_CFLAGS_COMPILE+=" -B$out/lib"
-
NIX_CFLAGS_COMPILE+=" -I$out/include"
-
NIX_LDFLAGS+=" -L$out/lib"
+
mkdir $BSDSRCDIR/lib/libcompiler_rt/i386
+
make -C $BSDSRCDIR/lib/libcompiler_rt $makeFlags
+
make -C $BSDSRCDIR/lib/libcompiler_rt $makeFlags install
-
make -C $BSDSRCDIR/lib/libthr $makeFlags
-
make -C $BSDSRCDIR/lib/libthr $makeFlags install
+
make -C $BSDSRCDIR/lib/libgcc_eh $makeFlags
+
make -C $BSDSRCDIR/lib/libgcc_eh $makeFlags install
-
make -C $BSDSRCDIR/lib/msun $makeFlags
-
make -C $BSDSRCDIR/lib/msun $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
-
make -C $BSDSRCDIR/lib/librpcsvc $makeFlags
-
make -C $BSDSRCDIR/lib/librpcsvc $makeFlags install
+
NIX_CFLAGS_COMPILE+=" -B$out/lib"
+
NIX_CFLAGS_COMPILE+=" -I$out/include"
+
NIX_LDFLAGS+=" -L$out/lib"
-
make -C $BSDSRCDIR/lib/libutil $makeFlags
-
make -C $BSDSRCDIR/lib/libutil $makeFlags install
+
make -C $BSDSRCDIR/lib/libc_nonshared $makeFlags
+
make -C $BSDSRCDIR/lib/libc_nonshared $makeFlags install
-
make -C $BSDSRCDIR/lib/librt $makeFlags
-
make -C $BSDSRCDIR/lib/librt $makeFlags install
+
mkdir $BSDSRCDIR/lib/libmd/sys
+
make -C $BSDSRCDIR/lib/libmd $makeFlags
+
make -C $BSDSRCDIR/lib/libmd $makeFlags install
-
make -C $BSDSRCDIR/lib/libcrypt $makeFlags
-
make -C $BSDSRCDIR/lib/libcrypt $makeFlags install
+
make -C $BSDSRCDIR/lib/libthr $makeFlags
+
make -C $BSDSRCDIR/lib/libthr $makeFlags install
+
+
make -C $BSDSRCDIR/lib/msun $makeFlags
+
make -C $BSDSRCDIR/lib/msun $makeFlags install
+
+
make -C $BSDSRCDIR/lib/librpcsvc $makeFlags
+
make -C $BSDSRCDIR/lib/librpcsvc $makeFlags install
+
+
make -C $BSDSRCDIR/lib/libutil $makeFlags
+
make -C $BSDSRCDIR/lib/libutil $makeFlags install
+
+
make -C $BSDSRCDIR/lib/librt $makeFlags
+
make -C $BSDSRCDIR/lib/librt $makeFlags install
+
+
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"
+
];
}
+3 -20
pkgs/os-specific/bsd/freebsd/pkgs/libdwarf.nix
···
{
-
lib,
-
stdenv,
mkDerivation,
-
bsdSetupHook,
-
freebsdSetupHook,
-
makeMinimal,
-
install,
-
mandoc,
-
groff,
m4,
compatIfNeeded,
-
libelf,
+
zlib,
}:
mkDerivation {
···
"sys/sys/elf64.h"
"sys/sys/elf_common.h"
];
-
nativeBuildInputs = [
-
bsdSetupHook
-
freebsdSetupHook
-
makeMinimal
-
install
-
mandoc
-
groff
-
-
m4
-
];
-
buildInputs = compatIfNeeded ++ [ libelf ];
+
extraNativeBuildInputs = [ m4 ];
+
buildInputs = compatIfNeeded ++ [ zlib ];
MK_TESTS = "no";
}
-35
pkgs/os-specific/bsd/freebsd/pkgs/libelf.nix
···
-
{
-
lib,
-
stdenv,
-
mkDerivation,
-
bsdSetupHook,
-
freebsdSetupHook,
-
makeMinimal,
-
install,
-
mandoc,
-
groff,
-
m4,
-
}:
-
-
mkDerivation {
-
path = "lib/libelf";
-
extraPaths = [
-
"contrib/elftoolchain/libelf"
-
"contrib/elftoolchain/common"
-
"sys/sys/elf32.h"
-
"sys/sys/elf64.h"
-
"sys/sys/elf_common.h"
-
];
-
BOOTSTRAPPING = !stdenv.isFreeBSD;
-
nativeBuildInputs = [
-
bsdSetupHook
-
freebsdSetupHook
-
makeMinimal
-
install
-
mandoc
-
groff
-
-
m4
-
];
-
MK_TESTS = "no";
-
}
+49
pkgs/os-specific/bsd/freebsd/pkgs/libmd.nix
···
+
{
+
lib,
+
stdenv,
+
mkDerivation,
+
freebsdSetupHook,
+
bsdSetupHook,
+
makeMinimal,
+
}:
+
mkDerivation {
+
path = "lib/libmd";
+
extraPaths = [
+
"sys/sys/md5.h"
+
"sys/crypto/sha2"
+
"sys/crypto/skein"
+
];
+
nativeBuildInputs = [
+
makeMinimal
+
bsdSetupHook
+
freebsdSetupHook
+
];
+
+
makeFlags = [
+
"STRIP=-s" # flag to install, not command
+
"RELDIR=."
+
] ++ lib.optional (!stdenv.hostPlatform.isFreeBSD) "MK_WERROR=no";
+
+
preBuild = ''
+
mkdir sys
+
'';
+
+
installPhase = ''
+
# libmd is used by install. do it yourself!
+
mkdir -p $out/include $out/lib $man/share/man
+
cp libmd.a $out/lib/libmd.a
+
for f in $(make $makeFlags -V INCS); do
+
if [ -e "$f" ]; then cp "$f" "$out/include/$f"; fi
+
if [ -e "$BSDSRCDIR/sys/crypto/sha2/$f" ]; then cp "$BSDSRCDIR/sys/crypto/sha2/$f" "$out/include/$f"; fi
+
if [ -e "$BSDSRCDIR/sys/crypto/skein/$f" ]; then cp "$BSDSRCDIR/sys/crypto/skein/$f" "$out/include/$f"; fi
+
done
+
for f in $(make $makeFlags -V MAN); do
+
cp "$f" "$man/share/man/$f"
+
done
+
'';
+
+
outputs = [
+
"out"
+
"man"
+
];
+
}
-7
pkgs/os-specific/bsd/freebsd/pkgs/libnetbsd/package.nix
···
lib,
stdenv,
mkDerivation,
-
patchesRoot,
bsdSetupHook,
freebsdSetupHook,
makeMinimal,
···
groff,
boot-install,
install,
-
compatIfNeeded,
}:
mkDerivation {
···
groff
(if stdenv.hostPlatform == stdenv.buildPlatform then boot-install else install)
];
-
patches = lib.optionals (!stdenv.hostPlatform.isFreeBSD) [
-
/${patchesRoot}/libnetbsd-do-install.patch
-
#/${patchesRoot}/libnetbsd-define-__va_list.patch
-
];
makeFlags = [
"STRIP=-s" # flag to install, not command
"MK_WERROR=no"
] ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) "INSTALL=boot-install";
-
buildInputs = compatIfNeeded;
}
+12 -11
pkgs/os-specific/bsd/freebsd/pkgs/libspl.nix
···
mkDerivation {
path = "cddl/lib/libspl";
extraPaths = [
-
"sys/contrib/openzfs/lib/libspl"
-
"sys/contrib/openzfs/include"
-
"cddl/compat/opensolaris/include"
+
"sys/contrib/openzfs/include"
+
"sys/contrib/openzfs/lib/libspl"
"sys/contrib/openzfs/module/icp/include"
-
"sys/modules/zfs"
+
"sys/modules/zfs/zfs_config.h"
];
-
# nativeBuildInputs = [
-
# bsdSetupHook freebsdSetupHook
-
# makeMinimal install mandoc groff
+
+
# Without a prefix it will try to put object files in nonexistant directories
+
preBuild = ''
+
export MAKEOBJDIRPREFIX=$TMP/obj
+
'';
-
# flex byacc file2c
-
# ];
-
# buildInputs = compatIfNeeded ++ [ libnv libsbuf ];
-
meta.license = lib.licenses.cddl;
+
meta = with lib; {
+
platform = platforms.freebsd;
+
license = licenses.cddl;
+
};
}
-1
pkgs/os-specific/bsd/freebsd/pkgs/libutil.nix
···
mkDerivation {
path = "lib/libutil";
extraPaths = [ "lib/libc/gen" ];
-
clangFixup = true;
MK_TESTS = "no";
}
+1 -2
pkgs/os-specific/bsd/freebsd/pkgs/lorder.nix
···
bsdSetupHook,
freebsdSetupHook,
}:
-
-
mkDerivation rec {
+
mkDerivation {
path = "usr.bin/lorder";
noCC = true;
dontBuild = true;
+3 -1
pkgs/os-specific/bsd/freebsd/pkgs/makeMinimal.nix
···
freebsdSetupHook,
}:
-
mkDerivation rec {
+
mkDerivation {
inherit (make) path;
buildInputs = [ ];
···
patchShebangs configure
${make.postPatch}
'';
+
+
configureFlags = [ "--with-filemon=no" ];
buildPhase = ''
runHook preBuild
+87 -24
pkgs/os-specific/bsd/freebsd/pkgs/mkDerivation.nix
···
lib,
stdenv,
stdenvNoCC,
+
versionData,
+
writeText,
+
patches,
compatIfNeeded,
-
runCommand,
-
rsync,
freebsd-lib,
-
source,
+
filterSource,
bsdSetupHook,
freebsdSetupHook,
makeMinimal,
···
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)}";
+
src = filterSource {
+
inherit pname;
+
inherit (attrs) path;
+
extraPaths = attrs.extraPaths or [ ];
+
};
nativeBuildInputs = [
bsdSetupHook
···
tsort
lorder
mandoc
-
groff # statHook
-
];
+
groff
+
] ++ attrs.extraNativeBuildInputs or [ ];
buildInputs = compatIfNeeded;
HOST_SH = stdenv'.shell;
···
strictDeps = true;
-
meta = with lib; {
-
maintainers = with maintainers; [ ericson2314 ];
-
platforms = platforms.unix;
-
license = licenses.bsd2;
-
};
+
meta =
+
with lib;
+
{
+
maintainers = with maintainers; [
+
rhelmot
+
artemist
+
];
+
platforms = platforms.unix;
+
license = licenses.bsd2;
+
}
+
// attrs.meta or { };
}
// lib.optionalAttrs stdenv'.hasCC {
# TODO should CC wrapper set this?
···
dontBuild = true;
}
// attrs
+
// lib.optionalAttrs (stdenv'.hasCC && stdenv'.cc.isClang or false && attrs.clangFixup or true) {
+
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"
+
export NIX_LDFLAGS="$NIX_LDFLAGS --undefined-version"
+
''
+
+ (attrs.preBuild or "");
+
}
+
// {
+
patches =
+
let
+
isDir =
+
file:
+
let
+
base = baseNameOf file;
+
type = (builtins.readDir (dirOf file)).${base} or null;
+
in
+
file == /. || type == "directory";
+
consolidatePatches =
+
patches:
+
if (lib.isDerivation patches) then
+
[ patches ]
+
else if (builtins.isPath patches) then
+
(if (isDir patches) then (lib.filesystem.listFilesRecursive patches) else [ patches ])
+
else if (builtins.isList patches) then
+
(lib.flatten (builtins.map consolidatePatches patches))
+
else
+
throw "Bad patches - must be path or derivation or list thereof";
+
consolidated = consolidatePatches patches;
+
splitPatch =
+
patchFile:
+
let
+
foldFunc =
+
a: b:
+
if (lib.strings.hasPrefix "--- " b) then
+
(a ++ [ [ b ] ])
+
else
+
((lib.lists.init a) ++ (lib.lists.singleton ((lib.lists.last a) ++ [ b ])));
+
partitionedPatches' = lib.lists.foldl foldFunc [ [ ] ] (
+
lib.strings.splitString "\n" (builtins.readFile patchFile)
+
);
+
partitionedPatches =
+
if (builtins.length partitionedPatches' > 1) then
+
(lib.lists.drop 1 partitionedPatches')
+
else
+
(throw "${patchFile} does not seem to be a unified patch (diff -u). this is required for FreeBSD.");
+
filterFunc =
+
patchLines:
+
let
+
prefixedPath = builtins.elemAt (builtins.split " |\t" (builtins.elemAt patchLines 1)) 2;
+
unfixedPath = lib.path.subpath.join (lib.lists.drop 1 (lib.path.subpath.components prefixedPath));
+
in
+
lib.lists.any (included: lib.path.hasPrefix (/. + ("/" + included)) (/. + ("/" + unfixedPath))) (
+
(attrs.extraPaths or [ ]) ++ [ attrs.path ]
+
);
+
filteredLines = builtins.filter filterFunc partitionedPatches;
+
derive = patchLines: writeText "freebsd-patch" (lib.concatLines patchLines);
+
derivedPatches = builtins.map derive filteredLines;
+
in
+
derivedPatches;
+
picked = lib.lists.concatMap splitPatch consolidated;
+
in
+
picked ++ attrs.patches or [ ];
+
}
)
)
+22
pkgs/os-specific/bsd/freebsd/pkgs/mkcsmapper.nix
···
+
{
+
stdenv,
+
mkDerivation,
+
byacc,
+
flex,
+
}:
+
+
mkDerivation {
+
path = "usr.bin/mkcsmapper";
+
+
extraPaths = [
+
"lib/libc/iconv"
+
"lib/libiconv_modules/mapper_std"
+
];
+
+
BOOTSTRAPPING = !stdenv.hostPlatform.isFreeBSD;
+
+
extraNativeBuildInputs = [
+
byacc
+
flex
+
];
+
}
+19
pkgs/os-specific/bsd/freebsd/pkgs/mkesdb.nix
···
+
{
+
stdenv,
+
mkDerivation,
+
byacc,
+
flex,
+
}:
+
+
mkDerivation {
+
path = "usr.bin/mkesdb";
+
+
extraPaths = [ "lib/libc/iconv" ];
+
+
BOOTSTRAPPING = !stdenv.hostPlatform.isFreeBSD;
+
+
extraNativeBuildInputs = [
+
byacc
+
flex
+
];
+
}
+35 -2
pkgs/os-specific/bsd/freebsd/pkgs/mtree.nix
···
-
{ mkDerivation, mknod }:
+
{
+
lib,
+
stdenv,
+
mkDerivation,
+
compatIfNeeded,
+
compatIsNeeded,
+
libmd,
+
libnetbsd,
+
libutil,
+
}:
mkDerivation {
path = "contrib/mtree";
-
extraPaths = [ mknod.path ];
+
extraPaths = [ "contrib/mknod" ];
+
buildInputs =
+
compatIfNeeded
+
++ [
+
libmd
+
libnetbsd
+
]
+
++ lib.optional (stdenv.isFreeBSD) libutil;
+
+
postPatch = ''
+
ln -s $BSDSRCDIR/contrib/mknod/*.c $BSDSRCDIR/contrib/mknod/*.h $BSDSRCDIR/contrib/mtree
+
'';
+
+
preBuild = ''
+
export NIX_LDFLAGS="$NIX_LDFLAGS ${
+
toString (
+
[
+
"-lmd"
+
"-lnetbsd"
+
]
+
++ lib.optional compatIsNeeded "-legacy"
+
++ lib.optional stdenv.isFreeBSD "-lutil"
+
)
+
}"
+
'';
}
+2 -2
pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/package.nix
···
patchesRoot,
}:
-
mkDerivation rec {
+
mkDerivation {
path = "usr.bin/rpcgen";
patches = lib.optionals (stdenv.hostPlatform.libc == "glibc") [
# `WUNTRACED` is defined privately `bits/waitflags.h` in glibc.
···
#
# This hacks around this by manually including `WUNTRACED` until
# the problem is fixed properly in glibc.
-
/${patchesRoot}/rpcgen-glibc-hack.patch
+
./rpcgen-glibc-hack.patch
];
}
+1 -2
pkgs/os-specific/bsd/freebsd/pkgs/sed.nix
···
-
{ mkDerivation, source }:
+
{ mkDerivation }:
mkDerivation {
path = "usr.bin/sed";
-
TESTSRC = "${source}/contrib/netbsd-tests";
MK_TESTS = "no";
}
-1
pkgs/os-specific/bsd/freebsd/pkgs/source.nix
···
# 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
owner = "freebsd";
repo = "freebsd-src";
inherit (sourceData) rev hash;
+1 -8
pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix
···
stdenv,
mkDerivation,
freebsd-lib,
-
patchesRoot,
buildPackages,
bsdSetupHook,
freebsdSetupHook,
···
file2c,
gawk,
uudecode,
-
xargs-j, # , ctfconvert
+
xargs-j,
}:
mkDerivation (
···
gawk
uudecode
xargs-j
-
#ctfconvert
-
];
-
-
patches = [
-
/${patchesRoot}/sys-gnu-date.patch
-
/${patchesRoot}/sys-no-explicit-intrinsics-dep.patch
];
# --dynamic-linker /red/herring is used when building the kernel.
+7
pkgs/os-specific/bsd/freebsd/pkgs/tsort.nix
···
{
+
lib,
mkDerivation,
bsdSetupHook,
freebsdSetupHook,
···
mkDerivation {
path = "usr.bin/tsort";
+
extraPaths = [ ];
+
outputs = [ "out" ];
+
MK_TESTS = "no";
+
makeFlags = [
+
"STRIP=-s" # flag to install, not command
+
];
nativeBuildInputs = [
bsdSetupHook
freebsdSetupHook
+1
pkgs/os-specific/bsd/netbsd/pkgs/netbsdSetupHook/setup-hook.sh
···
addNetBSDMakeFlags() {
makeFlags="INCSDIR=${!outputDev}/include $makeFlags"
+
makeFlags="MANDIR=${!outputMan}/share/man $makeFlags"
}
postUnpackHooks+=(mergeNetBSDSourceDir)
-1
pkgs/os-specific/bsd/setup-hook.sh
···
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"
+3 -3
pkgs/top-level/all-packages.nix
···
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 { };
···
# 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
···
# 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)
+1 -3
pkgs/top-level/stage.nix
···
, # 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