From dcf7a5ec3dac6a53ce1a27e0806bd93309b9d053 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 6 Oct 2022 00:51:05 -0400 Subject: [PATCH 1/3] netbsd: Adapt to BSD-common infra changes for FreeBSD See https://github.com/NixOS/nixpkgs/pull/82131 for the rest of the changes for FreeBSD. This is PRed separately because it is a macOS moderate rebuild so we target staging. The main change is that we CD to the path we're building *after* applying patches, so we can patch other parts of the tree (from `extraPaths`) as needed. Another change is that `netbsd.install` no longer depends on `fts`, which it evidently no longer needs. --- .../bsd/netbsd/compat-cxx-safe-header.patch | 4 +- .../netbsd/compat-dont-configure-twice.patch | 4 +- .../bsd/netbsd/compat-no-force-native.patch | 4 +- pkgs/os-specific/bsd/netbsd/default.nix | 39 ++++++++++--------- pkgs/os-specific/bsd/netbsd/getent.patch | 4 +- pkgs/os-specific/bsd/netbsd/locale.patch | 4 +- .../bsd/netbsd/no-dynamic-linker.patch | 4 +- .../bsd/netbsd/sys-headers-incsdir.patch | 4 +- pkgs/os-specific/bsd/setup-hook.sh | 7 +++- 9 files changed, 41 insertions(+), 33 deletions(-) diff --git a/pkgs/os-specific/bsd/netbsd/compat-cxx-safe-header.patch b/pkgs/os-specific/bsd/netbsd/compat-cxx-safe-header.patch index f67ca2e507915..2aaa90b76146b 100644 --- a/pkgs/os-specific/bsd/netbsd/compat-cxx-safe-header.patch +++ b/pkgs/os-specific/bsd/netbsd/compat-cxx-safe-header.patch @@ -1,6 +1,6 @@ diff -u -r1.35.2.1 nbtool_config.h.in ---- a/nbtool_config.h.in 22 Apr 2015 07:18:58 -0000 1.35.2.1 -+++ b/nbtool_config.h.in 31 May 2018 01:46:53 -0000 +--- a/tools/compat/nbtool_config.h.in 22 Apr 2015 07:18:58 -0000 1.35.2.1 ++++ b/tools/compat/nbtool_config.h.in 31 May 2018 01:46:53 -0000 @@ -680,5 +680,14 @@ /* Define if you have u_int8_t, but not uint8_t. */ #undef uint8_t diff --git a/pkgs/os-specific/bsd/netbsd/compat-dont-configure-twice.patch b/pkgs/os-specific/bsd/netbsd/compat-dont-configure-twice.patch index 1a69e73e255fc..2758e256a6168 100644 --- a/pkgs/os-specific/bsd/netbsd/compat-dont-configure-twice.patch +++ b/pkgs/os-specific/bsd/netbsd/compat-dont-configure-twice.patch @@ -6,8 +6,8 @@ Date: Wed Sep 1 15:38:56 2021 +0000 diff --git a/Makefile b/Makefile index b5adb8a5f2e9..1a914ef16739 100644 ---- a/Makefile -+++ b/Makefile +--- a/tools/compat/Makefile ++++ b/tools/compat/Makefile @@ -76,11 +76,6 @@ _CURDIR:= ${.CURDIR} SRCS:= ${SRCS:M*.c} diff --git a/pkgs/os-specific/bsd/netbsd/compat-no-force-native.patch b/pkgs/os-specific/bsd/netbsd/compat-no-force-native.patch index cd442d95f412a..117fb7e042982 100644 --- a/pkgs/os-specific/bsd/netbsd/compat-no-force-native.patch +++ b/pkgs/os-specific/bsd/netbsd/compat-no-force-native.patch @@ -8,8 +8,8 @@ Date: Wed Sep 1 15:38:56 2021 +0000 diff --git a/Makefile b/Makefile index 4bcf227f0e75..9ed1d6eea6ff 100644 ---- a/Makefile -+++ b/Makefile +--- a/tools/compat/Makefile ++++ b/tools/compat/Makefile @@ -1,6 +1,6 @@ # $NetBSD: Makefile,v 1.87 2019/05/08 02:25:50 thorpej Exp $ diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix index ae93d42b67657..82e7dafdd3b41 100644 --- a/pkgs/os-specific/bsd/netbsd/default.nix +++ b/pkgs/os-specific/bsd/netbsd/default.nix @@ -3,7 +3,7 @@ , buildPackages, splicePackages, newScope , bsdSetupHook, makeSetupHook, fetchcvs, groff, mandoc, byacc, flex , zlib -, writeText, symlinkJoin +, writeScript, writeText, runtimeShell, symlinkJoin }: let @@ -121,12 +121,12 @@ in lib.makeScopeWithSplicing installPhase = "includesPhase"; dontBuild = true; } // attrs // { + # Files that use NetBSD-specific macros need to have nbtool_config.h + # included ahead of them on non-NetBSD platforms. postPatch = lib.optionalString (!stdenv'.hostPlatform.isNetBSD) '' - # Files that use NetBSD-specific macros need to have nbtool_config.h - # included ahead of them on non-NetBSD platforms. set +e grep -Zlr "^__RCSID - ^__BEGIN_DECLS" | xargs -0r grep -FLZ nbtool_config.h | + ^__BEGIN_DECLS" $BSD_PATH | xargs -0r grep -FLZ nbtool_config.h | xargs -0tr sed -i '0,/^#/s//#include \n\0/' set -e '' + attrs.postPatch or ""; @@ -146,7 +146,7 @@ in lib.makeScopeWithSplicing skipIncludesPhase = true; postPatch = '' - patchShebangs configure + patchShebangs $BSD_PATH/configure ${self.make.postPatch} ''; @@ -281,11 +281,12 @@ in lib.makeScopeWithSplicing # HACK: to ensure parent directories exist. This emulates GNU # install’s -D option. No alternative seems to exist in BSD install. - install = let binstall = writeText "binstall" '' - #!${stdenv.shell} - for last in $@; do true; done + install = let binstall = writeScript "binstall" '' + #!${runtimeShell} + set -eu + for last in "$@"; do true; done mkdir -p $(dirname $last) - xinstall "$@" + @out@/bin/xinstall "$@" ''; in mkDerivation { path = "usr.bin/xinstall"; version = "9.2"; @@ -297,13 +298,14 @@ in lib.makeScopeWithSplicing mandoc groff rsync ]; skipIncludesPhase = true; - buildInputs = with self; compatIfNeeded ++ [ fts ]; + buildInputs = with self; compatIfNeeded; installPhase = '' runHook preInstall install -D install.1 $out/share/man/man1/install.1 install -D xinstall $out/bin/xinstall install -D -m 0550 ${binstall} $out/bin/binstall + substituteInPlace $out/bin/binstall --subst-var out ln -s $out/bin/binstall $out/bin/install runHook postInstall @@ -391,6 +393,7 @@ in lib.makeScopeWithSplicing install mandoc groff rsync ]; }; + ## ## END BOOTSTRAPPING ## @@ -705,10 +708,10 @@ in lib.makeScopeWithSplicing SHLIBINSTALLDIR = "$(out)/lib"; makeFlags = defaultMakeFlags ++ [ "LIBDO.terminfo=${self.libterminfo}/lib" ]; postPatch = '' - sed -i '1i #undef bool_t' el.h - substituteInPlace config.h \ + sed -i '1i #undef bool_t' $BSD_PATH/el.h + substituteInPlace $BSD_PATH/config.h \ --replace "#define HAVE_STRUCT_DIRENT_D_NAMLEN 1" "" - substituteInPlace readline/Makefile --replace /usr/include "$out/include" + substituteInPlace $BSD_PATH/readline/Makefile --replace /usr/include "$out/include" ''; NIX_CFLAGS_COMPILE = [ "-D__noinline=" @@ -728,8 +731,8 @@ in lib.makeScopeWithSplicing buildInputs = with self; compatIfNeeded; SHLIBINSTALLDIR = "$(out)/lib"; postPatch = '' - substituteInPlace term.c --replace /usr/share $out/share - substituteInPlace setupterm.c \ + substituteInPlace $BSD_PATH/term.c --replace /usr/share $out/share + substituteInPlace $BSD_PATH/setupterm.c \ --replace '#include ' 'void use_env(bool);' ''; postBuild = '' @@ -757,10 +760,10 @@ in lib.makeScopeWithSplicing MKDOC = "no"; # missing vfontedpr makeFlags = defaultMakeFlags ++ [ "LIBDO.terminfo=${self.libterminfo}/lib" ]; postPatch = lib.optionalString (!stdenv.isDarwin) '' - substituteInPlace printw.c \ + substituteInPlace $BSD_PATH/printw.c \ --replace "funopen(win, NULL, __winwrite, NULL, NULL)" NULL \ --replace "__strong_alias(vwprintw, vw_printw)" 'extern int vwprintw(WINDOW*, const char*, va_list) __attribute__ ((alias ("vw_printw")));' - substituteInPlace scanw.c \ + substituteInPlace $BSD_PATH/scanw.c \ --replace "__strong_alias(vwscanw, vw_scanw)" 'extern int vwscanw(WINDOW*, const char*, va_list) __attribute__ ((alias ("vw_scanw")));' ''; }; @@ -985,7 +988,7 @@ in lib.makeScopeWithSplicing # man0 generates a man.pdf using ps2pdf, but doesn't install it later, # so we can avoid the dependency on ghostscript postPatch = '' - substituteInPlace man0/Makefile --replace "ps2pdf" "echo noop " + substituteInPlace $BSD_PATH/man0/Makefile --replace "ps2pdf" "echo noop " ''; makeFlags = defaultMakeFlags ++ [ "FILESDIR=$(out)/share" diff --git a/pkgs/os-specific/bsd/netbsd/getent.patch b/pkgs/os-specific/bsd/netbsd/getent.patch index e9e34d19a315b..18258b6486186 100644 --- a/pkgs/os-specific/bsd/netbsd/getent.patch +++ b/pkgs/os-specific/bsd/netbsd/getent.patch @@ -1,8 +1,8 @@ Author: Matthew Bauer Description: Remove unavailable getent databases Version: 7.1.2 ---- a/getent.c 2018-04-16 13:33:49.000000000 -0500 -+++ b/getent.c 2018-04-16 13:29:30.000000000 -0500 +--- a/usr.bin/getent/getent.c 2018-04-16 13:33:49.000000000 -0500 ++++ b/usr.bin/getent/getent.c 2018-04-16 13:29:30.000000000 -0500 @@ -42,7 +42,6 @@ #include #include diff --git a/pkgs/os-specific/bsd/netbsd/locale.patch b/pkgs/os-specific/bsd/netbsd/locale.patch index 1df9eb385625c..4b7f478552879 100644 --- a/pkgs/os-specific/bsd/netbsd/locale.patch +++ b/pkgs/os-specific/bsd/netbsd/locale.patch @@ -1,5 +1,5 @@ ---- a/locale.c 2018-06-11 14:39:06.449762000 -0400 -+++ b/locale.c 2018-06-11 14:42:28.461122899 -0400 +--- a/usr.bin/locale/locale.c 2018-06-11 14:39:06.449762000 -0400 ++++ b/usr.bin/locale/locale.c 2018-06-11 14:42:28.461122899 -0400 @@ -56,14 +56,8 @@ #include #include diff --git a/pkgs/os-specific/bsd/netbsd/no-dynamic-linker.patch b/pkgs/os-specific/bsd/netbsd/no-dynamic-linker.patch index 5a2b9092a5c56..b3e9f3c88a13c 100644 --- a/pkgs/os-specific/bsd/netbsd/no-dynamic-linker.patch +++ b/pkgs/os-specific/bsd/netbsd/no-dynamic-linker.patch @@ -4,8 +4,8 @@ rcsdiff: /ftp/cvs/cvsroot/src/sys/arch/i386/stand/efiboot/Makefile.efiboot,v: wa retrieving revision 1.16 retrieving revision 1.17 diff -u -p -r1.16 -r1.17 ---- sys/arch/i386/stand/efiboot/Makefile.efiboot 2019/09/13 02:19:45 1.16 -+++ sys/arch/i386/stand/efiboot/Makefile.efiboot 2020/04/04 15:30:46 1.17 +--- a/sys/arch/i386/stand/efiboot/Makefile.efiboot 2019/09/13 02:19:45 1.16 ++++ b/sys/arch/i386/stand/efiboot/Makefile.efiboot 2020/04/04 15:30:46 1.17 @@ -41,6 +41,7 @@ BINMODE=444 .PATH: ${.CURDIR}/../../libsa diff --git a/pkgs/os-specific/bsd/netbsd/sys-headers-incsdir.patch b/pkgs/os-specific/bsd/netbsd/sys-headers-incsdir.patch index ed85f8ea5b0cf..5cfb2a54c8db2 100644 --- a/pkgs/os-specific/bsd/netbsd/sys-headers-incsdir.patch +++ b/pkgs/os-specific/bsd/netbsd/sys-headers-incsdir.patch @@ -1,7 +1,7 @@ diff --git a/Makefile b/Makefile index 3f1e18dc659d..163362b82f94 100644 ---- a/Makefile -+++ b/Makefile +--- a/sys/Makefile ++++ b/sys/Makefile @@ -2,6 +2,8 @@ .include diff --git a/pkgs/os-specific/bsd/setup-hook.sh b/pkgs/os-specific/bsd/setup-hook.sh index 4bdfde68b62e7..7dd7de48ac463 100644 --- a/pkgs/os-specific/bsd/setup-hook.sh +++ b/pkgs/os-specific/bsd/setup-hook.sh @@ -48,6 +48,7 @@ addMakeFlags() { makeFlags="BINDIR=${!outputBin}/bin $makeFlags" 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" @@ -61,10 +62,13 @@ setBSDSourceDir() { sourceRoot=$PWD/$sourceRoot export BSDSRCDIR=$sourceRoot export _SRC_TOP_=$BSDSRCDIR - cd $sourceRoot +} + +cdBSDPath() { if [ -d "$BSD_PATH" ] then sourceRoot=$sourceRoot/$BSD_PATH + cd $BSD_PATH fi } @@ -104,6 +108,7 @@ moveUsrDir() { } postUnpackHooks+=(setBSDSourceDir) +postPatchHooks+=(cdBSDPath) preConfigureHooks+=(addMakeFlags) preInstallHooks+=(includesPhase) fixupOutputHooks+=(moveUsrDir) From e3137f73fd85d6b63a04b4e2d94f48d2f68113f3 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 6 Oct 2022 12:48:19 -0400 Subject: [PATCH 2/3] netbsd.install: Use `writeShellScript` --- pkgs/os-specific/bsd/netbsd/default.nix | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix index 82e7dafdd3b41..8e120cd19a84f 100644 --- a/pkgs/os-specific/bsd/netbsd/default.nix +++ b/pkgs/os-specific/bsd/netbsd/default.nix @@ -3,7 +3,7 @@ , buildPackages, splicePackages, newScope , bsdSetupHook, makeSetupHook, fetchcvs, groff, mandoc, byacc, flex , zlib -, writeScript, writeText, runtimeShell, symlinkJoin +, writeShellScript, writeText, runtimeShell, symlinkJoin }: let @@ -281,8 +281,7 @@ in lib.makeScopeWithSplicing # HACK: to ensure parent directories exist. This emulates GNU # install’s -D option. No alternative seems to exist in BSD install. - install = let binstall = writeScript "binstall" '' - #!${runtimeShell} + install = let binstall = writeShellScript "binstall" '' set -eu for last in "$@"; do true; done mkdir -p $(dirname $last) From 044163d6ef477ed41ceca7b294814f9a36d8bee7 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Thu, 6 Oct 2022 14:44:14 -0400 Subject: [PATCH 3/3] bsd: `BSD_PATH` rename to `COMPONENT_PATH` @alyssais and I agreed this is clearer. --- pkgs/os-specific/bsd/netbsd/default.nix | 22 +++++++++++----------- pkgs/os-specific/bsd/setup-hook.sh | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix index 8e120cd19a84f..c90de5067dc3f 100644 --- a/pkgs/os-specific/bsd/netbsd/default.nix +++ b/pkgs/os-specific/bsd/netbsd/default.nix @@ -94,7 +94,7 @@ in lib.makeScopeWithSplicing }.${stdenv'.hostPlatform.parsed.cpu.name} or stdenv'.hostPlatform.parsed.cpu.name; - BSD_PATH = attrs.path; + COMPONENT_PATH = attrs.path; makeFlags = defaultMakeFlags; @@ -126,7 +126,7 @@ in lib.makeScopeWithSplicing postPatch = lib.optionalString (!stdenv'.hostPlatform.isNetBSD) '' set +e grep -Zlr "^__RCSID - ^__BEGIN_DECLS" $BSD_PATH | xargs -0r grep -FLZ nbtool_config.h | + ^__BEGIN_DECLS" $COMPONENT_PATH | xargs -0r grep -FLZ nbtool_config.h | xargs -0tr sed -i '0,/^#/s//#include \n\0/' set -e '' + attrs.postPatch or ""; @@ -146,7 +146,7 @@ in lib.makeScopeWithSplicing skipIncludesPhase = true; postPatch = '' - patchShebangs $BSD_PATH/configure + patchShebangs $COMPONENT_PATH/configure ${self.make.postPatch} ''; @@ -707,10 +707,10 @@ in lib.makeScopeWithSplicing SHLIBINSTALLDIR = "$(out)/lib"; makeFlags = defaultMakeFlags ++ [ "LIBDO.terminfo=${self.libterminfo}/lib" ]; postPatch = '' - sed -i '1i #undef bool_t' $BSD_PATH/el.h - substituteInPlace $BSD_PATH/config.h \ + sed -i '1i #undef bool_t' $COMPONENT_PATH/el.h + substituteInPlace $COMPONENT_PATH/config.h \ --replace "#define HAVE_STRUCT_DIRENT_D_NAMLEN 1" "" - substituteInPlace $BSD_PATH/readline/Makefile --replace /usr/include "$out/include" + substituteInPlace $COMPONENT_PATH/readline/Makefile --replace /usr/include "$out/include" ''; NIX_CFLAGS_COMPILE = [ "-D__noinline=" @@ -730,8 +730,8 @@ in lib.makeScopeWithSplicing buildInputs = with self; compatIfNeeded; SHLIBINSTALLDIR = "$(out)/lib"; postPatch = '' - substituteInPlace $BSD_PATH/term.c --replace /usr/share $out/share - substituteInPlace $BSD_PATH/setupterm.c \ + substituteInPlace $COMPONENT_PATH/term.c --replace /usr/share $out/share + substituteInPlace $COMPONENT_PATH/setupterm.c \ --replace '#include ' 'void use_env(bool);' ''; postBuild = '' @@ -759,10 +759,10 @@ in lib.makeScopeWithSplicing MKDOC = "no"; # missing vfontedpr makeFlags = defaultMakeFlags ++ [ "LIBDO.terminfo=${self.libterminfo}/lib" ]; postPatch = lib.optionalString (!stdenv.isDarwin) '' - substituteInPlace $BSD_PATH/printw.c \ + substituteInPlace $COMPONENT_PATH/printw.c \ --replace "funopen(win, NULL, __winwrite, NULL, NULL)" NULL \ --replace "__strong_alias(vwprintw, vw_printw)" 'extern int vwprintw(WINDOW*, const char*, va_list) __attribute__ ((alias ("vw_printw")));' - substituteInPlace $BSD_PATH/scanw.c \ + substituteInPlace $COMPONENT_PATH/scanw.c \ --replace "__strong_alias(vwscanw, vw_scanw)" 'extern int vwscanw(WINDOW*, const char*, va_list) __attribute__ ((alias ("vw_scanw")));' ''; }; @@ -987,7 +987,7 @@ in lib.makeScopeWithSplicing # man0 generates a man.pdf using ps2pdf, but doesn't install it later, # so we can avoid the dependency on ghostscript postPatch = '' - substituteInPlace $BSD_PATH/man0/Makefile --replace "ps2pdf" "echo noop " + substituteInPlace $COMPONENT_PATH/man0/Makefile --replace "ps2pdf" "echo noop " ''; makeFlags = defaultMakeFlags ++ [ "FILESDIR=$(out)/share" diff --git a/pkgs/os-specific/bsd/setup-hook.sh b/pkgs/os-specific/bsd/setup-hook.sh index 7dd7de48ac463..e0afefcd73f71 100644 --- a/pkgs/os-specific/bsd/setup-hook.sh +++ b/pkgs/os-specific/bsd/setup-hook.sh @@ -66,9 +66,9 @@ setBSDSourceDir() { } cdBSDPath() { - if [ -d "$BSD_PATH" ] - then sourceRoot=$sourceRoot/$BSD_PATH - cd $BSD_PATH + if [ -d "$COMPONENT_PATH" ] + then sourceRoot=$sourceRoot/$COMPONENT_PATH + cd $COMPONENT_PATH fi }