diff --git a/pkgs/os-specific/bsd/freebsd/package-set.nix b/pkgs/os-specific/bsd/freebsd/package-set.nix index 657334370e51..ee6480a660be 100644 --- a/pkgs/os-specific/bsd/freebsd/package-set.nix +++ b/pkgs/os-specific/bsd/freebsd/package-set.nix @@ -8,6 +8,7 @@ buildFreebsd, patchesRoot, writeText, + buildPackages, }: self: @@ -64,16 +65,32 @@ lib.packagesFromDirectoryRecursive { inherit (self) libmd libnetbsd; }; - libc = self.callPackage ./pkgs/libc/package.nix { + libcMinimal = self.callPackage ./pkgs/libcMinimal.nix { inherit (buildFreebsd) - makeMinimal - install - gencat rpcgen - mkcsmapper - mkesdb + gencat ; - inherit (self) csu include; + inherit (buildPackages) + flex + byacc + ; + }; + + libc = self.callPackage ./pkgs/libc/package.nix { + inherit (self) libcMinimal librpcsvc libelf; + }; + + librpcsvc = self.callPackage ./pkgs/librpcsvc.nix { + inherit (buildFreebsd) rpcgen; + }; + + i18n = self.callPackage ./pkgs/i18n.nix { inherit (buildFreebsd) mkcsmapper mkesdb; }; + + libelf = self.callPackage ./pkgs/libelf.nix { inherit (buildPackages) m4; }; + + rtld-elf = self.callPackage ./pkgs/rtld-elf.nix { + inherit (buildFreebsd) rpcgen; + inherit (buildPackages) flex byacc; }; libnetbsd = self.callPackage ./pkgs/libnetbsd/package.nix { inherit (buildFreebsd) makeMinimal; }; diff --git a/pkgs/os-specific/bsd/freebsd/patches/14.1/bsd-lib-mk-force-static.patch b/pkgs/os-specific/bsd/freebsd/patches/14.1/bsd-lib-mk-force-static.patch deleted file mode 100644 index 04446ce32b5e..000000000000 --- a/pkgs/os-specific/bsd/freebsd/patches/14.1/bsd-lib-mk-force-static.patch +++ /dev/null @@ -1,81 +0,0 @@ -From 197b10de54b53a089ad549f2e00787b4fa719210 Mon Sep 17 00:00:00 2001 -From: Artemis Tosini -Date: Sat, 2 Nov 2024 07:50:13 +0000 -Subject: [PATCH] HACK: bsd.lib.mk: Treat empty SHLIB_NAME as nonexistant - -Unsetting SHLIB_NAME in nix package definitions is a pain -but we can easily set it to be empty. This is useful when -building static libraries without unneeded static libraries. ---- - share/mk/bsd.lib.mk | 14 +++++++------- - 1 file changed, 7 insertions(+), 7 deletions(-) - -diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk -index 5f328d5378ca..89d16dc6fa41 100644 ---- a/share/mk/bsd.lib.mk -+++ b/share/mk/bsd.lib.mk -@@ -242,7 +242,7 @@ PO_FLAG=-pg - _LIBDIR:=${LIBDIR} - _SHLIBDIR:=${SHLIBDIR} - --.if defined(SHLIB_NAME) -+.if defined(SHLIB_NAME) && !empty(SHLIB_NAME) - .if ${MK_DEBUG_FILES} != "no" - SHLIB_NAME_FULL=${SHLIB_NAME}.full - # Use ${DEBUGDIR} for base system debug files, else .debug subdirectory -@@ -277,7 +277,7 @@ LDFLAGS+= -Wl,--undefined-version - .endif - .endif - --.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME) -+.if defined(LIB) && !empty(LIB) || (defined(SHLIB_NAME) && !empty(SHLIB_NAME)) - OBJS+= ${SRCS:N*.h:${OBJS_SRCS_FILTER:ts:}:S/$/.o/} - BCOBJS+= ${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.bco/g} - LLOBJS+= ${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.llo/g} -@@ -320,14 +320,14 @@ lib${LIB_PRIVATE}${LIB}.ll: ${LLOBJS} - CLEANFILES+= lib${LIB_PRIVATE}${LIB}.bc lib${LIB_PRIVATE}${LIB}.ll - .endif - --.if defined(SHLIB_NAME) || \ -+.if (defined(SHLIB_NAME) && !empty(SHLIB_NAME)) || \ - defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) - SOBJS+= ${OBJS:.o=.pico} - DEPENDOBJS+= ${SOBJS} - CLEANFILES+= ${SOBJS} - .endif - --.if defined(SHLIB_NAME) -+.if defined(SHLIB_NAME) && !empty(SHLIB_NAME) - _LIBS+= ${SHLIB_NAME} - - SOLINKOPTS+= -shared -Wl,-x -@@ -435,7 +435,7 @@ all: all-man - CLEANFILES+= ${_LIBS} - - _EXTRADEPEND: --.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME) -+.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME) && !empty(SHLIB_NAME) - .if defined(DPADD) && !empty(DPADD) - echo ${SHLIB_NAME_FULL}: ${DPADD} >> ${DEPENDFILE} - .endif -@@ -501,7 +501,7 @@ _libinstall: - ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}_p.a ${DESTDIR}${_LIBDIR}/ - .endif - .endif --.if defined(SHLIB_NAME) -+.if defined(SHLIB_NAME) && !empty(SHLIB_NAME) - ${INSTALL} ${TAG_ARGS} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ - ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \ - ${SHLIB_NAME} ${DESTDIR}${_SHLIBDIR}/ -@@ -588,7 +588,7 @@ OBJS_DEPEND_GUESS+= ${SRCS:M*.h} - OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.po+= ${_S} - .endfor - .endif --.if defined(SHLIB_NAME) || \ -+.if (defined(SHLIB_NAME) && !empty(SHLIB_NAME)) || \ - defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) - .for _S in ${SRCS:N*.[hly]} - OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.pico+= ${_S} --- -2.46.1 - diff --git a/pkgs/os-specific/bsd/freebsd/patches/14.1/libelf-bootstrapping.patch b/pkgs/os-specific/bsd/freebsd/patches/14.1/libelf-bootstrapping.patch new file mode 100644 index 000000000000..96c509b290a0 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/patches/14.1/libelf-bootstrapping.patch @@ -0,0 +1,13 @@ +diff --git a/lib/libelf/Makefile b/lib/libelf/Makefile +index c15ce2798a91..d6d8754e2b4f 100644 +--- a/lib/libelf/Makefile ++++ b/lib/libelf/Makefile +@@ -80,7 +80,7 @@ INCS= libelf.h gelf.h + SRCS+= sys/elf32.h sys/elf64.h sys/elf_common.h + + # Allow bootstrapping elftoolchain on Linux: +-.if defined(BOOTSTRAPPING) && ${.MAKE.OS} == "Linux" ++.if defined(BOOTSTRAPPING) + native-elf-format.h: + ${ELFTCDIR}/common/native-elf-format > ${.TARGET} || rm ${.TARGET} + SRCS+= native-elf-format.h diff --git a/pkgs/os-specific/bsd/freebsd/patches/14.1/mk.patch b/pkgs/os-specific/bsd/freebsd/patches/14.1/mk.patch new file mode 100644 index 000000000000..51f772ded2ee --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/patches/14.1/mk.patch @@ -0,0 +1,154 @@ +diff --git a/share/mk/bsd.incs.mk b/share/mk/bsd.incs.mk +index df4cf4641141..a87c7f9db03a 100644 +--- a/share/mk/bsd.incs.mk ++++ b/share/mk/bsd.incs.mk +@@ -63,8 +63,8 @@ stage_includes: stage_as.${header:T} + + installincludes: _${group}INS_${header:T} + _${group}INS_${header:T}: ${header} +- ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -C -o ${${group}OWN_${.ALLSRC:T}} \ +- -g ${${group}GRP_${.ALLSRC:T}} -m ${${group}MODE_${.ALLSRC:T}} \ ++ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -C \ ++ -m ${${group}MODE_${.ALLSRC:T}} \ + ${.ALLSRC} \ + ${DESTDIR}${${group}DIR_${.ALLSRC:T}}/${${group}NAME_${.ALLSRC:T}} + .else +@@ -78,10 +78,10 @@ stage_includes: stage_files.${group} + installincludes: _${group}INS + _${group}INS: ${_${group}INCS} + .if defined(${group}NAME) +- ${INSTALL} ${${group}TAG_ARGS} -C -o ${${group}OWN} -g ${${group}GRP} -m ${${group}MODE} \ ++ ${INSTALL} ${${group}TAG_ARGS} -C -m ${${group}MODE} \ + ${.ALLSRC} ${DESTDIR}${${group}DIR}/${${group}NAME} + .else +- ${INSTALL} ${${group}TAG_ARGS} -C -o ${${group}OWN} -g ${${group}GRP} -m ${${group}MODE} \ ++ ${INSTALL} ${${group}TAG_ARGS} -C -m ${${group}MODE} \ + ${.ALLSRC} ${DESTDIR}${${group}DIR}/ + .endif + .endif # !empty(_${group}INCS) +diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk +index 5f328d5378ca..264bbcc84ffb 100644 +--- a/share/mk/bsd.lib.mk ++++ b/share/mk/bsd.lib.mk +@@ -242,7 +242,7 @@ PO_FLAG=-pg + _LIBDIR:=${LIBDIR} + _SHLIBDIR:=${SHLIBDIR} + +-.if defined(SHLIB_NAME) ++.if defined(SHLIB_NAME) && !empty(SHLIB_NAME) + .if ${MK_DEBUG_FILES} != "no" + SHLIB_NAME_FULL=${SHLIB_NAME}.full + # Use ${DEBUGDIR} for base system debug files, else .debug subdirectory +@@ -277,7 +277,7 @@ LDFLAGS+= -Wl,--undefined-version + .endif + .endif + +-.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME) ++.if defined(LIB) && !empty(LIB) || (defined(SHLIB_NAME) && !empty(SHLIB_NAME)) + OBJS+= ${SRCS:N*.h:${OBJS_SRCS_FILTER:ts:}:S/$/.o/} + BCOBJS+= ${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.bco/g} + LLOBJS+= ${SRCS:N*.[hsS]:N*.asm:${OBJS_SRCS_FILTER:ts:}:S/$/.llo/g} +@@ -320,14 +320,14 @@ lib${LIB_PRIVATE}${LIB}.ll: ${LLOBJS} + CLEANFILES+= lib${LIB_PRIVATE}${LIB}.bc lib${LIB_PRIVATE}${LIB}.ll + .endif + +-.if defined(SHLIB_NAME) || \ ++.if (defined(SHLIB_NAME) && !empty(SHLIB_NAME)) || \ + defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) + SOBJS+= ${OBJS:.o=.pico} + DEPENDOBJS+= ${SOBJS} + CLEANFILES+= ${SOBJS} + .endif + +-.if defined(SHLIB_NAME) ++.if defined(SHLIB_NAME) && !empty(SHLIB_NAME) + _LIBS+= ${SHLIB_NAME} + + SOLINKOPTS+= -shared -Wl,-x +@@ -435,7 +435,7 @@ all: all-man + CLEANFILES+= ${_LIBS} + + _EXTRADEPEND: +-.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME) ++.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME) && !empty(SHLIB_NAME) + .if defined(DPADD) && !empty(DPADD) + echo ${SHLIB_NAME_FULL}: ${DPADD} >> ${DEPENDFILE} + .endif +@@ -482,7 +482,7 @@ _SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}} + installpcfiles: installpcfiles-${pcfile} + + installpcfiles-${pcfile}: ${pcfile} +- ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ ++ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -m ${LIBMODE} \ + ${_INSTALLFLAGS} \ + ${.ALLSRC} ${DESTDIR}${LIBDATADIR}/pkgconfig/ + .endfor +@@ -494,28 +494,28 @@ realinstall: _libinstall installpcfiles + .ORDER: beforeinstall _libinstall + _libinstall: + .if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no" +- ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ ++ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -m ${LIBMODE} \ + ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}${_STATICLIB_SUFFIX}.a ${DESTDIR}${_LIBDIR}/ + .if ${MK_PROFILE} != "no" +- ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ ++ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -m ${LIBMODE} \ + ${_INSTALLFLAGS} lib${LIB_PRIVATE}${LIB}_p.a ${DESTDIR}${_LIBDIR}/ + .endif + .endif +-.if defined(SHLIB_NAME) +- ${INSTALL} ${TAG_ARGS} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ ++.if defined(SHLIB_NAME) && !empty(SHLIB_NAME) ++ ${INSTALL} ${TAG_ARGS} ${STRIP} -m ${LIBMODE} \ + ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \ + ${SHLIB_NAME} ${DESTDIR}${_SHLIBDIR}/ + .if ${MK_DEBUG_FILES} != "no" + .if defined(DEBUGMKDIR) + ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -d ${DESTDIR}${DEBUGFILEDIR}/ + .endif +- ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -o ${LIBOWN} -g ${LIBGRP} -m ${DEBUGMODE} \ ++ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -m ${DEBUGMODE} \ + ${_INSTALLFLAGS} \ + ${SHLIB_NAME}.debug ${DESTDIR}${DEBUGFILEDIR}/ + .endif + .if defined(SHLIB_LINK) + .if commands(${SHLIB_LINK:R}.ld) +- ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -S -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ ++ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -S -m ${LIBMODE} \ + ${_INSTALLFLAGS} ${SHLIB_LINK:R}.ld \ + ${DESTDIR}${_LIBDIR}/${SHLIB_LINK} + .for _SHLIB_LINK_LINK in ${SHLIB_LDSCRIPT_LINKS} +@@ -548,7 +548,7 @@ _libinstall: + .endif # SHLIB_LINK + .endif # SHIB_NAME + .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) +- ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ ++ ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dev} -m ${LIBMODE} \ + ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${_LIBDIR}/ + .endif + .endif # !defined(INTERNALLIB) +@@ -588,7 +588,7 @@ OBJS_DEPEND_GUESS+= ${SRCS:M*.h} + OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.po+= ${_S} + .endfor + .endif +-.if defined(SHLIB_NAME) || \ ++.if (defined(SHLIB_NAME) && !empty(SHLIB_NAME)) || \ + defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) + .for _S in ${SRCS:N*.[hly]} + OBJS_DEPEND_GUESS.${_S:${OBJS_SRCS_FILTER:ts:}}.pico+= ${_S} +diff --git a/share/mk/bsd.man.mk b/share/mk/bsd.man.mk +index 04316c46b705..9ad3c8ce70e7 100644 +--- a/share/mk/bsd.man.mk ++++ b/share/mk/bsd.man.mk +@@ -50,9 +50,9 @@ + .endif + + .if ${MK_MANSPLITPKG} == "no" +-MINSTALL?= ${INSTALL} ${TAG_ARGS} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} ++MINSTALL?= ${INSTALL} ${TAG_ARGS} -m ${MANMODE} + .else +-MINSTALL?= ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},man} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} ++MINSTALL?= ${INSTALL} ${TAG_ARGS:D${TAG_ARGS},man} -m ${MANMODE} + .endif + + CATDIR= ${MANDIR:H:S/$/\/cat/} diff --git a/pkgs/os-specific/bsd/freebsd/patches/14.1/rtld-elf-symlink.patch b/pkgs/os-specific/bsd/freebsd/patches/14.1/rtld-elf-symlink.patch new file mode 100644 index 000000000000..d23cc82db932 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/patches/14.1/rtld-elf-symlink.patch @@ -0,0 +1,13 @@ +diff --git a/libexec/rtld-elf/Makefile b/libexec/rtld-elf/Makefile +index 0dbd2b8aa935..241d7a78e208 100644 +--- a/libexec/rtld-elf/Makefile ++++ b/libexec/rtld-elf/Makefile +@@ -54,7 +54,7 @@ NO_WCAST_ALIGN= yes + INSTALLFLAGS= -C -b + PRECIOUSPROG= + BINDIR= /libexec +-SYMLINKS= ../..${BINDIR}/${PROG} ${LIBEXECDIR}/${PROG} ++SYMLINKS= ${BINDIR}/${PROG} ${LIBEXECDIR}/${PROG} + MLINKS?= rtld.1 ld-elf.so.1.1 \ + rtld.1 ld.so.1 + diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/bin.nix b/pkgs/os-specific/bsd/freebsd/pkgs/bin.nix index 2b2738ec5794..27cd34d9e935 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/bin.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/bin.nix @@ -2,11 +2,9 @@ mkDerivation, pkgsBuildBuild, libjail, - libmd, libnetbsd, libcapsicum, libcasper, - libelf, libxo, libncurses-tinfo, libedit, @@ -36,11 +34,9 @@ mkDerivation { ]; buildInputs = [ libjail - libmd libnetbsd libcapsicum libcasper - libelf libxo libncurses-tinfo libedit diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/compat/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/compat/package.nix index 941e0537aef8..961b31d0720a 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/compat/package.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/compat/package.nix @@ -174,4 +174,6 @@ mkDerivation { # build build-time dependencies for building FreeBSD packages). It is # not needed when building for FreeBSD. meta.broken = stdenv.hostPlatform.isFreeBSD; + + alwaysKeepStatic = true; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/i18n.nix b/pkgs/os-specific/bsd/freebsd/pkgs/i18n.nix new file mode 100644 index 000000000000..f51edf4e861a --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/i18n.nix @@ -0,0 +1,20 @@ +{ + mkDerivation, + mkcsmapper, + mkesdb, +}: + +mkDerivation { + path = "share/i18n"; + + noLibc = true; + + extraNativeBuildInputs = [ + mkcsmapper + mkesdb + ]; + + preBuild = '' + export makeFlags="$makeFlags ESDBDIR=$out/share/i18n/esdb CSMAPPERDIR=$out/share/i18n/csmapper" + ''; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/include/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/include/package.nix index a4a364459daa..1119bdd35d89 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/include/package.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/include/package.nix @@ -1,5 +1,4 @@ { - stdenv, lib, mkDerivation, buildPackages, diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/install.nix b/pkgs/os-specific/bsd/freebsd/pkgs/install.nix index b8e59adb09c5..aab60480ec7a 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/install.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/install.nix @@ -26,6 +26,9 @@ let @out@/bin/xinstall "''${args[@]}" '' ); + libmd' = libmd.override { + bootstrapInstallation = true; + }; in mkDerivation { path = "usr.bin/xinstall"; @@ -39,10 +42,14 @@ mkDerivation { (if stdenv.hostPlatform == stdenv.buildPlatform then boot-install else install) ]; skipIncludesPhase = true; - buildInputs = compatIfNeeded ++ [ - libmd - libnetbsd - ]; + buildInputs = + compatIfNeeded + ++ lib.optionals (!stdenv.hostPlatform.isFreeBSD) [ + libmd' + ] + ++ [ + libnetbsd + ]; makeFlags = [ "STRIP=-s" # flag to install, not command diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/kldxref.nix b/pkgs/os-specific/bsd/freebsd/pkgs/kldxref.nix index 6c930a51db88..fd092950b2da 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/kldxref.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/kldxref.nix @@ -1,12 +1,14 @@ { + lib, + stdenv, mkDerivation, - libelf, compatIfNeeded, + libelf, }: mkDerivation { path = "usr.sbin/kldxref"; - buildInputs = [ libelf ] ++ compatIfNeeded; + buildInputs = lib.optionals (!stdenv.hostPlatform.isFreeBSD) [ libelf ] ++ compatIfNeeded; # We symlink in our modules, make it follow symlinks postPatch = '' diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/ldd.nix b/pkgs/os-specific/bsd/freebsd/pkgs/ldd.nix index 406e37402b2b..cc0f7ed2cdb2 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/ldd.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/ldd.nix @@ -2,7 +2,6 @@ lib, stdenv, mkDerivation, - libelf, }: mkDerivation { path = "usr.bin/ldd"; @@ -11,8 +10,6 @@ mkDerivation { "contrib/elftoolchain/libelf" ]; - buildInputs = [ libelf ]; - env = { NIX_CFLAGS_COMPILE = "-D_RTLD_PATH=${lib.getLib stdenv.cc.libc}/libexec/ld-elf.so.1"; }; diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libc/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libc/package.nix index 74e01d2be716..ec6aa033959b 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libc/package.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libc/package.nix @@ -1,303 +1,56 @@ { - lib, - buildPackages, - stdenv, - mkDerivation, - - bsdSetupHook, - freebsdSetupHook, - makeMinimal, - install, - flex, - byacc, - gencat, - rpcgen, - mkcsmapper, - mkesdb, - - csu, + symlinkJoin, include, - versionData, -}: - -mkDerivation { - noLibc = true; - pname = "libc"; - path = "lib/libc"; - 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" - ] - ++ lib.optionals (versionData.major == 13) [ "contrib/tzcode/stdtime" ] - ++ lib.optionals (versionData.major >= 14) [ "contrib/tzcode" ] - ++ [ - - # libthr - "lib/libthr" - "lib/libthread_db" - "libexec/rtld-elf" - "lib/csu/common/crtbrand.S" - "lib/csu/common/notes.h" - - # librpcsvc - "lib/librpcsvc" - - # librt - "lib/librt" - - # libcrypt - "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" - - # Used for aarch64-freebsd - "contrib/arm-optimized-routines" - ]; - - 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' - ''; - - # NIX_CFLAGS_LINK is empty at this point except when building static, - # in which case the stdenv adapter adds the `-static` flag. - # Building with `-static` set causes linker errors. - postConfigure = '' - export NIX_CFLAGS_LINK= - ''; - - nativeBuildInputs = [ - bsdSetupHook - freebsdSetupHook - makeMinimal - install - - flex - byacc - gencat - rpcgen - mkcsmapper - mkesdb - ]; - buildInputs = [ + csu, + libcMinimal, + libssp_nonshared, + libgcc, + libmd, + libthr, + msun, + librpcsvc, + libutil, + librt, + libcrypt, + libelf, + libexecinfo, + libkvm, + libmemstat, + libprocstat, + libdevstat, + libiconvModules, + libdl, + i18n, + rtld-elf, + baseModules ? [ include csu - ]; - 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\"" - ]; + libcMinimal + libssp_nonshared + libgcc + libmd + libthr + msun + librpcsvc + libutil + librt + libcrypt + libelf + libexecinfo + libkvm + libmemstat + libprocstat + libdevstat + libiconvModules + libdl + i18n + rtld-elf + ], + extraModules ? [ ], +}: - makeFlags = [ - "STRIP=-s" # flag to install, not command - # lib/libc/gen/getgrent.c has sketchy cast from `void *` to enum - "MK_WERROR=no" - ]; - - MK_SYMVER = "yes"; - MK_SSP = "yes"; - MK_NLS = "yes"; - MK_ICONV = "yes"; - MK_NS_CACHING = "yes"; - MK_INET6_SUPPORT = "yes"; - MK_HESIOD = "yes"; - MK_NIS = "yes"; - MK_HYPERV = "yes"; - MK_FP_LIBC = "yes"; - - MK_TCSH = "no"; - 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} - find . -type d -exec mkdir -p $out/\{} \; - find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \; - popd - - pushd ${csu} - find . -type d -exec mkdir -p $out/\{} \; - find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \; - popd - - mkdir $BSDSRCDIR/lib/libcompiler_rt/i386 $BSDSRCDIR/lib/libcompiler_rt/cpu_model - make -C $BSDSRCDIR/lib/libcompiler_rt $makeFlags - make -C $BSDSRCDIR/lib/libcompiler_rt $makeFlags install - - 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 # otherwise these dynamic libraries try to link with libc.a - mkdir $BSDSRCDIR/lib/libgcc_s/i386 $BSDSRCDIR/lib/libgcc_s/cpu_model - 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 - - 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 - '' - + lib.optionalString (!stdenv.hostPlatform.isStatic) '' - mkdir $out/lib/keep_static - mv $out/lib/*_nonshared.a $out/lib/libgcc*.a $out/lib/libcompiler_rt.a $out/lib/keep_static - rm $out/lib/*.a - mv $out/lib/keep_static/* $out/lib - rmdir $out/lib/keep_static - ''; - - # 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" - ]; +symlinkJoin { + pname = "libc"; + inherit (libcMinimal) version; + paths = baseModules ++ extraModules; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix new file mode 100644 index 000000000000..9da5df30df53 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libcMinimal.nix @@ -0,0 +1,92 @@ +{ + mkDerivation, + include, + rpcgen, + flex, + byacc, + gencat, + csu, +}: + +mkDerivation { + pname = "libcMinimal"; + path = "lib/libc"; + extraPaths = [ + "lib/libc_nonshared" + "lib/msun" + "lib/libmd" + "lib/libutil" + "libexec/rtld-elf" + "include/rpcsvc" + "contrib/libc-pwcache" + "contrib/libc-vis" + "contrib/tzcode" + "contrib/gdtoa" + "contrib/jemalloc" + "sys/sys" + "sys/kern" + "sys/libkern" + "sys/crypto" + "sys/opencrypto" + "etc/group" + "etc/master.passwd" + "etc/shells" + ]; + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + ]; + + extraNativeBuildInputs = [ + rpcgen + flex + byacc + gencat + ]; + + # this target is only used in the rtld-elf derivation. build it there instead. + postPatch = '' + sed -E -i -e '/BUILD_NOSSP_PIC_ARCHIVE=/d' $BSDSRCDIR/lib/libc/Makefile + ''; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; + + postBuild = '' + make -C $BSDSRCDIR/lib/libc_nonshared $makeFlags + ''; + + postInstall = '' + make -C $BSDSRCDIR/lib/libc_nonshared $makeFlags install + ''; + + alwaysKeepStatic = true; + + env = { + MK_TESTS = "no"; + MK_SYMVER = "yes"; + MK_SSP = "yes"; + MK_NLS = "yes"; + MK_ICONV = "yes"; + MK_NS_CACHING = "yes"; + MK_INET6_SUPPORT = "yes"; + MK_HESIOD = "yes"; + MK_NIS = "yes"; + MK_HYPERV = "yes"; + MK_FP_LIBC = "yes"; + MK_MALLOC_PRODUCTION = "yes"; + MK_MACHDEP_OPTIMIZATIONS = "yes"; + }; + + # definitely a bad idea to enable stack protection on the stack protection initializers + hardeningDisable = [ "stackprotector" ]; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libcrypt.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libcrypt.nix new file mode 100644 index 000000000000..f5c90f841e67 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libcrypt.nix @@ -0,0 +1,37 @@ +{ + mkDerivation, + include, + libcMinimal, + libgcc, + csu, +}: + +mkDerivation { + path = "lib/libcrypt"; + extraPaths = [ + "sys/kern" + "sys/crypto" + "lib/libmd" + "secure/lib/libcrypt" + ]; + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libcMinimal + libgcc + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; + + env.MK_TESTS = "no"; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libcxxrt.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libcxxrt.nix index f49718dc5ef1..8a7a0e1c321c 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libcxxrt.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libcxxrt.nix @@ -12,14 +12,16 @@ mkDerivation { pname = "libcxxrt"; path = "lib/libcxxrt"; extraPaths = [ "contrib/libcxxrt" ]; - outputs = - [ - "out" - "dev" - ] - ++ lib.optionals (!stdenv.hostPlatform.isStatic) [ - "debug" - ]; + outputs = [ + "out" + "dev" + "debug" + ]; noLibcxx = true; libName = "cxxrt"; + + # they already fixed the undefined symbols in the version map upstream. it'll be released probably in 15.0 + preBuild = '' + export NIX_LDFLAGS="$NIX_LDFLAGS --undefined-version" + ''; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libdevstat.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libdevstat.nix new file mode 100644 index 000000000000..f1287080ea10 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libdevstat.nix @@ -0,0 +1,44 @@ +{ + mkDerivation, + include, + libcMinimal, + libgcc, + libkvm, + libprocstat, + libutil, + libelf, + csu, +}: + +mkDerivation { + path = "lib/libdevstat"; + extraPaths = [ + "lib/libc/Versions.def" + "sys/contrib/openzfs" + "sys/contrib/pcg-c" + "sys/opencrypto" + "sys/crypto" + ]; + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libcMinimal + libgcc + libkvm + libprocstat + libutil + libelf + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libdl.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libdl.nix index 2b77a0f71662..5f0b8109dae3 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libdl.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libdl.nix @@ -1,9 +1,34 @@ -{ mkDerivation, ... }: +{ + mkDerivation, + include, + libcMinimal, + libgcc, + csu, +}: + mkDerivation { path = "lib/libdl"; extraPaths = [ - "lib/libc" "libexec/rtld-elf" + "lib/libc/gen" + "lib/libc/include" + "lib/libc/Versions.def" ]; - buildInputs = [ ]; + + outputs = [ + "out" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libcMinimal + libgcc + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libelf.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libelf.nix index d24b242bc4d3..0afedf611112 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libelf.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libelf.nix @@ -1,26 +1,44 @@ { + lib, stdenv, mkDerivation, - bsdSetupHook, - freebsdSetupHook, - makeMinimal, - install, m4, + include, + libcMinimal, + libgcc, + compatIfNeeded, + csu, }: + mkDerivation { path = "lib/libelf"; extraPaths = [ "lib/libc" "contrib/elftoolchain" - "sys/sys/elf32.h" - "sys/sys/elf64.h" - "sys/sys/elf_common.h" + "sys/sys" ]; - nativeBuildInputs = [ - bsdSetupHook - freebsdSetupHook - makeMinimal - install + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = stdenv.hostPlatform.isFreeBSD; + + buildInputs = + lib.optionals stdenv.hostPlatform.isFreeBSD [ + include + libcMinimal + libgcc + ] + ++ compatIfNeeded; + + extraNativeBuildInputs = [ m4 ]; + + preBuild = lib.optionalString stdenv.hostPlatform.isFreeBSD '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libexecinfo.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libexecinfo.nix new file mode 100644 index 000000000000..fff230ade0a5 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libexecinfo.nix @@ -0,0 +1,36 @@ +{ + mkDerivation, + include, + libelf, + libcMinimal, + libgcc, + csu, +}: + +mkDerivation { + path = "lib/libexecinfo"; + extraPaths = [ + "contrib/libexecinfo" + ]; + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libelf + libcMinimal + libgcc + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; + + env.MK_TESTS = "no"; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libgcc.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libgcc.nix new file mode 100644 index 000000000000..6bcc4639d15f --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libgcc.nix @@ -0,0 +1,49 @@ +{ + mkDerivation, + include, + libcMinimal, + csu, +}: + +mkDerivation { + path = "lib/libgcc_eh"; + extraPaths = [ + "lib/libgcc_s" + "lib/libcompiler_rt" + "lib/msun" + "lib/libc" # needs arch-specific fpmath files + "contrib/llvm-project/compiler-rt" + "contrib/llvm-project/libunwind" + ]; + + outputs = [ + "out" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libcMinimal + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; + + postBuild = '' + mkdir $BSDSRCDIR/lib/libgcc_s/i386 $BSDSRCDIR/lib/libgcc_s/cpu_model + make -C $BSDSRCDIR/lib/libgcc_s $makeFlags + + mkdir $BSDSRCDIR/lib/libcompiler_rt/i386 $BSDSRCDIR/lib/libcompiler_rt/cpu_model + make -C $BSDSRCDIR/lib/libcompiler_rt $makeFlags + ''; + + postInstall = '' + make -C $BSDSRCDIR/lib/libgcc_s $makeFlags install + make -C $BSDSRCDIR/lib/libcompiler_rt $makeFlags install + ''; + + alwaysKeepStatic = true; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libiconvModules.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libiconvModules.nix new file mode 100644 index 000000000000..015274801c42 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libiconvModules.nix @@ -0,0 +1,32 @@ +{ + mkDerivation, + include, + libcMinimal, + libgcc, + csu, +}: + +mkDerivation { + path = "lib/libiconv_modules"; + extraPaths = [ + "lib/libc/iconv" + ]; + + outputs = [ + "out" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libcMinimal + libgcc + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + export makeFlags="$makeFlags SHLIBDIR=$out/lib/i18n" + ''; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libkvm.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libkvm.nix new file mode 100644 index 000000000000..d4a7aac386b8 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libkvm.nix @@ -0,0 +1,36 @@ +{ + mkDerivation, + include, + libcMinimal, + libgcc, + libelf, + csu, +}: + +mkDerivation { + path = "lib/libkvm"; + extraPaths = [ + "sys" # wants sys/${arch} + ]; + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libcMinimal + libgcc + libelf + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; + + env.MK_TESTS = "no"; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libmd.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libmd.nix index 71d0c1e50d5e..a2ff458274e2 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libmd.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libmd.nix @@ -2,48 +2,74 @@ lib, stdenv, mkDerivation, - freebsdSetupHook, - bsdSetupHook, + libcMinimal, + include, + libgcc, makeMinimal, + bsdSetupHook, + freebsdSetupHook, + compatIfNeeded, + csu, + # this is set to true when used as the dependency of install + # this is set to false when used as the dependency of libc + bootstrapInstallation ? false, }: -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"; +mkDerivation ( + { + path = "lib/libmd"; + extraPaths = [ + "sys/crypto" + "sys/sys" + ]; - preBuild = '' - mkdir sys - ''; + outputs = [ + "out" + "man" + "debug" + ]; - 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 - ''; + noLibc = !bootstrapInstallation; - outputs = [ - "out" - "man" - ]; -} + buildInputs = + lib.optionals (!bootstrapInstallation) [ + libcMinimal + include + libgcc + ] + ++ compatIfNeeded; + + preBuild = + '' + mkdir $BSDSRCDIR/lib/libmd/sys + '' + + lib.optionalString stdenv.hostPlatform.isFreeBSD '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; + + installPhase = + if (!bootstrapInstallation) then + null + else + '' + # 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 + ''; + } + // lib.optionalAttrs bootstrapInstallation { + nativeBuildInputs = [ + makeMinimal + bsdSetupHook + freebsdSetupHook + ]; + } +) diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libmemstat.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libmemstat.nix new file mode 100644 index 000000000000..d5fbee0cf4cd --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libmemstat.nix @@ -0,0 +1,31 @@ +{ + mkDerivation, + include, + libcMinimal, + libgcc, + libkvm, + csu, +}: + +mkDerivation { + path = "lib/libmemstat"; + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libcMinimal + libgcc + libkvm + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libnetbsd/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libnetbsd/package.nix index 82a9e140102f..1752583b0532 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libnetbsd/package.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libnetbsd/package.nix @@ -25,4 +25,6 @@ mkDerivation { "STRIP=-s" # flag to install, not command "MK_WERROR=no" ] ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) "INSTALL=boot-install"; + + alwaysKeepStatic = true; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libprocstat.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libprocstat.nix new file mode 100644 index 000000000000..15c7729919d4 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libprocstat.nix @@ -0,0 +1,42 @@ +{ + mkDerivation, + include, + libcMinimal, + libgcc, + libkvm, + libutil, + libelf, + csu, +}: + +mkDerivation { + path = "lib/libprocstat"; + extraPaths = [ + "lib/libc/Versions.def" + "sys/contrib/openzfs" + "sys/contrib/pcg-c" + "sys/opencrypto" + "sys/crypto" + ]; + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libcMinimal + libgcc + libkvm + libutil + libelf + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libradius.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libradius.nix index 9766d75e6c3f..807c161c105c 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libradius.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libradius.nix @@ -1,12 +1,10 @@ { mkDerivation, openssl, - libmd, }: mkDerivation { path = "lib/libradius"; buildInputs = [ - libmd openssl ]; diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/librpcsvc.nix b/pkgs/os-specific/bsd/freebsd/pkgs/librpcsvc.nix new file mode 100644 index 000000000000..84f9093de4e1 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/librpcsvc.nix @@ -0,0 +1,30 @@ +{ + mkDerivation, + rpcgen, + include, + csu, +}: + +mkDerivation { + path = "lib/librpcsvc"; + extraPaths = [ + "sys/nlm" + "include/rpcsvc" + ]; + noLibc = true; + + extraNativeBuildInputs = [ + rpcgen + ]; + + buildInputs = [ + include + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${include}/include/rpcsvc" + ''; + + alwaysKeepStatic = true; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/librt.nix b/pkgs/os-specific/bsd/freebsd/pkgs/librt.nix new file mode 100644 index 000000000000..2cc2fc746153 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/librt.nix @@ -0,0 +1,36 @@ +{ + mkDerivation, + include, + libcMinimal, + libgcc, + libthr, + csu, +}: + +mkDerivation { + path = "lib/librt"; + extraPaths = [ + "lib/libc/include" # private headers + "lib/libc/Versions.def" + ]; + + outputs = [ + "out" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libcMinimal + libgcc + libthr + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; + + env.MK_TESTS = "no"; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libsbuf.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libsbuf.nix index 242492a3f2f2..f8e729d2d76e 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libsbuf.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libsbuf.nix @@ -3,5 +3,5 @@ mkDerivation { path = "lib/libsbuf"; extraPaths = [ "sys/kern" ]; - MK_TESTS = "no"; + env.MK_TESTS = "no"; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libssp_nonshared.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libssp_nonshared.nix new file mode 100644 index 000000000000..7b06fd660f1b --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libssp_nonshared.nix @@ -0,0 +1,15 @@ +{ + mkDerivation, + include, +}: + +mkDerivation { + path = "lib/libssp_nonshared"; + noLibc = true; + + buildInputs = [ + include + ]; + + alwaysKeepStatic = true; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libthr.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libthr.nix new file mode 100644 index 000000000000..f8f4e3e5978e --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libthr.nix @@ -0,0 +1,36 @@ +{ + mkDerivation, + libcMinimal, + include, + libgcc, + csu, +}: + +mkDerivation { + path = "lib/libthr"; + extraPaths = [ + "lib/libthread_db" + "lib/libc" # needs /include + arch-specific files + "libexec/rtld-elf" + ]; + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + libcMinimal + include + libgcc + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; + + env.MK_TESTS = "no"; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/libutil.nix b/pkgs/os-specific/bsd/freebsd/pkgs/libutil.nix index 450cdfde0eaa..e28ec53331ee 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/libutil.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/libutil.nix @@ -1,6 +1,31 @@ -{ mkDerivation }: +{ + mkDerivation, + include, + libgcc, + libcMinimal, + csu, +}: mkDerivation { path = "lib/libutil"; extraPaths = [ "lib/libc/gen" ]; - MK_TESTS = "no"; + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libgcc + libcMinimal + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; + + env.MK_TESTS = "no"; } diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/mkDerivation.nix b/pkgs/os-specific/bsd/freebsd/pkgs/mkDerivation.nix index 5035dfd3fcdb..4dc0f4c42bb7 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/mkDerivation.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/mkDerivation.nix @@ -75,6 +75,9 @@ lib.makeOverridable ( MACHINE_CPUARCH = freebsd-lib.mkBsdCpuArch stdenv'; COMPONENT_PATH = attrs.path or null; + + # don't set filesystem flags that require root + NO_FSCHG = "yes"; } // lib.optionalAttrs stdenv'.hasCC { # TODO should CC wrapper set this? @@ -129,5 +132,21 @@ lib.makeOverridable ( )) ++ attrs.patches or [ ]; } + // + lib.optionalAttrs + (!stdenv.hostPlatform.isStatic && !attrs.alwaysKeepStatic or false && stdenv.hostPlatform.isFreeBSD) + { + postInstall = + (attrs.postInstall or "") + + '' + rm -f $out/lib/*.a + ''; + } + // + lib.optionalAttrs + ((stdenv.hostPlatform.isStatic || !stdenv.hostPlatform.isFreeBSD) && attrs ? outputs) + { + outputs = lib.lists.remove "debug" attrs.outputs; + } ) ) diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/msun.nix b/pkgs/os-specific/bsd/freebsd/pkgs/msun.nix new file mode 100644 index 000000000000..87e081c6c445 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/msun.nix @@ -0,0 +1,34 @@ +{ + mkDerivation, + include, + libcMinimal, + libgcc, + csu, +}: + +mkDerivation { + path = "lib/msun"; + extraPaths = [ + "lib/libc" # wants arch headers + ]; + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + libcMinimal + libgcc + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + ''; + + env.MK_TESTS = "no"; +} diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/mtree.nix b/pkgs/os-specific/bsd/freebsd/pkgs/mtree.nix index f1cf4f9bd220..746d6a1d958c 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/mtree.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/mtree.nix @@ -4,21 +4,27 @@ mkDerivation, compatIfNeeded, compatIsNeeded, - libmd, libnetbsd, - libutil, + libmd, }: +let + libmd' = libmd.override { + bootstrapInstallation = true; + }; + +in mkDerivation { path = "contrib/mtree"; extraPaths = [ "contrib/mknod" ]; buildInputs = compatIfNeeded - ++ [ - libmd - libnetbsd + ++ lib.optionals (!stdenv.hostPlatform.isFreeBSD) [ + libmd' ] - ++ lib.optional (stdenv.hostPlatform.isFreeBSD) libutil; + ++ [ + libnetbsd + ]; postPatch = '' ln -s $BSDSRCDIR/contrib/mknod/*.c $BSDSRCDIR/contrib/mknod/*.h $BSDSRCDIR/contrib/mtree diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/package.nix index e187cacbb0d0..49b2ef805bc1 100644 --- a/pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/package.nix +++ b/pkgs/os-specific/bsd/freebsd/pkgs/rpcgen/package.nix @@ -2,7 +2,6 @@ lib, mkDerivation, stdenv, - patchesRoot, }: mkDerivation { diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix b/pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix new file mode 100644 index 000000000000..1a9aba91c252 --- /dev/null +++ b/pkgs/os-specific/bsd/freebsd/pkgs/rtld-elf.nix @@ -0,0 +1,58 @@ +{ + mkDerivation, + include, + rpcgen, + flex, + byacc, + csu, +}: + +mkDerivation { + path = "libexec/rtld-elf"; + extraPaths = [ + "lib/csu" + "lib/libc" + "lib/libmd" + "lib/msun" + "lib/libutil" + "lib/libc_nonshared" + "include/rpcsvc" + "contrib/libc-pwcache" + "contrib/libc-vis" + "contrib/tzcode" + "contrib/gdtoa" + "contrib/jemalloc" + "sys/sys" + "sys/kern" + "sys/libkern" + "sys/crypto" + ]; + + outputs = [ + "out" + "man" + "debug" + ]; + + noLibc = true; + + buildInputs = [ + include + ]; + + extraNativeBuildInputs = [ + rpcgen + flex + byacc + ]; + + preBuild = '' + export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -B${csu}/lib" + make -C $BSDSRCDIR/lib/libc $makeFlags libc_nossp_pic.a + ''; + + # definitely a bad idea to enable stack protection on the stack protection initializers + hardeningDisable = [ "stackprotector" ]; + + env.MK_TESTS = "no"; +}