about summary refs log tree commit diff
path: root/pkgs/os-specific
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/os-specific')
-rw-r--r--pkgs/os-specific/bsd/freebsd/default.nix9
-rw-r--r--pkgs/os-specific/bsd/netbsd/default.nix1099
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/cksum.nix8
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/column.nix7
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/common.nix3
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-cxx-safe-header.patch (renamed from pkgs/os-specific/bsd/netbsd/compat-cxx-safe-header.patch)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-dont-configure-twice.patch (renamed from pkgs/os-specific/bsd/netbsd/compat-dont-configure-twice.patch)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-no-force-native.patch (renamed from pkgs/os-specific/bsd/netbsd/compat-no-force-native.patch)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-setup-hook.sh (renamed from pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/compat/libbsd-overlay.pc (renamed from pkgs/os-specific/bsd/netbsd/libbsd-overlay.pc)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/compat/package.nix120
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/config.nix18
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/csu.nix24
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/dict.nix9
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/fts/fts-setup-hook.sh (renamed from pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/fts/package.nix41
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/genassym.nix7
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/gencat.nix7
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/getconf.nix7
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/getent/getent.patch (renamed from pkgs/os-specific/bsd/netbsd/getent.patch)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/getent/package.nix8
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/headers.nix11
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/i18n_module.nix9
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/include.nix40
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/install/install-setup-hook.sh (renamed from pkgs/os-specific/bsd/netbsd/install-setup-hook.sh)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/install/package.nix49
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/ld_elf_so.nix18
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libarch.nix8
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libc.nix76
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libcrypt.nix9
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libcurses.nix27
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libedit.nix26
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libm.nix10
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libossaudio.nix8
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libpci.nix11
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libpthread/base.nix6
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libpthread/headers.nix9
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libpthread/package.nix15
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libresolv.nix9
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/librpcsvc.nix21
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/librt.nix13
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libterminfo.nix32
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/libutil.nix21
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/locale/locale.patch (renamed from pkgs/os-specific/bsd/netbsd/locale.patch)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/locale/package.nix9
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/lorder.nix16
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/make.nix60
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/makeMinimal.nix43
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/man.nix17
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/misc.nix9
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/mkDerivation.nix82
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/mknod.nix7
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/mtree.nix8
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/nbperf.nix8
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/netbsdSetupHook/package.nix5
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/netbsdSetupHook/setup-hook.sh (renamed from pkgs/os-specific/bsd/netbsd/setup-hook.sh)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/rpcgen.nix7
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/stat/hook.nix14
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/stat/package.nix19
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/sys/base.nix72
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/sys/headers.nix21
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/sys/no-dynamic-linker.patch (renamed from pkgs/os-specific/bsd/netbsd/no-dynamic-linker.patch)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/sys/package.nix21
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/sys/sys-headers-incsdir.patch (renamed from pkgs/os-specific/bsd/netbsd/sys-headers-incsdir.patch)0
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/tic.nix28
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/tsort.nix16
-rw-r--r--pkgs/os-specific/bsd/netbsd/pkgs/uudecode.nix10
-rw-r--r--pkgs/os-specific/linux/busybox/default.nix2
-rw-r--r--pkgs/os-specific/linux/dbus-broker/default.nix4
-rw-r--r--pkgs/os-specific/linux/dbus-broker/disable-test.patch23
-rw-r--r--pkgs/os-specific/linux/earlyoom/default.nix38
-rw-r--r--pkgs/os-specific/linux/earlyoom/fix-dbus-path.patch11
-rw-r--r--pkgs/os-specific/linux/fw-ectool/default.nix33
-rw-r--r--pkgs/os-specific/linux/intel-compute-runtime/default.nix4
-rw-r--r--pkgs/os-specific/linux/lenovo-legion/app.nix15
-rw-r--r--pkgs/os-specific/linux/mwprocapture/default.nix2
-rw-r--r--pkgs/os-specific/linux/r8125/default.nix4
-rw-r--r--pkgs/os-specific/linux/rtl8852au/default.nix52
-rw-r--r--pkgs/os-specific/linux/sgx/azure-dcap-client/default.nix6
-rw-r--r--pkgs/os-specific/linux/sgx/psw/default.nix10
-rw-r--r--pkgs/os-specific/linux/sgx/sdk/cppmicroservices-no-mtime.patch26
-rw-r--r--pkgs/os-specific/linux/sgx/sdk/default.nix48
-rw-r--r--pkgs/os-specific/linux/sgx/sdk/disable-downloads.patch26
-rw-r--r--pkgs/os-specific/linux/sgx/sdk/ipp-crypto.nix4
-rw-r--r--pkgs/os-specific/linux/sgx/ssl/default.nix36
-rw-r--r--pkgs/os-specific/linux/sgx/ssl/tests.nix95
86 files changed, 1551 insertions, 1155 deletions
diff --git a/pkgs/os-specific/bsd/freebsd/default.nix b/pkgs/os-specific/bsd/freebsd/default.nix
index 1f321f032516f..b7cf5484c9e94 100644
--- a/pkgs/os-specific/bsd/freebsd/default.nix
+++ b/pkgs/os-specific/bsd/freebsd/default.nix
@@ -25,16 +25,11 @@ in makeScopeWithSplicing' {
       sha256 = "BpHqJfnGOeTE7tkFJBx0Wk8ryalmf4KNTit/Coh026E=";
     };
 
-    # Why do we have splicing and yet do `nativeBuildInputs = with self; ...`?
-    # See note in ../netbsd/default.nix.
-
     compatIfNeeded = lib.optional (!stdenvNoCC.hostPlatform.isFreeBSD) self.compat;
-
     freebsd-lib = import ./lib { inherit version; };
 
-    # Overridden arguments avoid cross package-set splicing issues,
-    # otherwise would just use implicit
-    # `lib.packagesFromDirectoryRecursive` auto-call.
+    # The manual callPackages below should in principle be unnecessary, but are
+    # necessary. See note in ../netbsd/default.nix
 
     compat = self.callPackage ./pkgs/compat/package.nix {
       inherit stdenv;
diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix
index 79d46732bd6c2..ff01c2ce62eb6 100644
--- a/pkgs/os-specific/bsd/netbsd/default.nix
+++ b/pkgs/os-specific/bsd/netbsd/default.nix
@@ -1,1028 +1,133 @@
 { stdenv, lib, stdenvNoCC
 , makeScopeWithSplicing', generateSplicesForMkScope
 , buildPackages
-, bsdSetupHook, makeSetupHook, fetchcvs, groff, mandoc, byacc, flex
-, zlib
-, writeShellScript, writeText, runtimeShell, symlinkJoin
+, fetchcvs
 }:
 
-let
-  inherit (buildPackages.buildPackages) rsync;
-
-  fetchNetBSD = path: version: sha256: fetchcvs {
-    cvsRoot = ":pserver:anoncvs@anoncvs.NetBSD.org:/cvsroot";
-    module = "src/${path}";
-    inherit sha256;
-    tag = "netbsd-${lib.replaceStrings ["."] ["-"] version}-RELEASE";
-  };
-
-  netbsdSetupHook = makeSetupHook {
-    name = "netbsd-setup-hook";
-  } ./setup-hook.sh;
-
-  defaultMakeFlags = [
-    "MKSOFTFLOAT=${if stdenv.hostPlatform.gcc.float or (stdenv.hostPlatform.parsed.abi.float or "hard") == "soft"
-      then "yes"
-      else "no"}"
-  ];
-
-in makeScopeWithSplicing' {
+makeScopeWithSplicing' {
   otherSplices = generateSplicesForMkScope "netbsd";
-  f = (self: let
-    inherit (self) mkDerivation;
-  in {
-
-  # Why do we have splicing and yet do `nativeBuildInputs = with self; ...`?
-  #
-  # We use `makeScopeWithSplicing'` because this should be used for all
-  # nested package sets which support cross, so the inner `callPackage` works
-  # correctly. But for the inline packages we don't bother to use
-  # `callPackage`.
-  #
-  # We still could have tried to `with` a big spliced packages set, but
-  # splicing is jank and causes a number of bootstrapping infinite recursions
-  # if one is not careful. Pulling deps out of the right package set directly
-  # side-steps splicing entirely and avoids those footguns.
-  #
-  # For non-bootstrap-critical packages, we might as well use `callPackage` for
-  # consistency with everything else, and maybe put in separate files too.
-
-  compatIfNeeded = lib.optional (!stdenvNoCC.hostPlatform.isNetBSD) self.compat;
-
-  mkDerivation = lib.makeOverridable (attrs: let
-    stdenv' = if attrs.noCC or false then stdenvNoCC else stdenv;
-  in stdenv'.mkDerivation ({
-    pname = "${attrs.pname or (baseNameOf attrs.path)}-netbsd";
-    inherit (attrs) version;
-    src = fetchNetBSD attrs.path attrs.version attrs.sha256;
-
-    extraPaths = [ ];
-
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      install tsort lorder buildPackages.mandoc groff statHook rsync
-    ];
-    buildInputs = with self; compatIfNeeded;
-
-    HOST_SH = stdenv'.shell;
-
-    MACHINE_ARCH = {
-      i486 = "i386";
-      i586 = "i386";
-      i686 = "i386";
-    }.${stdenv'.hostPlatform.parsed.cpu.name}
-      or stdenv'.hostPlatform.parsed.cpu.name;
-
-    MACHINE = {
-      x86_64 = "amd64";
-      aarch64 = "evbarm64";
-      i486 = "i386";
-      i586 = "i386";
-      i686 = "i386";
-    }.${stdenv'.hostPlatform.parsed.cpu.name}
-      or stdenv'.hostPlatform.parsed.cpu.name;
-
-    COMPONENT_PATH = attrs.path;
-
-    makeFlags = defaultMakeFlags;
-
-    strictDeps = true;
-
-    meta = with lib; {
-      maintainers = with maintainers; [ matthewbauer qyliss ];
-      platforms = platforms.unix;
-      license = licenses.bsd2;
+  f = (self: lib.packagesFromDirectoryRecursive {
+    callPackage = self.callPackage;
+    directory = ./pkgs;
+  } // (let inherit (self) mkDerivation; in {
+
+    fetchNetBSD = path: version: sha256: fetchcvs {
+      cvsRoot = ":pserver:anoncvs@anoncvs.NetBSD.org:/cvsroot";
+      module = "src/${path}";
+      inherit sha256;
+      tag = "netbsd-${lib.replaceStrings ["."] ["-"] version}-RELEASE";
     };
 
-  } // lib.optionalAttrs stdenv'.hasCC {
-    # TODO should CC wrapper set this?
-    CPP = "${stdenv'.cc.targetPrefix}cpp";
-  } // lib.optionalAttrs stdenv'.isDarwin {
-    MKRELRO = "no";
-  } // lib.optionalAttrs (stdenv'.cc.isClang or false) {
-    HAVE_LLVM = lib.versions.major (lib.getVersion stdenv'.cc.cc);
-  } // lib.optionalAttrs (stdenv'.cc.isGNU or false) {
-    HAVE_GCC = lib.versions.major (lib.getVersion stdenv'.cc.cc);
-  } // lib.optionalAttrs (stdenv'.isx86_32) {
-    USE_SSP = "no";
-  } // lib.optionalAttrs (attrs.headersOnly or false) {
-    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) ''
-      set +e
-      grep -Zlr "^__RCSID
-      ^__BEGIN_DECLS" $COMPONENT_PATH | xargs -0r grep -FLZ nbtool_config.h |
-          xargs -0tr sed -i '0,/^#/s//#include <nbtool_config.h>\n\0/'
-      set -e
-    '' + attrs.postPatch or "";
-  }));
-
-  ##
-  ## START BOOTSTRAPPING
-  ##
-  makeMinimal = mkDerivation {
-    path = "tools/make";
-    sha256 = "0fh0nrnk18m613m5blrliq2aydciv51qhc0ihsj4k63incwbk90n";
-    version = "9.2";
-
-    buildInputs = with self; [];
-    nativeBuildInputs = with buildPackages.netbsd; [ bsdSetupHook netbsdSetupHook rsync ];
-
-    skipIncludesPhase = true;
-
-    postPatch = ''
-      patchShebangs $COMPONENT_PATH/configure
-      ${self.make.postPatch}
-    '';
-
-    buildPhase = ''
-      runHook preBuild
-
-      sh ./buildmake.sh
-
-      runHook postBuild
-    '';
-
-    installPhase = ''
-      runHook preInstall
-
-      install -D nbmake $out/bin/nbmake
-      ln -s $out/bin/nbmake $out/bin/make
-      mkdir -p $out/share
-      cp -r $BSDSRCDIR/share/mk $out/share/mk
-
-      runHook postInstall
-    '';
-
-    extraPaths = with self; [ make.src ] ++ make.extraPaths;
-  };
-
-  compat = mkDerivation (let
-    version = "9.2";
-    commonDeps = [ zlib ];
-  in {
-    path = "tools/compat";
-    sha256 = "1vsxg7136nlhc72vpa664vs22874xh7ila95nkmsd8crn3z3cyn0";
-    inherit version;
-
-    setupHooks = [
-      ../../../build-support/setup-hooks/role.bash
-      ./compat-setup-hook.sh
-    ];
-
-    preConfigure = ''
-      make include/.stamp configure nbtool_config.h.in defs.mk.in
-    '';
-
-    configurePlatforms = [ "build" "host" ];
-    configureFlags = [
-      "--cache-file=config.cache"
-    ] ++ lib.optionals stdenv.hostPlatform.isMusl [
-      # We include this header in our musl package only for legacy
-      # compatibility, and compat works fine without it (and having it
-      # know about sys/cdefs.h breaks packages like glib when built
-      # statically).
-      "ac_cv_header_sys_cdefs_h=no"
-    ];
-
-    nativeBuildInputs = with buildPackages.netbsd; commonDeps ++ [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      rsync
-    ];
-
-    buildInputs = with self; commonDeps;
-
-    # temporarily use gnuinstall for bootstrapping
-    # bsdinstall will be built later
-    makeFlags = defaultMakeFlags ++ [
-      "INSTALL=${buildPackages.coreutils}/bin/install"
-      "DATADIR=$(out)/share"
-      # Can't sort object files yet
-      "LORDER=echo"
-      "TSORT=cat"
-      # Can't process man pages yet
-      "MKSHARE=no"
-    ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
-      # GNU objcopy produces broken .a libs which won't link into dependers.
-      # Makefiles only invoke `$OBJCOPY -x/-X`, so cctools strip works here.
-      "OBJCOPY=${buildPackages.darwin.cctools-port}/bin/strip"
-    ];
-    RENAME = "-D";
-
-    passthru.tests = { netbsd-install = self.install; };
-
-    patches = [
-      ./compat-cxx-safe-header.patch
-      ./compat-dont-configure-twice.patch
-      ./compat-no-force-native.patch
-    ];
-
-    preInstall = ''
-      makeFlagsArray+=('INSTALL_FILE=''${INSTALL} ''${COPY} ''${PRESERVE} ''${RENAME}')
-      makeFlagsArray+=('INSTALL_DIR=''${INSTALL} -d')
-      makeFlagsArray+=('INSTALL_SYMLINK=''${INSTALL} ''${SYMLINK} ''${RENAME}')
-    '';
-
-    postInstall = ''
-      # why aren't these installed by netbsd?
-      install -D compat_defs.h $out/include/compat_defs.h
-      install -D $BSDSRCDIR/include/cdbw.h $out/include/cdbw.h
-      install -D $BSDSRCDIR/sys/sys/cdbr.h $out/include/cdbr.h
-      install -D $BSDSRCDIR/sys/sys/featuretest.h \
-                 $out/include/sys/featuretest.h
-      install -D $BSDSRCDIR/sys/sys/md5.h $out/include/md5.h
-      install -D $BSDSRCDIR/sys/sys/rmd160.h $out/include/rmd160.h
-      install -D $BSDSRCDIR/sys/sys/sha1.h $out/include/sha1.h
-      install -D $BSDSRCDIR/sys/sys/sha2.h $out/include/sha2.h
-      install -D $BSDSRCDIR/sys/sys/queue.h $out/include/sys/queue.h
-      install -D $BSDSRCDIR/include/vis.h $out/include/vis.h
-      install -D $BSDSRCDIR/include/db.h $out/include/db.h
-      install -D $BSDSRCDIR/include/netconfig.h $out/include/netconfig.h
-      install -D $BSDSRCDIR/include/utmpx.h $out/include/utmpx.h
-      install -D $BSDSRCDIR/include/tzfile.h $out/include/tzfile.h
-      install -D $BSDSRCDIR/sys/sys/tree.h $out/include/sys/tree.h
-      install -D $BSDSRCDIR/include/nl_types.h $out/include/nl_types.h
-      install -D $BSDSRCDIR/include/stringlist.h $out/include/stringlist.h
-
-      # Collapse includes slightly to fix dangling reference
-      install -D $BSDSRCDIR/common/include/rpc/types.h $out/include/rpc/types.h
-      sed -i '1s;^;#include "nbtool_config.h"\n;' $out/include/rpc/types.h
-   '' + lib.optionalString stdenv.isDarwin ''
-      mkdir -p $out/include/ssp
-      touch $out/include/ssp/ssp.h
-   '' + ''
-      mkdir -p $out/lib/pkgconfig
-      substitute ${./libbsd-overlay.pc} $out/lib/pkgconfig/libbsd-overlay.pc \
-        --subst-var-by out $out \
-        --subst-var-by version ${version}
-    '';
-    extraPaths = with self; [ include.src libc.src libutil.src
-      (fetchNetBSD "external/bsd/flex" "9.2" "0h98jpfj7vx5zh7vd7bk6b1hmzgkcb757a8j6d9zgygxxv13v43m")
-      (fetchNetBSD "sys/sys" "9.2" "0zawhw51klaigqqwkx0lzrx3mim2jywrc24cm7c66qsf1im9awgd")
-      (fetchNetBSD "common/include/rpc/types.h" "9.2" "0n2df12mlc3cbc48jxq35yzl1y7ghgpykvy7jnfh898rdhac7m9a")
-    ] ++ libutil.extraPaths ++ _mainLibcExtraPaths;
-  });
-
-  # HACK: to ensure parent directories exist. This emulates GNU
-  # install’s -D option. No alternative seems to exist in BSD install.
-  install = let binstall = writeShellScript "binstall" ''
-    set -eu
-    for last in "$@"; do true; done
-    mkdir -p $(dirname $last)
-    @out@/bin/xinstall "$@"
-  ''; in mkDerivation {
-    path = "usr.bin/xinstall";
-    version = "9.2";
-    sha256 = "1f6pbz3qv1qcrchdxif8p5lbmnwl8b9nq615hsd3cyl4avd5bfqj";
-    extraPaths = with self; [ mtree.src make.src ];
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      mandoc groff rsync
-    ];
-    skipIncludesPhase = true;
-    buildInputs = with self; compatIfNeeded
-      # fts header is needed. glibc already has this header, but musl doesn't,
-      # so make sure pkgsMusl.netbsd.install still builds in case you want to
-      # remove it!
-      ++ [ fts ];
-    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
-    '';
-    setupHook = ./install-setup-hook.sh;
-  };
-
-  fts = mkDerivation {
-    pname = "fts";
-    path = "include/fts.h";
-    sha256 = "01d4fpxvz1pgzfk5xznz5dcm0x0gdzwcsfm1h3d0xc9kc6hj2q77";
-    version = "9.2";
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook rsync
-    ];
-    propagatedBuildInputs = with self; compatIfNeeded;
-    extraPaths = with self; [
-      (fetchNetBSD "lib/libc/gen/fts.c" "9.2" "1a8hmf26242nmv05ipn3ircxb0jqmmi66rh78kkyi9vjwkfl3qn7")
-      (fetchNetBSD "lib/libc/include/namespace.h" "9.2" "0kksr3pdwdc1cplqf5z12ih4cml6l11lqrz91f7hjjm64y7785kc")
-      (fetchNetBSD "lib/libc/gen/fts.3" "9.2" "1asxw0n3fhjdadwkkq3xplfgqgl3q32w1lyrvbakfa3gs0wz5zc1")
-    ];
-    skipIncludesPhase = true;
-    buildPhase = ''
-      "$CC" -c -Iinclude -Ilib/libc/include lib/libc/gen/fts.c \
-          -o lib/libc/gen/fts.o
-      "$AR" -rsc libfts.a lib/libc/gen/fts.o
-    '';
-    installPhase = ''
-      runHook preInstall
-
-      install -D lib/libc/gen/fts.3 $out/share/man/man3/fts.3
-      install -D include/fts.h $out/include/fts.h
-      install -D lib/libc/include/namespace.h $out/include/namespace.h
-      install -D libfts.a $out/lib/libfts.a
-
-      runHook postInstall
-    '';
-    setupHooks = [
-      ../../../build-support/setup-hooks/role.bash
-      ./fts-setup-hook.sh
-    ];
-  };
-
-  # Don't add this to nativeBuildInputs directly.  Use statHook instead.
-  stat = mkDerivation {
-    path = "usr.bin/stat";
-    version = "9.2";
-    sha256 = "18nqwlndfc34qbbgqx5nffil37jfq9aw663ippasfxd2hlyc106x";
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      install mandoc groff rsync
-    ];
-  };
-
-  # stat isn't in POSIX, and NetBSD stat supports a completely
-  # different range of flags than GNU stat, so including it in PATH
-  # breaks stdenv.  Work around that with a hook that will point
-  # NetBSD's build system and NetBSD stat without including it in
-  # PATH.
-  statHook = makeSetupHook {
-    name = "netbsd-stat-hook";
-  } (writeText "netbsd-stat-hook-impl" ''
-    makeFlagsArray+=(TOOL_STAT=${self.stat}/bin/stat)
-  '');
-
-  tsort = mkDerivation {
-    path = "usr.bin/tsort";
-    version = "9.2";
-    sha256 = "1dqvf9gin29nnq3c4byxc7lfd062pg7m84843zdy6n0z63hnnwiq";
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      install mandoc groff rsync
-    ];
-  };
-
-  lorder = mkDerivation {
-    path = "usr.bin/lorder";
-    version = "9.2";
-    sha256 = "0rjf9blihhm0n699vr2bg88m4yjhkbxh6fxliaay3wxkgnydjwn2";
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      install mandoc groff rsync
-    ];
-  };
-
-  ##
-  ## END BOOTSTRAPPING
-  ##
-
-  ##
-  ## START COMMAND LINE TOOLS
-  ##
-  make = mkDerivation {
-    path = "usr.bin/make";
-    sha256 = "0vi73yicbmbp522qzqvd979cx6zm5jakhy77xh73c1kygf8klccs";
-    version = "9.2";
-
-   postPatch = ''
-     substituteInPlace $BSDSRCDIR/share/mk/bsd.doc.mk \
-       --replace '-o ''${DOCOWN}' "" \
-       --replace '-g ''${DOCGRP}' ""
-     for mk in $BSDSRCDIR/share/mk/bsd.inc.mk $BSDSRCDIR/share/mk/bsd.kinc.mk; do
-       substituteInPlace $mk \
-         --replace '-o ''${BINOWN}' "" \
-         --replace '-g ''${BINGRP}' ""
-     done
-     substituteInPlace $BSDSRCDIR/share/mk/bsd.kmodule.mk \
-       --replace '-o ''${KMODULEOWN}' "" \
-       --replace '-g ''${KMODULEGRP}' ""
-     substituteInPlace $BSDSRCDIR/share/mk/bsd.lib.mk \
-       --replace '-o ''${LIBOWN}' "" \
-       --replace '-g ''${LIBGRP}' "" \
-       --replace '-o ''${DEBUGOWN}' "" \
-       --replace '-g ''${DEBUGGRP}' ""
-     substituteInPlace $BSDSRCDIR/share/mk/bsd.lua.mk \
-       --replace '-o ''${LIBOWN}' "" \
-       --replace '-g ''${LIBGRP}' ""
-     substituteInPlace $BSDSRCDIR/share/mk/bsd.man.mk \
-       --replace '-o ''${MANOWN}' "" \
-       --replace '-g ''${MANGRP}' ""
-     substituteInPlace $BSDSRCDIR/share/mk/bsd.nls.mk \
-       --replace '-o ''${NLSOWN}' "" \
-       --replace '-g ''${NLSGRP}' ""
-     substituteInPlace $BSDSRCDIR/share/mk/bsd.prog.mk \
-       --replace '-o ''${BINOWN}' "" \
-       --replace '-g ''${BINGRP}' "" \
-       --replace '-o ''${RUMPBINOWN}' "" \
-       --replace '-g ''${RUMPBINGRP}' "" \
-       --replace '-o ''${DEBUGOWN}' "" \
-       --replace '-g ''${DEBUGGRP}' ""
-
-      # make needs this to pick up our sys make files
-      export NIX_CFLAGS_COMPILE+=" -D_PATH_DEFSYSPATH=\"$out/share/mk\""
-
-      substituteInPlace $BSDSRCDIR/share/mk/bsd.lib.mk \
-        --replace '_INSTRANLIB=''${empty(PRESERVE):?-a "''${RANLIB} -t":}' '_INSTRANLIB='
-      substituteInPlace $BSDSRCDIR/share/mk/bsd.kinc.mk \
-        --replace /bin/rm rm
-    '' + lib.optionalString stdenv.isDarwin ''
-      substituteInPlace $BSDSRCDIR/share/mk/bsd.sys.mk \
-        --replace '-Wl,--fatal-warnings' "" \
-        --replace '-Wl,--warn-shared-textrel' ""
-    '';
-    postInstall = ''
-      make -C $BSDSRCDIR/share/mk FILESDIR=$out/share/mk install
-    '';
-    extraPaths = [
-      (fetchNetBSD "share/mk" "9.2" "0w9x77cfnm6zwy40slradzi0ip9gz80x6lk7pvnlxzsr2m5ra5sy")
-    ];
-  };
-
-  mtree = mkDerivation {
-    path = "usr.sbin/mtree";
-    version = "9.2";
-    sha256 = "04p7w540vz9npvyb8g8hcf2xa05phn1y88hsyrcz3vwanvpc0yv9";
-    extraPaths = with self; [ mknod.src ];
-  };
-
-  mknod = mkDerivation {
-    path = "sbin/mknod";
-    version = "9.2";
-    sha256 = "1d9369shzwgixz3nph991i8q5vk7hr04py3n9avbfbhzy4gndqs2";
-  };
-
-  getent = mkDerivation {
-    path = "usr.bin/getent";
-    sha256 = "1qngywcmm0y7nl8h3n8brvkxq4jw63szbci3kc1q6a6ndhycbbvr";
-    version = "9.2";
-    patches = [ ./getent.patch ];
-  };
-
-  getconf = mkDerivation {
-    path = "usr.bin/getconf";
-    sha256 = "122vslz4j3h2mfs921nr2s6m078zcj697yrb75rwp2hnw3qz4s8q";
-    version = "9.2";
-  };
-
-  locale = mkDerivation {
-    path = "usr.bin/locale";
-    version = "9.2";
-    sha256 = "0kk6v9k2bygq0wf9gbinliqzqpzs9bgxn0ndyl2wcv3hh2bmsr9p";
-    patches = [ ./locale.patch ];
-    env.NIX_CFLAGS_COMPILE = "-DYESSTR=__YESSTR -DNOSTR=__NOSTR";
-  };
-
-  rpcgen = mkDerivation {
-    path = "usr.bin/rpcgen";
-    version = "9.2";
-    sha256 = "1kfgfx54jg98wbg0d95p0rvf4w0302v8fz724b0bdackdsrd4988";
-  };
-
-  genassym = mkDerivation {
-    path = "usr.bin/genassym";
-    version = "9.2";
-    sha256 = "1acl1dz5kvh9h5806vkz2ap95rdsz7phmynh5i3x5y7agbki030c";
-  };
-
-  gencat = mkDerivation {
-    path = "usr.bin/gencat";
-    version = "9.2";
-    sha256 = "0gd463x1hg36bhr7y0xryb5jyxk0z0g7xvy8rgk82nlbnlnsbbwb";
-  };
-
-  nbperf = mkDerivation {
-    path = "usr.bin/nbperf";
-    version = "9.2";
-    sha256 = "1nxc302vgmjhm3yqdivqyfzslrg0vjpbss44s74rcryrl19mma9r";
-  };
-
-  tic = mkDerivation {
-    path = "tools/tic";
-    version = "9.2";
-    sha256 = "092y7db7k4kh2jq8qc55126r5qqvlb8lq8mhmy5ipbi36hwb4zrz";
-    HOSTPROG = "tic";
-    buildInputs = with self; compatIfNeeded;
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      install mandoc groff nbperf rsync
-    ];
-    makeFlags = defaultMakeFlags ++ [ "TOOLDIR=$(out)" ];
-    extraPaths = with self; [
-      libterminfo.src
-      (fetchNetBSD "usr.bin/tic" "9.2" "1mwdfg7yx1g43ss378qsgl5rqhsxskqvsd2mqvrn38qw54i8v5i1")
-      (fetchNetBSD "tools/Makefile.host" "9.2" "15b4ab0n36lqj00j5lz2xs83g7l8isk3wx1wcapbrn66qmzz2sxy")
+    defaultMakeFlags = [
+      "MKSOFTFLOAT=${if stdenv.hostPlatform.gcc.float or (stdenv.hostPlatform.parsed.abi.float or "hard") == "soft"
+        then "yes"
+        else "no"}"
     ];
-  };
 
-  uudecode = mkDerivation {
-    path = "usr.bin/uudecode";
-    version = "9.2";
-    sha256 = "00a3zmh15pg4vx6hz0kaa5mi8d2b1sj4h512d7p6wbvxq6mznwcn";
-    env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isLinux "-DNO_BASE64";
-    NIX_LDFLAGS = lib.optional stdenv.isDarwin "-lresolv";
-  };
+    compatIfNeeded = lib.optional (!stdenvNoCC.hostPlatform.isNetBSD) self.compat;
 
-  cksum = mkDerivation {
-    path = "usr.bin/cksum";
-    version = "9.2";
-    sha256 = "0msfhgyvh5c2jmc6qjnf12c378dhw32ffsl864qz4rdb2b98rfcq";
-    meta.platforms = lib.platforms.netbsd;
-  };
+    # The manual callPackages below should in principle be unnecessary because
+    # they're just selecting arguments that would be selected anyway. However,
+    # if we don't perform these manual calls, we get infinite recursion issues
+    # because of the splices.
 
-  config = mkDerivation {
-    path = "usr.bin/config";
-    version = "9.2";
-    sha256 = "1yz3n4hncdkk6kp595fh2q5lg150vpqg8iw2dccydkyw4y3hgsjj";
-    env.NIX_CFLAGS_COMPILE = toString [ "-DMAKE_BOOTSTRAP" ];
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal install mandoc byacc flex rsync
-    ];
-    buildInputs = with self; compatIfNeeded;
-    extraPaths = with self; [ cksum.src ];
-  };
-  ##
-  ## END COMMAND LINE TOOLS
-  ##
-
-  ##
-  ## START HEADERS
-  ##
-  include = mkDerivation {
-    path = "include";
-    version = "9.2";
-    sha256 = "0nxnmj4c8s3hb9n3fpcmd0zl3l1nmhivqgi9a35sis943qvpgl9h";
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      install mandoc groff rsync nbperf rpcgen
-    ];
-
-    # The makefiles define INCSDIR per subdirectory, so we have to set
-    # something else on the command line so those definitions aren't
-    # overridden.
-    postPatch = ''
-      find "$BSDSRCDIR" -name Makefile -exec \
-        sed -i -E \
-          -e 's_/usr/include_''${INCSDIR0}_' \
-          {} \;
-    '';
-
-    # multiple header dirs, see above
-    postConfigure = ''
-      makeFlags=''${makeFlags/INCSDIR/INCSDIR0}
-    '';
-
-    extraPaths = with self; [ common ];
-    headersOnly = true;
-    noCC = true;
-    meta.platforms = lib.platforms.netbsd;
-    makeFlags = defaultMakeFlags ++ [ "RPCGEN_CPP=${buildPackages.stdenv.cc.cc}/bin/cpp" ];
-  };
-
-  common = fetchNetBSD "common" "9.2" "1pfylz9r3ap5wnwwbwczbfjb1m5qdyspzbnmxmcdkpzz2zgj64b9";
-
-  sys-headers = mkDerivation {
-    pname = "sys-headers";
-    path = "sys";
-    version = "9.2";
-    sha256 = "03s18q8d9giipf05bx199fajc2qwikji0djz7hw63d2lya6bfnpj";
-
-    # Make the build ignore linker warnings
-    prePatch = ''
-      substituteInPlace sys/conf/Makefile.kern.inc \
-        --replace "-Wa,--fatal-warnings" ""
-    '';
-
-    patches = [
-      # Fix this error when building bootia32.efi and bootx64.efi:
-      # error: PHDR segment not covered by LOAD segment
-      ./no-dynamic-linker.patch
-
-      # multiple header dirs, see above
-      ./sys-headers-incsdir.patch
-    ];
+    mkDerivation = self.callPackage ./pkgs/mkDerivation.nix {
+      inherit stdenv stdenvNoCC;
+      inherit (buildPackages.netbsd) netbsdSetupHook makeMinimal install tsort lorder;
+      inherit (buildPackages) mandoc;
+      inherit (buildPackages.buildPackages) rsync;
 
-    postPatch =
-      ''
-        substituteInPlace sys/arch/i386/stand/efiboot/Makefile.efiboot \
-          --replace "-nocombreloc" "-z nocombreloc"
-      '' +
-      # multiple header dirs, see above
-      self.include.postPatch;
-
-    CONFIG = "GENERIC";
-
-    propagatedBuildInputs = with self; [ include ];
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal install tsort lorder statHook rsync uudecode config genassym
-    ];
-
-    postConfigure = ''
-      pushd arch/$MACHINE/conf
-      config $CONFIG
-      popd
-    ''
-      # multiple header dirs, see above
-      + self.include.postConfigure;
-
-    makeFlags = defaultMakeFlags ++ [ "FIRMWAREDIR=$(out)/libdata/firmware" ];
-    hardeningDisable = [ "pic" ];
-    MKKMOD = "no";
-    env.NIX_CFLAGS_COMPILE = toString [
-      "-Wno-error=array-parameter"
-      "-Wno-error=array-bounds"
-      "-Wa,--no-warn"
-    ];
-
-    postBuild = ''
-      make -C arch/$MACHINE/compile/$CONFIG $makeFlags
-    '';
-
-    postInstall = ''
-      cp arch/$MACHINE/compile/$CONFIG/netbsd $out
-    '';
-
-    meta.platforms = lib.platforms.netbsd;
-    extraPaths = with self; [ common ];
-
-    installPhase = "includesPhase";
-    dontBuild = true;
-    noCC = true;
-  };
-
-  # The full kernel. We do the funny thing of overridding the headers to the
-  # full kernal and not vice versa to avoid infinite recursion -- the headers
-  # come earlier in the bootstrap.
-  sys = self.sys-headers.override {
-    pname = "sys";
-    installPhase = null;
-    noCC = false;
-    dontBuild = false;
-  };
-
-  headers = symlinkJoin {
-    name = "netbsd-headers-9.2";
-    paths = with self; [
-      include
-      sys-headers
-      libpthread-headers
-    ];
-    meta.platforms = lib.platforms.netbsd;
-  };
-  ##
-  ## END HEADERS
-  ##
-
-  ##
-  ## START LIBRARIES
-  ##
-  libarch = mkDerivation {
-    path = "lib/libarch";
-    version = "9.2";
-    sha256 = "6ssenRhuSwp0Jn71ErT0PrEoCJ+cIYRztwdL4QTDZsQ=";
-    meta.platforms = lib.platforms.netbsd;
-  };
-
-  libutil = mkDerivation {
-    path = "lib/libutil";
-    version = "9.2";
-    sha256 = "02gm5a5zhh8qp5r5q5r7x8x6x50ir1i0ncgsnfwh1vnrz6mxbq7z";
-    extraPaths = with self; [ common libc.src sys.src ];
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      byacc install tsort lorder mandoc statHook rsync
-    ];
-    buildInputs = with self; [ headers ];
-    SHLIBINSTALLDIR = "$(out)/lib";
-  };
-
-  libedit = mkDerivation {
-    path = "lib/libedit";
-    version = "9.2";
-    sha256 = "1wqhngraxwqk4jgrf5f18jy195yrp7c06n1gf31pbplq79mg1bcj";
-    buildInputs = with self; [ libterminfo libcurses ];
-    propagatedBuildInputs = with self; compatIfNeeded;
-    SHLIBINSTALLDIR = "$(out)/lib";
-    makeFlags = defaultMakeFlags ++ [ "LIBDO.terminfo=${self.libterminfo}/lib" ];
-    postPatch = ''
-      sed -i '1i #undef bool_t' $COMPONENT_PATH/el.h
-      substituteInPlace $COMPONENT_PATH/config.h \
-        --replace "#define HAVE_STRUCT_DIRENT_D_NAMLEN 1" ""
-      substituteInPlace $COMPONENT_PATH/readline/Makefile --replace /usr/include "$out/include"
-    '';
-    env.NIX_CFLAGS_COMPILE = toString [
-      "-D__noinline="
-      "-D__scanflike(a,b)="
-      "-D__va_list=va_list"
-    ];
-  };
-
-  libterminfo = mkDerivation {
-    path = "lib/libterminfo";
-    version = "9.2";
-    sha256 = "0pq05k3dj0dfsczv07frnnji92mazmy2qqngqbx2zgqc1x251414";
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal install tsort lorder mandoc statHook nbperf tic rsync
-    ];
-    buildInputs = with self; compatIfNeeded;
-    SHLIBINSTALLDIR = "$(out)/lib";
-    postPatch = ''
-      substituteInPlace $COMPONENT_PATH/term.c --replace /usr/share $out/share
-      substituteInPlace $COMPONENT_PATH/setupterm.c \
-        --replace '#include <curses.h>' 'void use_env(bool);'
-    '';
-    postBuild = ''
-      make -C $BSDSRCDIR/share/terminfo $makeFlags BINDIR=$out/share
-    '';
-    postInstall = ''
-      make -C $BSDSRCDIR/share/terminfo $makeFlags BINDIR=$out/share install
-    '';
-    extraPaths = with self; [
-      (fetchNetBSD "share/terminfo" "9.2" "1vh9rl4w8118a9qdpblfxmv1wkpm83rm9gb4rzz5bpm56i6d7kk7")
-    ];
-  };
-
-  libcurses = mkDerivation {
-    path = "lib/libcurses";
-    version = "9.2";
-    sha256 = "0pd0dggl3w4bv5i5h0s1wrc8hr66n4hkv3zlklarwfdhc692fqal";
-    buildInputs = with self; [ libterminfo ];
-    env.NIX_CFLAGS_COMPILE = toString ([
-      "-D__scanflike(a,b)="
-      "-D__va_list=va_list"
-      "-D__warn_references(a,b)="
-    ] ++ lib.optional stdenv.isDarwin "-D__strong_alias(a,b)=");
-    propagatedBuildInputs = with self; compatIfNeeded;
-    MKDOC = "no"; # missing vfontedpr
-    makeFlags = defaultMakeFlags ++ [ "LIBDO.terminfo=${self.libterminfo}/lib" ];
-    postPatch = lib.optionalString (!stdenv.isDarwin) ''
-      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 $COMPONENT_PATH/scanw.c \
-        --replace "__strong_alias(vwscanw, vw_scanw)" 'extern int vwscanw(WINDOW*, const char*, va_list) __attribute__ ((alias ("vw_scanw")));'
-    '';
-  };
-
-  column = mkDerivation {
-    path = "usr.bin/column";
-    version = "9.2";
-    sha256 = "0r6b0hjn5ls3j3sv6chibs44fs32yyk2cg8kh70kb4cwajs4ifyl";
-  };
+    };
 
-  libossaudio = mkDerivation {
-    path = "lib/libossaudio";
-    version = "9.2";
-    sha256 = "16l3bfy6dcwqnklvh3x0ps8ld1y504vf57v9rx8f9adzhb797jh0";
-    meta.platforms = lib.platforms.netbsd;
-  };
+    makeMinimal = self.callPackage ./pkgs/makeMinimal.nix {
+      inherit (self) make;
+    };
 
-  librpcsvc = mkDerivation {
-    path = "lib/librpcsvc";
-    version = "9.2";
-    sha256 = "1q34pfiyjbrgrdqm46jwrsqms49ly6z3b0xh1wg331zga900vq5n";
-    makeFlags = defaultMakeFlags ++ [ "INCSDIR=$(out)/include/rpcsvc" ];
-    meta.platforms = lib.platforms.netbsd;
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      install tsort lorder rpcgen statHook
-    ];
-  };
+    compat = self.callPackage ./pkgs/compat/package.nix {
+      inherit (buildPackages) coreutils;
+      inherit (buildPackages.darwin) cctools-port;
+      inherit (buildPackages.buildPackages) rsync;
+      inherit (buildPackages.netbsd) makeMinimal;
+      inherit (self) install include libc libutil;
+    };
 
-  librt = mkDerivation {
-    path = "lib/librt";
-    version = "9.2";
-    sha256 = "07f8mpjcqh5kig5z5sp97fg55mc4dz6aa1x5g01nv2pvbmqczxc6";
-    meta.platforms = lib.platforms.netbsd;
-    extraPaths = with self; [ libc.src ] ++ libc.extraPaths;
-    postPatch = ''
-      sed -i 's,/usr\(/include/sys/syscall.h\),${self.headers}\1,g' \
-        $BSDSRCDIR/lib/{libc,librt}/sys/Makefile.inc
-    '';
-  };
+    install = self.callPackage ./pkgs/install/package.nix {
+      inherit (self) fts mtree make compatIfNeeded;
+      inherit (buildPackages.buildPackages) rsync;
+      inherit (buildPackages.netbsd) makeMinimal;
+    };
 
-  libcrypt = mkDerivation {
-    path = "lib/libcrypt";
-    version = "9.2";
-    sha256 = "0siqan1wdqmmhchh2n8w6a8x1abbff8n4yb6jrqxap3hqn8ay54g";
-    SHLIBINSTALLDIR = "$(out)/lib";
-    meta.platforms = lib.platforms.netbsd;
-  };
+    # See note in pkgs/stat/package.nix
+    stat = self.callPackage ./pkgs/stat/package.nix {
+      inherit (buildPackages.netbsd) makeMinimal install;
+      inherit (buildPackages.buildPackages) rsync;
+    };
 
-  libpci = mkDerivation {
-    pname = "libpci";
-    path = "lib/libpci";
-    version = "9.2";
-    sha256 = "+IOEO1Bw3/H3iCp3uk3bwsFZbvCqN5Ciz70irnPl8E8=";
-    env.NIX_CFLAGS_COMPILE = toString [ "-I." ];
-    meta.platforms = lib.platforms.netbsd;
-    extraPaths = with self; [ sys.src ];
-  };
+    # See note in pkgs/stat/hook.nix
+    statHook = self.callPackage ./pkgs/stat/hook.nix {
+      inherit (self) stat;
+    };
 
-  libpthread-headers = mkDerivation {
-    pname = "libpthread-headers";
-    path = "lib/libpthread";
-    version = "9.2";
-    sha256 = "0mlmc31k509dwfmx5s2x010wxjc44mr6y0cbmk30cfipqh8c962h";
-    installPhase = "includesPhase";
-    dontBuild = true;
-    noCC = true;
-    meta.platforms = lib.platforms.netbsd;
-  };
+    tsort = self.callPackage ./pkgs/tsort.nix {
+      inherit (buildPackages.netbsd) makeMinimal install;
+      inherit (buildPackages.buildPackages) rsync;
+    };
 
-  libpthread = self.libpthread-headers.override {
-    pname = "libpthread";
-    installPhase = null;
-    noCC = false;
-    dontBuild = false;
-    buildInputs = with self; [ headers ];
-    SHLIBINSTALLDIR = "$(out)/lib";
-    extraPaths = with self; [ common libc.src librt.src sys.src ];
-  };
+    lorder = self.callPackage ./pkgs/lorder.nix {
+      inherit (buildPackages.netbsd) makeMinimal install;
+      inherit (buildPackages.buildPackages) rsync;
+    };
 
-  libresolv = mkDerivation {
-    path = "lib/libresolv";
-    version = "9.2";
-    sha256 = "1am74s74mf1ynwz3p4ncjkg63f78a1zjm983q166x4sgzps15626";
-    meta.platforms = lib.platforms.netbsd;
-    extraPaths = with self; [ libc.src ];
-  };
+    config = self.callPackage ./pkgs/config.nix {
+      inherit (buildPackages.netbsd) makeMinimal install;
+      inherit (buildPackages.buildPackages) rsync;
+      inherit (self) cksum;
+    };
 
-  libm = mkDerivation {
-    path = "lib/libm";
-    version = "9.2";
-    sha256 = "1apwfr26shdmbqqnmg7hxf7bkfxw44ynqnnnghrww9bnhqdnsy92";
-    SHLIBINSTALLDIR = "$(out)/lib";
-    meta.platforms = lib.platforms.netbsd;
-    extraPaths = with self; [ sys.src ];
-  };
+    include = self.callPackage ./pkgs/include.nix {
+      inherit (buildPackages.netbsd)
+        makeMinimal install nbperf rpcgen;
+      inherit (buildPackages) stdenv;
+      inherit (buildPackages.buildPackages) rsync;
+    };
 
-  i18n_module = mkDerivation {
-    path = "lib/i18n_module";
-    version = "9.2";
-    sha256 = "0w6y5v3binm7gf2kn7y9jja8k18rhnyl55cvvfnfipjqdxvxd9jd";
-    meta.platforms = lib.platforms.netbsd;
-    extraPaths = with self; [ libc.src ];
-  };
+    sys-headers = self.callPackage ./pkgs/sys/headers.nix {
+      inherit (buildPackages.netbsd)
+        makeMinimal install tsort lorder statHook uudecode config genassym;
+      inherit (buildPackages.buildPackages) rsync;
+    };
 
-  csu = mkDerivation {
-    path = "lib/csu";
-    version = "9.2";
-    sha256 = "0al5jfazvhlzn9hvmnrbchx4d0gm282hq5gp4xs2zmj9ycmf6d03";
-    meta.platforms = lib.platforms.netbsd;
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      install mandoc groff flex
-      byacc genassym gencat lorder tsort statHook rsync
-    ];
-    buildInputs = with self; [ headers ];
-    extraPaths = with self; [ sys.src ld_elf_so.src ];
-  };
+    libutil = self.callPackage ./pkgs/libutil.nix {
+      inherit (self) libc sys;
+    };
 
-  ld_elf_so = mkDerivation {
-    path  = "libexec/ld.elf_so";
-    version = "9.2";
-    sha256 = "0ia9mqzdljly0vqfwflm5mzz55k7qsr4rw2bzhivky6k30vgirqa";
-    meta.platforms = lib.platforms.netbsd;
-    LIBC_PIC = "${self.libc}/lib/libc_pic.a";
-    # Hack to prevent a symlink being installed here for compatibility.
-    SHLINKINSTALLDIR = "/usr/libexec";
-    USE_FORT = "yes";
-    makeFlags = defaultMakeFlags ++ [ "BINDIR=$(out)/libexec" "CLIBOBJ=${self.libc}/lib" ];
-    extraPaths = with self; [ libc.src ] ++ libc.extraPaths;
-  };
+    libpthread-headers = self.callPackage ./pkgs/libpthread/headers.nix { };
 
-  _mainLibcExtraPaths = with self; [
-      common i18n_module.src sys.src
-      ld_elf_so.src libpthread.src libm.src libresolv.src
-      librpcsvc.src libutil.src librt.src libcrypt.src
-  ];
+    csu = self.callPackage ./pkgs/csu.nix {
+      inherit (self) headers sys ld_elf_so;
+      inherit (buildPackages.netbsd)
+        netbsdSetupHook
+        makeMinimal
+        install
+        genassym gencat lorder tsort statHook;
+      inherit (buildPackages.buildPackages) rsync;
+    };
 
-  libc = mkDerivation {
-    path = "lib/libc";
-    version = "9.2";
-    sha256 = "1y9c13igg0kai07sqvf9cm6yqmd8lhfd8hq3q7biilbgs1l99as3";
-    USE_FORT = "yes";
-    MKPROFILE = "no";
-    extraPaths = with self; _mainLibcExtraPaths ++ [
-      (fetchNetBSD "external/bsd/jemalloc" "9.2" "0cq704swa0h2yxv4gc79z2lwxibk9k7pxh3q5qfs7axx3jx3n8kb")
-    ];
-    nativeBuildInputs = with buildPackages.netbsd; [
-      bsdSetupHook netbsdSetupHook
-      makeMinimal
-      install mandoc groff flex
-      byacc genassym gencat lorder tsort statHook rsync rpcgen
+    _mainLibcExtraPaths = with self; [
+        common i18n_module.src sys.src
+        ld_elf_so.src libpthread.src libm.src libresolv.src
+        librpcsvc.src libutil.src librt.src libcrypt.src
     ];
-    buildInputs = with self; [ headers csu ];
-    env.NIX_CFLAGS_COMPILE = "-B${self.csu}/lib -fcommon";
-    meta.platforms = lib.platforms.netbsd;
-    SHLIBINSTALLDIR = "$(out)/lib";
-    MKPICINSTALL = "yes";
-    NLSDIR = "$(out)/share/nls";
-    makeFlags = defaultMakeFlags ++ [ "FILESDIR=$(out)/var/db"];
-    postInstall = ''
-      pushd ${self.headers}
-      find . -type d -exec mkdir -p $out/\{} \;
-      find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
-      popd
-
-      pushd ${self.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"
-
-      make -C $BSDSRCDIR/lib/libpthread $makeFlags
-      make -C $BSDSRCDIR/lib/libpthread $makeFlags install
-
-      make -C $BSDSRCDIR/lib/libm $makeFlags
-      make -C $BSDSRCDIR/lib/libm $makeFlags install
-
-      make -C $BSDSRCDIR/lib/libresolv $makeFlags
-      make -C $BSDSRCDIR/lib/libresolv $makeFlags install
-
-      make -C $BSDSRCDIR/lib/librpcsvc $makeFlags
-      make -C $BSDSRCDIR/lib/librpcsvc $makeFlags install
 
-      make -C $BSDSRCDIR/lib/i18n_module $makeFlags
-      make -C $BSDSRCDIR/lib/i18n_module $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
-    '';
-    inherit (self.librt) postPatch;
-  };
-  #
-  # END LIBRARIES
-  #
-
-  #
-  # START MISCELLANEOUS
-  #
-  dict = mkDerivation {
-    path = "share/dict";
-    noCC = true;
-    version = "9.2";
-    sha256 = "0svfc0byk59ri37pyjslv4c4rc7zw396r73mr593i78d39q5g3ad";
-    makeFlags = defaultMakeFlags ++ [ "BINDIR=$(out)/share" ];
-  };
-
-  misc = mkDerivation {
-    path = "share/misc";
-    noCC = true;
-    version = "9.2";
-    sha256 = "1j2cdssdx6nncv8ffj7f7ybl7m9hadjj8vm8611skqdvxnjg6nbc";
-    makeFlags = defaultMakeFlags ++ [ "BINDIR=$(out)/share" ];
-  };
-
-  man = mkDerivation {
-    path = "share/man";
-    noCC = true;
-    version = "9.2";
-    sha256 = "1l4lmj4kmg8dl86x94sr45w0xdnkz8dn4zjx0ipgr9bnq98663zl";
-    # man0 generates a man.pdf using ps2pdf, but doesn't install it later,
-    # so we can avoid the dependency on ghostscript
-    postPatch = ''
-      substituteInPlace $COMPONENT_PATH/man0/Makefile --replace "ps2pdf" "echo noop "
-    '';
-    makeFlags = defaultMakeFlags ++ [
-      "FILESDIR=$(out)/share"
-      "MKRUMP=no" # would require to have additional path sys/rump/share/man
-    ];
-  };
-  #
-  # END MISCELLANEOUS
-  #
+    libc = self.callPackage ./pkgs/libc.nix {
+      inherit (self) headers csu librt;
+      inherit (buildPackages.netbsd)
+        netbsdSetupHook
+        makeMinimal
+        install
+        genassym gencat lorder tsort statHook rpcgen;
+      inherit (buildPackages.buildPackages) rsync;
+    };
 
-});
+  }));
 }
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/cksum.nix b/pkgs/os-specific/bsd/netbsd/pkgs/cksum.nix
new file mode 100644
index 0000000000000..a2ec387501ae1
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/cksum.nix
@@ -0,0 +1,8 @@
+{ lib, mkDerivation }:
+
+mkDerivation {
+  path = "usr.bin/cksum";
+  version = "9.2";
+  sha256 = "0msfhgyvh5c2jmc6qjnf12c378dhw32ffsl864qz4rdb2b98rfcq";
+  meta.platforms = lib.platforms.netbsd;
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/column.nix b/pkgs/os-specific/bsd/netbsd/pkgs/column.nix
new file mode 100644
index 0000000000000..f3cebfa9ab261
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/column.nix
@@ -0,0 +1,7 @@
+{ mkDerivation }:
+
+mkDerivation {
+  path = "usr.bin/column";
+  version = "9.2";
+  sha256 = "0r6b0hjn5ls3j3sv6chibs44fs32yyk2cg8kh70kb4cwajs4ifyl";
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/common.nix b/pkgs/os-specific/bsd/netbsd/pkgs/common.nix
new file mode 100644
index 0000000000000..464fc1c9e0c26
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/common.nix
@@ -0,0 +1,3 @@
+{ fetchNetBSD }:
+
+fetchNetBSD "common" "9.2" "1pfylz9r3ap5wnwwbwczbfjb1m5qdyspzbnmxmcdkpzz2zgj64b9"
diff --git a/pkgs/os-specific/bsd/netbsd/compat-cxx-safe-header.patch b/pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-cxx-safe-header.patch
index 2aaa90b76146b..2aaa90b76146b 100644
--- a/pkgs/os-specific/bsd/netbsd/compat-cxx-safe-header.patch
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-cxx-safe-header.patch
diff --git a/pkgs/os-specific/bsd/netbsd/compat-dont-configure-twice.patch b/pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-dont-configure-twice.patch
index 2758e256a6168..2758e256a6168 100644
--- a/pkgs/os-specific/bsd/netbsd/compat-dont-configure-twice.patch
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-dont-configure-twice.patch
diff --git a/pkgs/os-specific/bsd/netbsd/compat-no-force-native.patch b/pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-no-force-native.patch
index 117fb7e042982..117fb7e042982 100644
--- a/pkgs/os-specific/bsd/netbsd/compat-no-force-native.patch
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-no-force-native.patch
diff --git a/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh b/pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-setup-hook.sh
index acd90b7aa2f0e..acd90b7aa2f0e 100644
--- a/pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/compat/compat-setup-hook.sh
diff --git a/pkgs/os-specific/bsd/netbsd/libbsd-overlay.pc b/pkgs/os-specific/bsd/netbsd/pkgs/compat/libbsd-overlay.pc
index 3aadabe508822..3aadabe508822 100644
--- a/pkgs/os-specific/bsd/netbsd/libbsd-overlay.pc
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/compat/libbsd-overlay.pc
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/compat/package.nix b/pkgs/os-specific/bsd/netbsd/pkgs/compat/package.nix
new file mode 100644
index 0000000000000..a1336ad52f6dc
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/compat/package.nix
@@ -0,0 +1,120 @@
+{ lib, mkDerivation, stdenv
+, zlib
+, defaultMakeFlags
+, coreutils
+, cctools-port
+, include, libc, libutil
+, install
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, rsync
+, fetchNetBSD
+, _mainLibcExtraPaths
+}:
+
+mkDerivation (let
+    version = "9.2";
+    commonDeps = [ zlib ];
+  in {
+    path = "tools/compat";
+    sha256 = "1vsxg7136nlhc72vpa664vs22874xh7ila95nkmsd8crn3z3cyn0";
+    inherit version;
+
+    setupHooks = [
+      ../../../../../build-support/setup-hooks/role.bash
+      ./compat-setup-hook.sh
+    ];
+
+    preConfigure = ''
+      make include/.stamp configure nbtool_config.h.in defs.mk.in
+    '';
+
+    configurePlatforms = [ "build" "host" ];
+    configureFlags = [
+      "--cache-file=config.cache"
+    ] ++ lib.optionals stdenv.hostPlatform.isMusl [
+      # We include this header in our musl package only for legacy
+      # compatibility, and compat works fine without it (and having it
+      # know about sys/cdefs.h breaks packages like glib when built
+      # statically).
+      "ac_cv_header_sys_cdefs_h=no"
+    ];
+
+    nativeBuildInputs = commonDeps ++ [
+      bsdSetupHook netbsdSetupHook
+      makeMinimal
+      rsync
+    ];
+
+    buildInputs = commonDeps;
+
+    # temporarily use gnuinstall for bootstrapping
+    # bsdinstall will be built later
+    makeFlags = defaultMakeFlags ++ [
+      "INSTALL=${coreutils}/bin/install"
+      "DATADIR=$(out)/share"
+      # Can't sort object files yet
+      "LORDER=echo"
+      "TSORT=cat"
+      # Can't process man pages yet
+      "MKSHARE=no"
+    ] ++ lib.optionals stdenv.hostPlatform.isDarwin [
+      # GNU objcopy produces broken .a libs which won't link into dependers.
+      # Makefiles only invoke `$OBJCOPY -x/-X`, so cctools strip works here.
+      "OBJCOPY=${cctools-port}/bin/strip"
+    ];
+    RENAME = "-D";
+
+    passthru.tests = { netbsd-install = install; };
+
+    patches = [
+      ./compat-cxx-safe-header.patch
+      ./compat-dont-configure-twice.patch
+      ./compat-no-force-native.patch
+    ];
+
+    preInstall = ''
+      makeFlagsArray+=('INSTALL_FILE=''${INSTALL} ''${COPY} ''${PRESERVE} ''${RENAME}')
+      makeFlagsArray+=('INSTALL_DIR=''${INSTALL} -d')
+      makeFlagsArray+=('INSTALL_SYMLINK=''${INSTALL} ''${SYMLINK} ''${RENAME}')
+    '';
+
+    postInstall = ''
+      # why aren't these installed by netbsd?
+      install -D compat_defs.h $out/include/compat_defs.h
+      install -D $BSDSRCDIR/include/cdbw.h $out/include/cdbw.h
+      install -D $BSDSRCDIR/sys/sys/cdbr.h $out/include/cdbr.h
+      install -D $BSDSRCDIR/sys/sys/featuretest.h \
+                 $out/include/sys/featuretest.h
+      install -D $BSDSRCDIR/sys/sys/md5.h $out/include/md5.h
+      install -D $BSDSRCDIR/sys/sys/rmd160.h $out/include/rmd160.h
+      install -D $BSDSRCDIR/sys/sys/sha1.h $out/include/sha1.h
+      install -D $BSDSRCDIR/sys/sys/sha2.h $out/include/sha2.h
+      install -D $BSDSRCDIR/sys/sys/queue.h $out/include/sys/queue.h
+      install -D $BSDSRCDIR/include/vis.h $out/include/vis.h
+      install -D $BSDSRCDIR/include/db.h $out/include/db.h
+      install -D $BSDSRCDIR/include/netconfig.h $out/include/netconfig.h
+      install -D $BSDSRCDIR/include/utmpx.h $out/include/utmpx.h
+      install -D $BSDSRCDIR/include/tzfile.h $out/include/tzfile.h
+      install -D $BSDSRCDIR/sys/sys/tree.h $out/include/sys/tree.h
+      install -D $BSDSRCDIR/include/nl_types.h $out/include/nl_types.h
+      install -D $BSDSRCDIR/include/stringlist.h $out/include/stringlist.h
+
+      # Collapse includes slightly to fix dangling reference
+      install -D $BSDSRCDIR/common/include/rpc/types.h $out/include/rpc/types.h
+      sed -i '1s;^;#include "nbtool_config.h"\n;' $out/include/rpc/types.h
+   '' + lib.optionalString stdenv.isDarwin ''
+      mkdir -p $out/include/ssp
+      touch $out/include/ssp/ssp.h
+   '' + ''
+      mkdir -p $out/lib/pkgconfig
+      substitute ${./libbsd-overlay.pc} $out/lib/pkgconfig/libbsd-overlay.pc \
+        --subst-var-by out $out \
+        --subst-var-by version ${version}
+    '';
+    extraPaths = [ include.src libc.src libutil.src
+      (fetchNetBSD "external/bsd/flex" "9.2" "0h98jpfj7vx5zh7vd7bk6b1hmzgkcb757a8j6d9zgygxxv13v43m")
+      (fetchNetBSD "sys/sys" "9.2" "0zawhw51klaigqqwkx0lzrx3mim2jywrc24cm7c66qsf1im9awgd")
+      (fetchNetBSD "common/include/rpc/types.h" "9.2" "0n2df12mlc3cbc48jxq35yzl1y7ghgpykvy7jnfh898rdhac7m9a")
+    ] ++ libutil.extraPaths ++ _mainLibcExtraPaths;
+  })
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/config.nix b/pkgs/os-specific/bsd/netbsd/pkgs/config.nix
new file mode 100644
index 0000000000000..277d70129e6f7
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/config.nix
@@ -0,0 +1,18 @@
+{ mkDerivation
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal, install, mandoc, byacc, flex, rsync
+, compatIfNeeded
+, cksum
+}:
+mkDerivation {
+  path = "usr.bin/config";
+  version = "9.2";
+  sha256 = "1yz3n4hncdkk6kp595fh2q5lg150vpqg8iw2dccydkyw4y3hgsjj";
+  env.NIX_CFLAGS_COMPILE = toString [ "-DMAKE_BOOTSTRAP" ];
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal install mandoc byacc flex rsync
+  ];
+  buildInputs = compatIfNeeded;
+  extraPaths = [ cksum.src ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/csu.nix b/pkgs/os-specific/bsd/netbsd/pkgs/csu.nix
new file mode 100644
index 0000000000000..2d13ced6d5ed5
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/csu.nix
@@ -0,0 +1,24 @@
+{ lib, mkDerivation
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, install, mandoc, groff, flex
+, byacc, genassym, gencat, lorder, tsort, statHook, rsync
+, headers
+, sys
+, ld_elf_so
+}:
+
+mkDerivation {
+  path = "lib/csu";
+  version = "9.2";
+  sha256 = "0al5jfazvhlzn9hvmnrbchx4d0gm282hq5gp4xs2zmj9ycmf6d03";
+  meta.platforms = lib.platforms.netbsd;
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal
+    install mandoc groff flex
+    byacc genassym gencat lorder tsort statHook rsync
+  ];
+  buildInputs = [ headers ];
+  extraPaths = [ sys.src ld_elf_so.src ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/dict.nix b/pkgs/os-specific/bsd/netbsd/pkgs/dict.nix
new file mode 100644
index 0000000000000..0d7d026dd21d2
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/dict.nix
@@ -0,0 +1,9 @@
+{ mkDerivation, defaultMakeFlags }:
+
+mkDerivation {
+  path = "share/dict";
+  noCC = true;
+  version = "9.2";
+  sha256 = "0svfc0byk59ri37pyjslv4c4rc7zw396r73mr593i78d39q5g3ad";
+  makeFlags = defaultMakeFlags ++ [ "BINDIR=$(out)/share" ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh b/pkgs/os-specific/bsd/netbsd/pkgs/fts/fts-setup-hook.sh
index b6cb5aaca05b3..b6cb5aaca05b3 100644
--- a/pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/fts/fts-setup-hook.sh
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/fts/package.nix b/pkgs/os-specific/bsd/netbsd/pkgs/fts/package.nix
new file mode 100644
index 0000000000000..0393d36357f6e
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/fts/package.nix
@@ -0,0 +1,41 @@
+{ mkDerivation
+, bsdSetupHook, netbsdSetupHook, rsync
+, compatIfNeeded
+, fetchNetBSD
+}:
+
+mkDerivation {
+  pname = "fts";
+  path = "include/fts.h";
+  sha256 = "01d4fpxvz1pgzfk5xznz5dcm0x0gdzwcsfm1h3d0xc9kc6hj2q77";
+  version = "9.2";
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook rsync
+  ];
+  propagatedBuildInputs = compatIfNeeded;
+  extraPaths = [
+    (fetchNetBSD "lib/libc/gen/fts.c" "9.2" "1a8hmf26242nmv05ipn3ircxb0jqmmi66rh78kkyi9vjwkfl3qn7")
+    (fetchNetBSD "lib/libc/include/namespace.h" "9.2" "0kksr3pdwdc1cplqf5z12ih4cml6l11lqrz91f7hjjm64y7785kc")
+    (fetchNetBSD "lib/libc/gen/fts.3" "9.2" "1asxw0n3fhjdadwkkq3xplfgqgl3q32w1lyrvbakfa3gs0wz5zc1")
+  ];
+  skipIncludesPhase = true;
+  buildPhase = ''
+    "$CC" -c -Iinclude -Ilib/libc/include lib/libc/gen/fts.c \
+        -o lib/libc/gen/fts.o
+    "$AR" -rsc libfts.a lib/libc/gen/fts.o
+  '';
+  installPhase = ''
+    runHook preInstall
+
+    install -D lib/libc/gen/fts.3 $out/share/man/man3/fts.3
+    install -D include/fts.h $out/include/fts.h
+    install -D lib/libc/include/namespace.h $out/include/namespace.h
+    install -D libfts.a $out/lib/libfts.a
+
+    runHook postInstall
+  '';
+  setupHooks = [
+    ../../../../../build-support/setup-hooks/role.bash
+    ./fts-setup-hook.sh
+  ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/genassym.nix b/pkgs/os-specific/bsd/netbsd/pkgs/genassym.nix
new file mode 100644
index 0000000000000..7f81a77a02dd2
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/genassym.nix
@@ -0,0 +1,7 @@
+{ mkDerivation }:
+
+mkDerivation {
+  path = "usr.bin/genassym";
+  version = "9.2";
+  sha256 = "1acl1dz5kvh9h5806vkz2ap95rdsz7phmynh5i3x5y7agbki030c";
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/gencat.nix b/pkgs/os-specific/bsd/netbsd/pkgs/gencat.nix
new file mode 100644
index 0000000000000..411be85e91e2f
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/gencat.nix
@@ -0,0 +1,7 @@
+{ mkDerivation }:
+
+mkDerivation {
+  path = "usr.bin/gencat";
+  version = "9.2";
+  sha256 = "0gd463x1hg36bhr7y0xryb5jyxk0z0g7xvy8rgk82nlbnlnsbbwb";
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/getconf.nix b/pkgs/os-specific/bsd/netbsd/pkgs/getconf.nix
new file mode 100644
index 0000000000000..c8483d454b877
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/getconf.nix
@@ -0,0 +1,7 @@
+{ mkDerivation }:
+
+mkDerivation {
+  path = "usr.bin/getconf";
+  sha256 = "122vslz4j3h2mfs921nr2s6m078zcj697yrb75rwp2hnw3qz4s8q";
+  version = "9.2";
+}
diff --git a/pkgs/os-specific/bsd/netbsd/getent.patch b/pkgs/os-specific/bsd/netbsd/pkgs/getent/getent.patch
index 18258b6486186..18258b6486186 100644
--- a/pkgs/os-specific/bsd/netbsd/getent.patch
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/getent/getent.patch
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/getent/package.nix b/pkgs/os-specific/bsd/netbsd/pkgs/getent/package.nix
new file mode 100644
index 0000000000000..7a9acb1e0a9e8
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/getent/package.nix
@@ -0,0 +1,8 @@
+{ mkDerivation }:
+
+mkDerivation {
+  path = "usr.bin/getent";
+  sha256 = "1qngywcmm0y7nl8h3n8brvkxq4jw63szbci3kc1q6a6ndhycbbvr";
+  version = "9.2";
+  patches = [ ./getent.patch ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/headers.nix b/pkgs/os-specific/bsd/netbsd/pkgs/headers.nix
new file mode 100644
index 0000000000000..646e5675130bb
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/headers.nix
@@ -0,0 +1,11 @@
+{ lib, symlinkJoin, include, sys-headers, libpthread-headers }:
+
+symlinkJoin {
+  name = "netbsd-headers-9.2";
+  paths = [
+    include
+    sys-headers
+    libpthread-headers
+  ];
+  meta.platforms = lib.platforms.netbsd;
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/i18n_module.nix b/pkgs/os-specific/bsd/netbsd/pkgs/i18n_module.nix
new file mode 100644
index 0000000000000..60b091ef0b718
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/i18n_module.nix
@@ -0,0 +1,9 @@
+{ lib, mkDerivation, libc }:
+
+mkDerivation {
+  path = "lib/i18n_module";
+  version = "9.2";
+  sha256 = "0w6y5v3binm7gf2kn7y9jja8k18rhnyl55cvvfnfipjqdxvxd9jd";
+  meta.platforms = lib.platforms.netbsd;
+  extraPaths = [ libc.src ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/include.nix b/pkgs/os-specific/bsd/netbsd/pkgs/include.nix
new file mode 100644
index 0000000000000..1ecdec90ae095
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/include.nix
@@ -0,0 +1,40 @@
+{ lib, mkDerivation
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, install, mandoc, groff, rsync, nbperf, rpcgen
+, common
+, defaultMakeFlags
+, stdenv
+}:
+
+mkDerivation {
+  path = "include";
+  version = "9.2";
+  sha256 = "0nxnmj4c8s3hb9n3fpcmd0zl3l1nmhivqgi9a35sis943qvpgl9h";
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal
+    install mandoc groff rsync nbperf rpcgen
+  ];
+
+  # The makefiles define INCSDIR per subdirectory, so we have to set
+  # something else on the command line so those definitions aren't
+  # overridden.
+  postPatch = ''
+    find "$BSDSRCDIR" -name Makefile -exec \
+      sed -i -E \
+        -e 's_/usr/include_''${INCSDIR0}_' \
+        {} \;
+  '';
+
+  # multiple header dirs, see above
+  postConfigure = ''
+    makeFlags=''${makeFlags/INCSDIR/INCSDIR0}
+  '';
+
+  extraPaths = [ common ];
+  headersOnly = true;
+  noCC = true;
+  meta.platforms = lib.platforms.netbsd;
+  makeFlags = defaultMakeFlags ++ [ "RPCGEN_CPP=${stdenv.cc.cc}/bin/cpp" ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/install-setup-hook.sh b/pkgs/os-specific/bsd/netbsd/pkgs/install/install-setup-hook.sh
index 4bfd4d785fac4..4bfd4d785fac4 100644
--- a/pkgs/os-specific/bsd/netbsd/install-setup-hook.sh
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/install/install-setup-hook.sh
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/install/package.nix b/pkgs/os-specific/bsd/netbsd/pkgs/install/package.nix
new file mode 100644
index 0000000000000..991517ac2d486
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/install/package.nix
@@ -0,0 +1,49 @@
+{ mkDerivation
+, writeShellScript
+, mtree, make
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, mandoc, groff, rsync
+, compatIfNeeded, fts
+
+}:
+
+# HACK: to ensure parent directories exist. This emulates GNU
+# install’s -D option. No alternative seems to exist in BSD install.
+let
+  binstall = writeShellScript "binstall" ''
+    set -eu
+    for last in "$@"; do true; done
+    mkdir -p $(dirname $last)
+    @out@/bin/xinstall "$@"
+  '';
+in
+  mkDerivation {
+    path = "usr.bin/xinstall";
+    version = "9.2";
+    sha256 = "1f6pbz3qv1qcrchdxif8p5lbmnwl8b9nq615hsd3cyl4avd5bfqj";
+    extraPaths = [ mtree.src make.src ];
+    nativeBuildInputs = [
+      bsdSetupHook netbsdSetupHook
+      makeMinimal
+      mandoc groff rsync
+    ];
+    skipIncludesPhase = true;
+    buildInputs = compatIfNeeded
+      # fts header is needed. glibc already has this header, but musl doesn't,
+      # so make sure pkgsMusl.netbsd.install still builds in case you want to
+      # remove it!
+      ++ [ fts ];
+    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
+    '';
+    setupHook = ./install-setup-hook.sh;
+  }
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/ld_elf_so.nix b/pkgs/os-specific/bsd/netbsd/pkgs/ld_elf_so.nix
new file mode 100644
index 0000000000000..1496ad6a0e884
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/ld_elf_so.nix
@@ -0,0 +1,18 @@
+{ lib
+, mkDerivation
+, libc
+, defaultMakeFlags
+}:
+
+mkDerivation {
+  path  = "libexec/ld.elf_so";
+  version = "9.2";
+  sha256 = "0ia9mqzdljly0vqfwflm5mzz55k7qsr4rw2bzhivky6k30vgirqa";
+  meta.platforms = lib.platforms.netbsd;
+  LIBC_PIC = "${libc}/lib/libc_pic.a";
+  # Hack to prevent a symlink being installed here for compatibility.
+  SHLINKINSTALLDIR = "/usr/libexec";
+  USE_FORT = "yes";
+  makeFlags = defaultMakeFlags ++ [ "BINDIR=$(out)/libexec" "CLIBOBJ=${libc}/lib" ];
+  extraPaths = [ libc.src ] ++ libc.extraPaths;
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libarch.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libarch.nix
new file mode 100644
index 0000000000000..93ea02f8a17c1
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libarch.nix
@@ -0,0 +1,8 @@
+{ lib, mkDerivation }:
+
+mkDerivation {
+  path = "lib/libarch";
+  version = "9.2";
+  sha256 = "6ssenRhuSwp0Jn71ErT0PrEoCJ+cIYRztwdL4QTDZsQ=";
+  meta.platforms = lib.platforms.netbsd;
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libc.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libc.nix
new file mode 100644
index 0000000000000..ebc01a11668a6
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libc.nix
@@ -0,0 +1,76 @@
+{ lib
+, mkDerivation
+, defaultMakeFlags
+, _mainLibcExtraPaths
+, fetchNetBSD
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, install, mandoc, groff, flex
+, byacc, genassym, gencat, lorder, tsort, statHook, rsync, rpcgen
+, csu, headers
+, librt
+}:
+
+mkDerivation {
+  path = "lib/libc";
+  version = "9.2";
+  sha256 = "1y9c13igg0kai07sqvf9cm6yqmd8lhfd8hq3q7biilbgs1l99as3";
+  USE_FORT = "yes";
+  MKPROFILE = "no";
+  extraPaths = _mainLibcExtraPaths ++ [
+    (fetchNetBSD "external/bsd/jemalloc" "9.2" "0cq704swa0h2yxv4gc79z2lwxibk9k7pxh3q5qfs7axx3jx3n8kb")
+  ];
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal
+    install mandoc groff flex
+    byacc genassym gencat lorder tsort statHook rsync rpcgen
+  ];
+  buildInputs = [ headers csu ];
+  env.NIX_CFLAGS_COMPILE = "-B${csu}/lib -fcommon";
+  meta.platforms = lib.platforms.netbsd;
+  SHLIBINSTALLDIR = "$(out)/lib";
+  MKPICINSTALL = "yes";
+  NLSDIR = "$(out)/share/nls";
+  makeFlags = defaultMakeFlags ++ [ "FILESDIR=$(out)/var/db"];
+  postInstall = ''
+    pushd ${headers}
+    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
+
+    NIX_CFLAGS_COMPILE+=" -B$out/lib"
+    NIX_CFLAGS_COMPILE+=" -I$out/include"
+    NIX_LDFLAGS+=" -L$out/lib"
+
+    make -C $BSDSRCDIR/lib/libpthread $makeFlags
+    make -C $BSDSRCDIR/lib/libpthread $makeFlags install
+
+    make -C $BSDSRCDIR/lib/libm $makeFlags
+    make -C $BSDSRCDIR/lib/libm $makeFlags install
+
+    make -C $BSDSRCDIR/lib/libresolv $makeFlags
+    make -C $BSDSRCDIR/lib/libresolv $makeFlags install
+
+    make -C $BSDSRCDIR/lib/librpcsvc $makeFlags
+    make -C $BSDSRCDIR/lib/librpcsvc $makeFlags install
+
+    make -C $BSDSRCDIR/lib/i18n_module $makeFlags
+    make -C $BSDSRCDIR/lib/i18n_module $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
+  '';
+  inherit (librt) postPatch;
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libcrypt.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libcrypt.nix
new file mode 100644
index 0000000000000..c5f9deff589c4
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libcrypt.nix
@@ -0,0 +1,9 @@
+{ lib, mkDerivation }:
+
+mkDerivation {
+  path = "lib/libcrypt";
+  version = "9.2";
+  sha256 = "0siqan1wdqmmhchh2n8w6a8x1abbff8n4yb6jrqxap3hqn8ay54g";
+  SHLIBINSTALLDIR = "$(out)/lib";
+  meta.platforms = lib.platforms.netbsd;
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libcurses.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libcurses.nix
new file mode 100644
index 0000000000000..2409879640a90
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libcurses.nix
@@ -0,0 +1,27 @@
+{ lib, mkDerivation, stdenv
+, libterminfo
+, compatIfNeeded
+, defaultMakeFlags
+}:
+
+mkDerivation {
+  path = "lib/libcurses";
+  version = "9.2";
+  sha256 = "0pd0dggl3w4bv5i5h0s1wrc8hr66n4hkv3zlklarwfdhc692fqal";
+  buildInputs = [ libterminfo ];
+  env.NIX_CFLAGS_COMPILE = toString ([
+    "-D__scanflike(a,b)="
+    "-D__va_list=va_list"
+    "-D__warn_references(a,b)="
+  ] ++ lib.optional stdenv.isDarwin "-D__strong_alias(a,b)=");
+  propagatedBuildInputs = compatIfNeeded;
+  MKDOC = "no"; # missing vfontedpr
+  makeFlags = defaultMakeFlags ++ [ "LIBDO.terminfo=${libterminfo}/lib" ];
+  postPatch = lib.optionalString (!stdenv.isDarwin) ''
+    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 $COMPONENT_PATH/scanw.c \
+      --replace "__strong_alias(vwscanw, vw_scanw)" 'extern int vwscanw(WINDOW*, const char*, va_list) __attribute__ ((alias ("vw_scanw")));'
+  '';
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libedit.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libedit.nix
new file mode 100644
index 0000000000000..eb734f34c3d49
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libedit.nix
@@ -0,0 +1,26 @@
+{ lib, mkDerivation
+, libterminfo, libcurses
+, compatIfNeeded
+, defaultMakeFlags
+}:
+
+mkDerivation {
+    path = "lib/libedit";
+    version = "9.2";
+    sha256 = "1wqhngraxwqk4jgrf5f18jy195yrp7c06n1gf31pbplq79mg1bcj";
+    buildInputs = [ libterminfo libcurses ];
+    propagatedBuildInputs = compatIfNeeded;
+    SHLIBINSTALLDIR = "$(out)/lib";
+    makeFlags = defaultMakeFlags ++ [ "LIBDO.terminfo=${libterminfo}/lib" ];
+    postPatch = ''
+      sed -i '1i #undef bool_t' $COMPONENT_PATH/el.h
+      substituteInPlace $COMPONENT_PATH/config.h \
+        --replace "#define HAVE_STRUCT_DIRENT_D_NAMLEN 1" ""
+      substituteInPlace $COMPONENT_PATH/readline/Makefile --replace /usr/include "$out/include"
+    '';
+    env.NIX_CFLAGS_COMPILE = toString [
+      "-D__noinline="
+      "-D__scanflike(a,b)="
+      "-D__va_list=va_list"
+    ];
+  }
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libm.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libm.nix
new file mode 100644
index 0000000000000..86990088adf28
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libm.nix
@@ -0,0 +1,10 @@
+{ lib, mkDerivation, sys }:
+
+mkDerivation {
+  path = "lib/libm";
+  version = "9.2";
+  sha256 = "1apwfr26shdmbqqnmg7hxf7bkfxw44ynqnnnghrww9bnhqdnsy92";
+  SHLIBINSTALLDIR = "$(out)/lib";
+  meta.platforms = lib.platforms.netbsd;
+  extraPaths = [ sys.src ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libossaudio.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libossaudio.nix
new file mode 100644
index 0000000000000..51bbc216e2046
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libossaudio.nix
@@ -0,0 +1,8 @@
+{ lib, mkDerivation }:
+
+mkDerivation {
+  path = "lib/libossaudio";
+  version = "9.2";
+  sha256 = "16l3bfy6dcwqnklvh3x0ps8ld1y504vf57v9rx8f9adzhb797jh0";
+  meta.platforms = lib.platforms.netbsd;
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libpci.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libpci.nix
new file mode 100644
index 0000000000000..21ca0f62fd4e4
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libpci.nix
@@ -0,0 +1,11 @@
+{ lib, mkDerivation, sys }:
+
+mkDerivation {
+  pname = "libpci";
+  path = "lib/libpci";
+  version = "9.2";
+  sha256 = "+IOEO1Bw3/H3iCp3uk3bwsFZbvCqN5Ciz70irnPl8E8=";
+  env.NIX_CFLAGS_COMPILE = toString [ "-I." ];
+  meta.platforms = lib.platforms.netbsd;
+  extraPaths = [ sys.src ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libpthread/base.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libpthread/base.nix
new file mode 100644
index 0000000000000..485a12837bcb4
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libpthread/base.nix
@@ -0,0 +1,6 @@
+{
+  path = "lib/libpthread";
+  version = "9.2";
+  sha256 = "0mlmc31k509dwfmx5s2x010wxjc44mr6y0cbmk30cfipqh8c962h";
+}
+
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libpthread/headers.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libpthread/headers.nix
new file mode 100644
index 0000000000000..3896562501fc5
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libpthread/headers.nix
@@ -0,0 +1,9 @@
+{ lib, mkDerivation }:
+
+mkDerivation (import ./base.nix // {
+  pname = "libpthread-headers";
+  installPhase = "includesPhase";
+  dontBuild = true;
+  noCC = true;
+  meta.platforms = lib.platforms.netbsd;
+})
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libpthread/package.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libpthread/package.nix
new file mode 100644
index 0000000000000..c2a0d407718e9
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libpthread/package.nix
@@ -0,0 +1,15 @@
+{ lib, mkDerivation
+, headers
+, common, libc, librt, sys
+}:
+
+mkDerivation (import ./base.nix // {
+  pname = "libpthread";
+  installPhase = null;
+  noCC = false;
+  dontBuild = false;
+  buildInputs = [ headers ];
+  SHLIBINSTALLDIR = "$(out)/lib";
+  extraPaths = [ common libc.src librt.src sys.src ];
+  meta.platforms = lib.platforms.netbsd;
+})
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libresolv.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libresolv.nix
new file mode 100644
index 0000000000000..2427592e4aa9a
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libresolv.nix
@@ -0,0 +1,9 @@
+{ lib, mkDerivation, libc }:
+
+mkDerivation {
+  path = "lib/libresolv";
+  version = "9.2";
+  sha256 = "1am74s74mf1ynwz3p4ncjkg63f78a1zjm983q166x4sgzps15626";
+  meta.platforms = lib.platforms.netbsd;
+  extraPaths = [ libc.src ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/librpcsvc.nix b/pkgs/os-specific/bsd/netbsd/pkgs/librpcsvc.nix
new file mode 100644
index 0000000000000..87524339e268f
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/librpcsvc.nix
@@ -0,0 +1,21 @@
+{ lib
+, mkDerivation
+, defaultMakeFlags
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, install, tsort, lorder, rpcgen, statHook
+}:
+
+mkDerivation {
+  path = "lib/librpcsvc";
+  version = "9.2";
+  sha256 = "1q34pfiyjbrgrdqm46jwrsqms49ly6z3b0xh1wg331zga900vq5n";
+  makeFlags = defaultMakeFlags ++ [ "INCSDIR=$(out)/include/rpcsvc" ];
+  meta.platforms = lib.platforms.netbsd;
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal
+    install tsort lorder rpcgen statHook
+  ];
+}
+
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/librt.nix b/pkgs/os-specific/bsd/netbsd/pkgs/librt.nix
new file mode 100644
index 0000000000000..2ffe0787004a5
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/librt.nix
@@ -0,0 +1,13 @@
+{ lib, mkDerivation, libc, headers }:
+
+mkDerivation {
+  path = "lib/librt";
+  version = "9.2";
+  sha256 = "07f8mpjcqh5kig5z5sp97fg55mc4dz6aa1x5g01nv2pvbmqczxc6";
+  meta.platforms = lib.platforms.netbsd;
+  extraPaths = [ libc.src ] ++ libc.extraPaths;
+  postPatch = ''
+    sed -i 's,/usr\(/include/sys/syscall.h\),${headers}\1,g' \
+      $BSDSRCDIR/lib/{libc,librt}/sys/Makefile.inc
+  '';
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libterminfo.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libterminfo.nix
new file mode 100644
index 0000000000000..b9268cc7ba333
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libterminfo.nix
@@ -0,0 +1,32 @@
+{ mkDerivation
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal, install, tsort, lorder, mandoc, statHook, nbperf, tic, rsync
+, compatIfNeeded
+, fetchNetBSD
+}:
+
+mkDerivation {
+  path = "lib/libterminfo";
+  version = "9.2";
+  sha256 = "0pq05k3dj0dfsczv07frnnji92mazmy2qqngqbx2zgqc1x251414";
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal install tsort lorder mandoc statHook nbperf tic rsync
+  ];
+  buildInputs = compatIfNeeded;
+  SHLIBINSTALLDIR = "$(out)/lib";
+  postPatch = ''
+    substituteInPlace $COMPONENT_PATH/term.c --replace /usr/share $out/share
+    substituteInPlace $COMPONENT_PATH/setupterm.c \
+      --replace '#include <curses.h>' 'void use_env(bool);'
+  '';
+  postBuild = ''
+    make -C $BSDSRCDIR/share/terminfo $makeFlags BINDIR=$out/share
+  '';
+  postInstall = ''
+    make -C $BSDSRCDIR/share/terminfo $makeFlags BINDIR=$out/share install
+  '';
+  extraPaths = [
+    (fetchNetBSD "share/terminfo" "9.2" "1vh9rl4w8118a9qdpblfxmv1wkpm83rm9gb4rzz5bpm56i6d7kk7")
+  ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/libutil.nix b/pkgs/os-specific/bsd/netbsd/pkgs/libutil.nix
new file mode 100644
index 0000000000000..4aaf8f0e7ab63
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/libutil.nix
@@ -0,0 +1,21 @@
+{ mkDerivation
+, common, libc, sys
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, byacc, install, tsort, lorder, mandoc, statHook, rsync
+, headers
+}:
+
+mkDerivation {
+  path = "lib/libutil";
+  version = "9.2";
+  sha256 = "02gm5a5zhh8qp5r5q5r7x8x6x50ir1i0ncgsnfwh1vnrz6mxbq7z";
+  extraPaths = [ common libc.src sys.src ];
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal
+    byacc install tsort lorder mandoc statHook rsync
+  ];
+  buildInputs = [ headers ];
+  SHLIBINSTALLDIR = "$(out)/lib";
+}
diff --git a/pkgs/os-specific/bsd/netbsd/locale.patch b/pkgs/os-specific/bsd/netbsd/pkgs/locale/locale.patch
index 4b7f478552879..4b7f478552879 100644
--- a/pkgs/os-specific/bsd/netbsd/locale.patch
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/locale/locale.patch
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/locale/package.nix b/pkgs/os-specific/bsd/netbsd/pkgs/locale/package.nix
new file mode 100644
index 0000000000000..3c61e8517b35b
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/locale/package.nix
@@ -0,0 +1,9 @@
+{ mkDerivation }:
+
+mkDerivation {
+  path = "usr.bin/locale";
+  version = "9.2";
+  sha256 = "0kk6v9k2bygq0wf9gbinliqzqpzs9bgxn0ndyl2wcv3hh2bmsr9p";
+  patches = [ ./locale.patch ];
+  env.NIX_CFLAGS_COMPILE = "-DYESSTR=__YESSTR -DNOSTR=__NOSTR";
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/lorder.nix b/pkgs/os-specific/bsd/netbsd/pkgs/lorder.nix
new file mode 100644
index 0000000000000..d3109601382a0
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/lorder.nix
@@ -0,0 +1,16 @@
+{ mkDerivation
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, install, mandoc, groff, rsync
+}:
+
+mkDerivation {
+  path = "usr.bin/lorder";
+  version = "9.2";
+  sha256 = "0rjf9blihhm0n699vr2bg88m4yjhkbxh6fxliaay3wxkgnydjwn2";
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal
+    install mandoc groff rsync
+  ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/make.nix b/pkgs/os-specific/bsd/netbsd/pkgs/make.nix
new file mode 100644
index 0000000000000..dcd80ef004678
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/make.nix
@@ -0,0 +1,60 @@
+{ lib, mkDerivation, fetchNetBSD, stdenv }:
+
+mkDerivation {
+  path = "usr.bin/make";
+  sha256 = "0vi73yicbmbp522qzqvd979cx6zm5jakhy77xh73c1kygf8klccs";
+  version = "9.2";
+
+ postPatch = ''
+   substituteInPlace $BSDSRCDIR/share/mk/bsd.doc.mk \
+     --replace '-o ''${DOCOWN}' "" \
+     --replace '-g ''${DOCGRP}' ""
+   for mk in $BSDSRCDIR/share/mk/bsd.inc.mk $BSDSRCDIR/share/mk/bsd.kinc.mk; do
+     substituteInPlace $mk \
+       --replace '-o ''${BINOWN}' "" \
+       --replace '-g ''${BINGRP}' ""
+   done
+   substituteInPlace $BSDSRCDIR/share/mk/bsd.kmodule.mk \
+     --replace '-o ''${KMODULEOWN}' "" \
+     --replace '-g ''${KMODULEGRP}' ""
+   substituteInPlace $BSDSRCDIR/share/mk/bsd.lib.mk \
+     --replace '-o ''${LIBOWN}' "" \
+     --replace '-g ''${LIBGRP}' "" \
+     --replace '-o ''${DEBUGOWN}' "" \
+     --replace '-g ''${DEBUGGRP}' ""
+   substituteInPlace $BSDSRCDIR/share/mk/bsd.lua.mk \
+     --replace '-o ''${LIBOWN}' "" \
+     --replace '-g ''${LIBGRP}' ""
+   substituteInPlace $BSDSRCDIR/share/mk/bsd.man.mk \
+     --replace '-o ''${MANOWN}' "" \
+     --replace '-g ''${MANGRP}' ""
+   substituteInPlace $BSDSRCDIR/share/mk/bsd.nls.mk \
+     --replace '-o ''${NLSOWN}' "" \
+     --replace '-g ''${NLSGRP}' ""
+   substituteInPlace $BSDSRCDIR/share/mk/bsd.prog.mk \
+     --replace '-o ''${BINOWN}' "" \
+     --replace '-g ''${BINGRP}' "" \
+     --replace '-o ''${RUMPBINOWN}' "" \
+     --replace '-g ''${RUMPBINGRP}' "" \
+     --replace '-o ''${DEBUGOWN}' "" \
+     --replace '-g ''${DEBUGGRP}' ""
+
+    # make needs this to pick up our sys make files
+    export NIX_CFLAGS_COMPILE+=" -D_PATH_DEFSYSPATH=\"$out/share/mk\""
+
+    substituteInPlace $BSDSRCDIR/share/mk/bsd.lib.mk \
+      --replace '_INSTRANLIB=''${empty(PRESERVE):?-a "''${RANLIB} -t":}' '_INSTRANLIB='
+    substituteInPlace $BSDSRCDIR/share/mk/bsd.kinc.mk \
+      --replace /bin/rm rm
+  '' + lib.optionalString stdenv.isDarwin ''
+    substituteInPlace $BSDSRCDIR/share/mk/bsd.sys.mk \
+      --replace '-Wl,--fatal-warnings' "" \
+      --replace '-Wl,--warn-shared-textrel' ""
+  '';
+  postInstall = ''
+    make -C $BSDSRCDIR/share/mk FILESDIR=$out/share/mk install
+  '';
+  extraPaths = [
+    (fetchNetBSD "share/mk" "9.2" "0w9x77cfnm6zwy40slradzi0ip9gz80x6lk7pvnlxzsr2m5ra5sy")
+  ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/makeMinimal.nix b/pkgs/os-specific/bsd/netbsd/pkgs/makeMinimal.nix
new file mode 100644
index 0000000000000..18655b3bf863e
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/makeMinimal.nix
@@ -0,0 +1,43 @@
+{ mkDerivation
+, bsdSetupHook, netbsdSetupHook, rsync
+, make
+}:
+
+mkDerivation {
+  path = "tools/make";
+  sha256 = "0fh0nrnk18m613m5blrliq2aydciv51qhc0ihsj4k63incwbk90n";
+  version = "9.2";
+
+  buildInputs = [];
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook rsync
+  ];
+
+  skipIncludesPhase = true;
+
+  postPatch = ''
+    patchShebangs $COMPONENT_PATH/configure
+    ${make.postPatch}
+  '';
+
+  buildPhase = ''
+    runHook preBuild
+
+    sh ./buildmake.sh
+
+    runHook postBuild
+  '';
+
+  installPhase = ''
+    runHook preInstall
+
+    install -D nbmake $out/bin/nbmake
+    ln -s $out/bin/nbmake $out/bin/make
+    mkdir -p $out/share
+    cp -r $BSDSRCDIR/share/mk $out/share/mk
+
+    runHook postInstall
+  '';
+
+  extraPaths = [ make.src ] ++ make.extraPaths;
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/man.nix b/pkgs/os-specific/bsd/netbsd/pkgs/man.nix
new file mode 100644
index 0000000000000..bce5bcee66946
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/man.nix
@@ -0,0 +1,17 @@
+{ mkDerivation, defaultMakeFlags }:
+
+mkDerivation {
+  path = "share/man";
+  noCC = true;
+  version = "9.2";
+  sha256 = "1l4lmj4kmg8dl86x94sr45w0xdnkz8dn4zjx0ipgr9bnq98663zl";
+  # man0 generates a man.pdf using ps2pdf, but doesn't install it later,
+  # so we can avoid the dependency on ghostscript
+  postPatch = ''
+    substituteInPlace $COMPONENT_PATH/man0/Makefile --replace "ps2pdf" "echo noop "
+  '';
+  makeFlags = defaultMakeFlags ++ [
+    "FILESDIR=$(out)/share"
+    "MKRUMP=no" # would require to have additional path sys/rump/share/man
+  ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/misc.nix b/pkgs/os-specific/bsd/netbsd/pkgs/misc.nix
new file mode 100644
index 0000000000000..7f96f4d1495ad
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/misc.nix
@@ -0,0 +1,9 @@
+{ mkDerivation, defaultMakeFlags }:
+
+mkDerivation {
+  path = "share/misc";
+  noCC = true;
+  version = "9.2";
+  sha256 = "1j2cdssdx6nncv8ffj7f7ybl7m9hadjj8vm8611skqdvxnjg6nbc";
+  makeFlags = defaultMakeFlags ++ [ "BINDIR=$(out)/share" ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/mkDerivation.nix b/pkgs/os-specific/bsd/netbsd/pkgs/mkDerivation.nix
new file mode 100644
index 0000000000000..82e8889f6cf4d
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/mkDerivation.nix
@@ -0,0 +1,82 @@
+{ lib
+, stdenvNoCC, stdenv
+, fetchNetBSD
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, install, tsort, lorder
+, mandoc, groff, statHook, rsync
+, compatIfNeeded
+, defaultMakeFlags
+}:
+
+lib.makeOverridable (attrs: let
+  stdenv' = if attrs.noCC or false then stdenvNoCC else stdenv;
+in stdenv'.mkDerivation ({
+  pname = "${attrs.pname or (baseNameOf attrs.path)}-netbsd";
+  inherit (attrs) version;
+  src = fetchNetBSD attrs.path attrs.version attrs.sha256;
+
+  extraPaths = [ ];
+
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal
+    install tsort lorder mandoc groff statHook rsync
+  ];
+  buildInputs = compatIfNeeded;
+
+  HOST_SH = stdenv'.shell;
+
+  MACHINE_ARCH = {
+    i486 = "i386";
+    i586 = "i386";
+    i686 = "i386";
+  }.${stdenv'.hostPlatform.parsed.cpu.name}
+    or stdenv'.hostPlatform.parsed.cpu.name;
+
+  MACHINE = {
+    x86_64 = "amd64";
+    aarch64 = "evbarm64";
+    i486 = "i386";
+    i586 = "i386";
+    i686 = "i386";
+  }.${stdenv'.hostPlatform.parsed.cpu.name}
+    or stdenv'.hostPlatform.parsed.cpu.name;
+
+  COMPONENT_PATH = attrs.path;
+
+  makeFlags = defaultMakeFlags;
+
+  strictDeps = true;
+
+  meta = with lib; {
+    maintainers = with maintainers; [ matthewbauer qyliss ];
+    platforms = platforms.unix;
+    license = licenses.bsd2;
+  };
+
+} // lib.optionalAttrs stdenv'.hasCC {
+  # TODO should CC wrapper set this?
+  CPP = "${stdenv'.cc.targetPrefix}cpp";
+} // lib.optionalAttrs stdenv'.isDarwin {
+  MKRELRO = "no";
+} // lib.optionalAttrs (stdenv'.cc.isClang or false) {
+  HAVE_LLVM = lib.versions.major (lib.getVersion stdenv'.cc.cc);
+} // lib.optionalAttrs (stdenv'.cc.isGNU or false) {
+  HAVE_GCC = lib.versions.major (lib.getVersion stdenv'.cc.cc);
+} // lib.optionalAttrs (stdenv'.isx86_32) {
+  USE_SSP = "no";
+} // lib.optionalAttrs (attrs.headersOnly or false) {
+  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) ''
+    set +e
+    grep -Zlr "^__RCSID
+    ^__BEGIN_DECLS" $COMPONENT_PATH | xargs -0r grep -FLZ nbtool_config.h |
+        xargs -0tr sed -i '0,/^#/s//#include <nbtool_config.h>\n\0/'
+    set -e
+  '' + attrs.postPatch or "";
+}))
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/mknod.nix b/pkgs/os-specific/bsd/netbsd/pkgs/mknod.nix
new file mode 100644
index 0000000000000..5c4c172e40a7d
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/mknod.nix
@@ -0,0 +1,7 @@
+{ mkDerivation }:
+
+mkDerivation {
+  path = "sbin/mknod";
+  version = "9.2";
+  sha256 = "1d9369shzwgixz3nph991i8q5vk7hr04py3n9avbfbhzy4gndqs2";
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/mtree.nix b/pkgs/os-specific/bsd/netbsd/pkgs/mtree.nix
new file mode 100644
index 0000000000000..723da3ad891bc
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/mtree.nix
@@ -0,0 +1,8 @@
+{ mkDerivation, mknod }:
+
+mkDerivation {
+  path = "usr.sbin/mtree";
+  version = "9.2";
+  sha256 = "04p7w540vz9npvyb8g8hcf2xa05phn1y88hsyrcz3vwanvpc0yv9";
+  extraPaths = [ mknod.src ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/nbperf.nix b/pkgs/os-specific/bsd/netbsd/pkgs/nbperf.nix
new file mode 100644
index 0000000000000..02ce7cf6ce5eb
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/nbperf.nix
@@ -0,0 +1,8 @@
+{ mkDerivation }:
+
+mkDerivation {
+  path = "usr.bin/nbperf";
+  version = "9.2";
+  sha256 = "1nxc302vgmjhm3yqdivqyfzslrg0vjpbss44s74rcryrl19mma9r";
+}
+
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/netbsdSetupHook/package.nix b/pkgs/os-specific/bsd/netbsd/pkgs/netbsdSetupHook/package.nix
new file mode 100644
index 0000000000000..e80571f2bf9a2
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/netbsdSetupHook/package.nix
@@ -0,0 +1,5 @@
+{ makeSetupHook }:
+
+makeSetupHook {
+    name = "netbsd-setup-hook";
+  } ./setup-hook.sh
diff --git a/pkgs/os-specific/bsd/netbsd/setup-hook.sh b/pkgs/os-specific/bsd/netbsd/pkgs/netbsdSetupHook/setup-hook.sh
index fa8b19e7d8ce4..fa8b19e7d8ce4 100644
--- a/pkgs/os-specific/bsd/netbsd/setup-hook.sh
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/netbsdSetupHook/setup-hook.sh
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/rpcgen.nix b/pkgs/os-specific/bsd/netbsd/pkgs/rpcgen.nix
new file mode 100644
index 0000000000000..b1482d4dff112
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/rpcgen.nix
@@ -0,0 +1,7 @@
+{ mkDerivation }:
+
+mkDerivation {
+  path = "usr.bin/rpcgen";
+  version = "9.2";
+  sha256 = "1kfgfx54jg98wbg0d95p0rvf4w0302v8fz724b0bdackdsrd4988";
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/stat/hook.nix b/pkgs/os-specific/bsd/netbsd/pkgs/stat/hook.nix
new file mode 100644
index 0000000000000..78186f55cd455
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/stat/hook.nix
@@ -0,0 +1,14 @@
+{ makeSetupHook, writeText, stat }:
+
+# stat isn't in POSIX, and NetBSD stat supports a completely
+# different range of flags than GNU stat, so including it in PATH
+# breaks stdenv.  Work around that with a hook that will point
+# NetBSD's build system and NetBSD stat without including it in
+# PATH.
+
+makeSetupHook {
+  name = "netbsd-stat-hook";
+} (writeText "netbsd-stat-hook-impl" ''
+  makeFlagsArray+=(TOOL_STAT=${stat}/bin/stat)
+'')
+
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/stat/package.nix b/pkgs/os-specific/bsd/netbsd/pkgs/stat/package.nix
new file mode 100644
index 0000000000000..fa4d5cb3e21f6
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/stat/package.nix
@@ -0,0 +1,19 @@
+{ mkDerivation
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, install, mandoc, groff, rsync
+}:
+
+# Don't add this to nativeBuildInputs directly.
+# Use statHook instead. See note in stat/hook.nix
+
+mkDerivation {
+  path = "usr.bin/stat";
+  version = "9.2";
+  sha256 = "18nqwlndfc34qbbgqx5nffil37jfq9aw663ippasfxd2hlyc106x";
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal
+    install mandoc groff rsync
+  ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/sys/base.nix b/pkgs/os-specific/bsd/netbsd/pkgs/sys/base.nix
new file mode 100644
index 0000000000000..ba458ef5c712f
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/sys/base.nix
@@ -0,0 +1,72 @@
+{ lib, mkDerivation
+, include
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal, install, tsort, lorder, statHook, rsync, uudecode, config, genassym
+, defaultMakeFlags
+, common
+}:
+{
+  path = "sys";
+  version = "9.2";
+  sha256 = "03s18q8d9giipf05bx199fajc2qwikji0djz7hw63d2lya6bfnpj";
+
+  # Make the build ignore linker warnings
+  prePatch = ''
+    substituteInPlace sys/conf/Makefile.kern.inc \
+      --replace "-Wa,--fatal-warnings" ""
+  '';
+
+  patches = [
+    # Fix this error when building bootia32.efi and bootx64.efi:
+    # error: PHDR segment not covered by LOAD segment
+    ./no-dynamic-linker.patch
+
+    # multiple header dirs, see above
+    ./sys-headers-incsdir.patch
+  ];
+
+  postPatch =
+    ''
+      substituteInPlace sys/arch/i386/stand/efiboot/Makefile.efiboot \
+        --replace "-nocombreloc" "-z nocombreloc"
+    '' +
+    # multiple header dirs, see above
+    include.postPatch;
+
+  CONFIG = "GENERIC";
+
+  propagatedBuildInputs = [ include ];
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal install tsort lorder statHook rsync uudecode config genassym
+  ];
+
+  postConfigure = ''
+    pushd arch/$MACHINE/conf
+    config $CONFIG
+    popd
+  ''
+    # multiple header dirs, see above
+    + include.postConfigure;
+
+  makeFlags = defaultMakeFlags ++ [ "FIRMWAREDIR=$(out)/libdata/firmware" ];
+  hardeningDisable = [ "pic" ];
+  MKKMOD = "no";
+  env.NIX_CFLAGS_COMPILE = toString [
+    "-Wno-error=array-parameter"
+    "-Wno-error=array-bounds"
+    "-Wa,--no-warn"
+  ];
+
+  postBuild = ''
+    make -C arch/$MACHINE/compile/$CONFIG $makeFlags
+  '';
+
+  postInstall = ''
+    cp arch/$MACHINE/compile/$CONFIG/netbsd $out
+  '';
+
+  meta.platforms = lib.platforms.netbsd;
+  extraPaths = [ common ];
+
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/sys/headers.nix b/pkgs/os-specific/bsd/netbsd/pkgs/sys/headers.nix
new file mode 100644
index 0000000000000..a3f20d772a3e7
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/sys/headers.nix
@@ -0,0 +1,21 @@
+{ lib, mkDerivation
+, include
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal, install, tsort, lorder, statHook, rsync, uudecode, config, genassym
+, defaultMakeFlags
+, common
+}:
+let
+  base = import ./base.nix {
+    inherit
+      lib mkDerivation include bsdSetupHook netbsdSetupHook makeMinimal install
+      tsort lorder statHook rsync uudecode config genassym defaultMakeFlags
+      common;
+  };
+in
+  mkDerivation (base // {
+    pname = "sys-headers";
+    installPhase = "includesPhase";
+    dontBuild = true;
+    noCC = true;
+  })
diff --git a/pkgs/os-specific/bsd/netbsd/no-dynamic-linker.patch b/pkgs/os-specific/bsd/netbsd/pkgs/sys/no-dynamic-linker.patch
index b3e9f3c88a13c..b3e9f3c88a13c 100644
--- a/pkgs/os-specific/bsd/netbsd/no-dynamic-linker.patch
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/sys/no-dynamic-linker.patch
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/sys/package.nix b/pkgs/os-specific/bsd/netbsd/pkgs/sys/package.nix
new file mode 100644
index 0000000000000..87031a50346ea
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/sys/package.nix
@@ -0,0 +1,21 @@
+{ lib, mkDerivation
+, include
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal, install, tsort, lorder, statHook, rsync, uudecode, config, genassym
+, defaultMakeFlags
+, common
+}:
+let
+  base = import ./base.nix {
+    inherit
+      lib mkDerivation include bsdSetupHook netbsdSetupHook makeMinimal install
+      tsort lorder statHook rsync uudecode config genassym defaultMakeFlags
+      common;
+  };
+in
+  mkDerivation (base // {
+    pname = "sys";
+    installPhase = null;
+    noCC = false;
+    dontBuild = false;
+  })
diff --git a/pkgs/os-specific/bsd/netbsd/sys-headers-incsdir.patch b/pkgs/os-specific/bsd/netbsd/pkgs/sys/sys-headers-incsdir.patch
index 5cfb2a54c8db2..5cfb2a54c8db2 100644
--- a/pkgs/os-specific/bsd/netbsd/sys-headers-incsdir.patch
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/sys/sys-headers-incsdir.patch
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/tic.nix b/pkgs/os-specific/bsd/netbsd/pkgs/tic.nix
new file mode 100644
index 0000000000000..2a7e3644b6be9
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/tic.nix
@@ -0,0 +1,28 @@
+{ mkDerivation
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, install, mandoc, groff, nbperf, rsync
+, compatIfNeeded
+, defaultMakeFlags
+, libterminfo
+, fetchNetBSD
+}:
+
+mkDerivation {
+  path = "tools/tic";
+  version = "9.2";
+  sha256 = "092y7db7k4kh2jq8qc55126r5qqvlb8lq8mhmy5ipbi36hwb4zrz";
+  HOSTPROG = "tic";
+  buildInputs = compatIfNeeded;
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal
+    install mandoc groff nbperf rsync
+  ];
+  makeFlags = defaultMakeFlags ++ [ "TOOLDIR=$(out)" ];
+  extraPaths = [
+    libterminfo.src
+    (fetchNetBSD "usr.bin/tic" "9.2" "1mwdfg7yx1g43ss378qsgl5rqhsxskqvsd2mqvrn38qw54i8v5i1")
+    (fetchNetBSD "tools/Makefile.host" "9.2" "15b4ab0n36lqj00j5lz2xs83g7l8isk3wx1wcapbrn66qmzz2sxy")
+  ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/tsort.nix b/pkgs/os-specific/bsd/netbsd/pkgs/tsort.nix
new file mode 100644
index 0000000000000..334eccc64c551
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/tsort.nix
@@ -0,0 +1,16 @@
+{ mkDerivation
+, bsdSetupHook, netbsdSetupHook
+, makeMinimal
+, install, mandoc, groff, rsync
+}:
+
+mkDerivation {
+  path = "usr.bin/tsort";
+  version = "9.2";
+  sha256 = "1dqvf9gin29nnq3c4byxc7lfd062pg7m84843zdy6n0z63hnnwiq";
+  nativeBuildInputs = [
+    bsdSetupHook netbsdSetupHook
+    makeMinimal
+    install mandoc groff rsync
+  ];
+}
diff --git a/pkgs/os-specific/bsd/netbsd/pkgs/uudecode.nix b/pkgs/os-specific/bsd/netbsd/pkgs/uudecode.nix
new file mode 100644
index 0000000000000..dac9674f9d6f3
--- /dev/null
+++ b/pkgs/os-specific/bsd/netbsd/pkgs/uudecode.nix
@@ -0,0 +1,10 @@
+{ lib, mkDerivation, stdenv }:
+
+mkDerivation {
+  path = "usr.bin/uudecode";
+  version = "9.2";
+  sha256 = "00a3zmh15pg4vx6hz0kaa5mi8d2b1sj4h512d7p6wbvxq6mznwcn";
+  env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isLinux "-DNO_BASE64";
+  NIX_LDFLAGS = lib.optional stdenv.isDarwin "-lresolv";
+}
+
diff --git a/pkgs/os-specific/linux/busybox/default.nix b/pkgs/os-specific/linux/busybox/default.nix
index ffeb82d9b41bf..33fa7663f46dd 100644
--- a/pkgs/os-specific/linux/busybox/default.nix
+++ b/pkgs/os-specific/linux/busybox/default.nix
@@ -167,6 +167,6 @@ stdenv.mkDerivation rec {
     license = licenses.gpl2Only;
     maintainers = with maintainers; [ TethysSvensson qyliss ];
     platforms = platforms.linux;
-    priority = 10;
+    priority = 15; # below systemd (halt, init, poweroff, reboot) and coreutils
   };
 }
diff --git a/pkgs/os-specific/linux/dbus-broker/default.nix b/pkgs/os-specific/linux/dbus-broker/default.nix
index 5180917623e93..784024f8754d0 100644
--- a/pkgs/os-specific/linux/dbus-broker/default.nix
+++ b/pkgs/os-specific/linux/dbus-broker/default.nix
@@ -40,13 +40,13 @@ in
 
 stdenv.mkDerivation (finalAttrs: {
   pname = "dbus-broker";
-  version = "35";
+  version = "36";
 
   src = fetchFromGitHub {
     owner = "bus1";
     repo = "dbus-broker";
     rev = "v${finalAttrs.version}";
-    hash = "sha256-Qwi9X5jXHiQ3TOWefzv/p7x8/JkQW1QgdYji5SpLej0=";
+    hash = "sha256-5dAMKjybqrHG57vArbtWEPR/svSj2ION75JrjvnnpVM=";
   };
 
   patches = [
diff --git a/pkgs/os-specific/linux/dbus-broker/disable-test.patch b/pkgs/os-specific/linux/dbus-broker/disable-test.patch
index 487967aea8406..14faf1907cc20 100644
--- a/pkgs/os-specific/linux/dbus-broker/disable-test.patch
+++ b/pkgs/os-specific/linux/dbus-broker/disable-test.patch
@@ -1,11 +1,14 @@
---- b/src/meson.build
-+++ a/src/meson.build
-@@ -196,9 +195,6 @@
- test_fdlist = executable('test-fdlist', ['util/test-fdlist.c'], dependencies: dep_bus)
- test('Utility File-Desciptor Lists', test_fdlist)
-
--test_fs = executable('test-fs', ['util/test-fs.c'], dependencies: dep_bus)
--test('File System Helpers', test_fs)
+diff --git a/src/meson.build b/src/meson.build
+index 4b9bc71..221ed5c 100644
+--- a/src/meson.build
++++ b/src/meson.build
+@@ -202,9 +202,6 @@ test('Error Handling', test_error, suite: 'unit')
+ test_fdlist = executable('test-fdlist', sources: ['util/test-fdlist.c'], kwargs: test_kwargs)
+ test('Utility File-Desciptor Lists', test_fdlist, suite: 'unit')
+ 
+-test_fs = executable('test-fs', sources: ['util/test-fs.c'], kwargs: test_kwargs)
+-test('File System Helpers', test_fs, suite: 'unit')
 -
- test_match = executable('test-match', ['bus/test-match.c'], dependencies: dep_bus)
- test('D-Bus Match Handling', test_match)
+ test_match = executable('test-match', sources: ['bus/test-match.c'], kwargs: test_kwargs)
+ test('D-Bus Match Handling', test_match, suite: 'unit')
+ 
diff --git a/pkgs/os-specific/linux/earlyoom/default.nix b/pkgs/os-specific/linux/earlyoom/default.nix
deleted file mode 100644
index d1d95b4d3f959..0000000000000
--- a/pkgs/os-specific/linux/earlyoom/default.nix
+++ /dev/null
@@ -1,38 +0,0 @@
-{ lib, stdenv, fetchFromGitHub, pandoc, installShellFiles, withManpage ? false, nixosTests }:
-
-stdenv.mkDerivation rec {
-  pname = "earlyoom";
-  version = "1.7";
-
-  src = fetchFromGitHub {
-    owner = "rfjakob";
-    repo = "earlyoom";
-    rev = "v${version}";
-    sha256 = "sha256-8YcT1TTlAet7F1U9Ginda4IApNqkudegOXqm8rnRGfc=";
-  };
-
-  nativeBuildInputs = lib.optionals withManpage [ pandoc installShellFiles ];
-
-  patches = [ ./fix-dbus-path.patch ];
-
-  makeFlags = [ "VERSION=${version}" ];
-
-  installPhase = ''
-    install -D earlyoom $out/bin/earlyoom
-  '' + lib.optionalString withManpage ''
-    installManPage earlyoom.1
-  '';
-
-  passthru.tests = {
-    inherit (nixosTests) earlyoom;
-  };
-
-  meta = with lib; {
-    description = "Early OOM Daemon for Linux";
-    mainProgram = "earlyoom";
-    homepage = "https://github.com/rfjakob/earlyoom";
-    license = licenses.mit;
-    platforms = platforms.linux;
-    maintainers = with maintainers; [];
-  };
-}
diff --git a/pkgs/os-specific/linux/earlyoom/fix-dbus-path.patch b/pkgs/os-specific/linux/earlyoom/fix-dbus-path.patch
deleted file mode 100644
index e1c10cf82f96e..0000000000000
--- a/pkgs/os-specific/linux/earlyoom/fix-dbus-path.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- a/kill.c
-+++ b/kill.c
-@@ -55,7 +55,7 @@ static void notify(const char* summary, const char* body)
-     }
-     // Complete command line looks like this:
-     // dbus-send --system / net.nuetzlich.SystemNotifications.Notify 'string:summary text' 'string:and body text'
--    execl("/usr/bin/dbus-send", "dbus-send", "--system", "/", "net.nuetzlich.SystemNotifications.Notify",
-+    execlp("dbus-send", "dbus-send", "--system", "/", "net.nuetzlich.SystemNotifications.Notify",
-         summary2, body2, NULL);
-     warn("notify: exec failed: %s\n", strerror(errno));
-     exit(1);
diff --git a/pkgs/os-specific/linux/fw-ectool/default.nix b/pkgs/os-specific/linux/fw-ectool/default.nix
index 1d23411f3eefc..a73cc1896ecdc 100644
--- a/pkgs/os-specific/linux/fw-ectool/default.nix
+++ b/pkgs/os-specific/linux/fw-ectool/default.nix
@@ -1,43 +1,38 @@
 { stdenv
 , lib
-, fetchFromGitLab
-, cmake
+, fetchFromGitHub
 , pkg-config
-, libusb1
-, libftdi1
+, hostname
 }:
 
 stdenv.mkDerivation {
   pname = "fw-ectool";
-  version = "0-unstable-2023-12-15";
+  version = "unstable-2022-12-03";
 
-  src = fetchFromGitLab {
-    domain = "gitlab.howett.net";
+  src = fetchFromGitHub {
     owner = "DHowett";
-    repo = "ectool";
-    rev = "3ebe7b8b713b2ebfe2ce92d48fd8d044276b2879";
-    hash = "sha256-s6PrFPAL+XJAENqLw5oJqFmAf11tHOJ8h3F5l3pOlZ4=";
+    repo = "fw-ectool";
+    rev = "54c140399bbc3e6a3dce6c9f842727c4128367be";
+    hash = "sha256-2teJFz4zcA+USpbVPXMEIHLdmMLem8ik7YrmrSxr/n0=";
   };
 
   nativeBuildInputs = [
-    cmake
     pkg-config
+    hostname
   ];
 
-  buildInputs = [
-    libusb1
-    libftdi1
-  ];
+  buildPhase = ''
+    patchShebangs util
+    make out=out utils
+  '';
 
   installPhase = ''
-    runHook preInstall
-    install -Dm555 src/ectool "$out/bin/ectool"
-    runHook postInstall
+    install -D out/util/ectool $out/bin/ectool
   '';
 
   meta = with lib; {
     description = "EC-Tool adjusted for usage with framework embedded controller";
-    homepage = "https://gitlab.howett.net/DHowett/ectool";
+    homepage = "https://github.com/DHowett/framework-ec";
     license = licenses.bsd3;
     maintainers = [ maintainers.mkg20001 ];
     platforms = platforms.linux;
diff --git a/pkgs/os-specific/linux/intel-compute-runtime/default.nix b/pkgs/os-specific/linux/intel-compute-runtime/default.nix
index f4a250d4a84c8..e686e06804197 100644
--- a/pkgs/os-specific/linux/intel-compute-runtime/default.nix
+++ b/pkgs/os-specific/linux/intel-compute-runtime/default.nix
@@ -11,13 +11,13 @@
 
 stdenv.mkDerivation rec {
   pname = "intel-compute-runtime";
-  version = "24.09.28717.12";
+  version = "24.13.29138.7";
 
   src = fetchFromGitHub {
     owner = "intel";
     repo = "compute-runtime";
     rev = version;
-    hash = "sha256-RzXV6icenMcQxmOfKA8Tpb6FigLXz3ZyoL0n16+jFRc=";
+    hash = "sha256-AMIuA1AMrSX0xpdGSfye8iUJTk5s9HDiRy9Yy3kZss8=";
   };
 
   nativeBuildInputs = [ cmake pkg-config ];
diff --git a/pkgs/os-specific/linux/lenovo-legion/app.nix b/pkgs/os-specific/linux/lenovo-legion/app.nix
index 6d6c604b1c054..eeccf301ee95b 100644
--- a/pkgs/os-specific/linux/lenovo-legion/app.nix
+++ b/pkgs/os-specific/linux/lenovo-legion/app.nix
@@ -2,13 +2,13 @@
 
 python3.pkgs.buildPythonApplication rec {
   pname = "lenovo-legion-app";
-  version = "0.0.9";
+  version = "0.0.12";
 
   src = fetchFromGitHub {
     owner = "johnfanv2";
     repo = "LenovoLegionLinux";
     rev = "v${version}-prerelease";
-    hash = "sha256-PQdxfDfW3sn0wWjmsPoAt3HZ43PS3Tyez3/0KEVVZQg=";
+    hash = "sha256-BNrRv9EBmNINQbAw+BzVxKl/XoDgH1tsNZHJxfSpNoU=";
   };
 
   sourceRoot = "${src.name}/python/legion_linux";
@@ -17,6 +17,7 @@ python3.pkgs.buildPythonApplication rec {
 
   propagatedBuildInputs = with python3.pkgs; [
     pyqt5
+    pyqt6
     argcomplete
     pyyaml
     darkdetect
@@ -26,13 +27,13 @@ python3.pkgs.buildPythonApplication rec {
 
   postPatch = ''
     substituteInPlace ./setup.cfg \
-      --replace "_VERSION" "${version}"
+      --replace-fail "_VERSION" "${version}"
     substituteInPlace ../../extra/service/fancurve-set \
-      --replace "FOLDER=/etc/legion_linux/" "FOLDER=$out/share/legion_linux"
+      --replace-fail "FOLDER=/etc/legion_linux/" "FOLDER=$out/share/legion_linux"
     substituteInPlace ./legion_linux/legion.py \
-      --replace "/etc/legion_linux" "$out/share/legion_linux"
-    substituteInPlace ./legion_linux/legion_gui{,_user}.desktop \
-      --replace "Icon=/usr/share/pixmaps/legion_logo.png" "Icon=legion_logo"
+      --replace-fail "/etc/legion_linux" "$out/share/legion_linux"
+    substituteInPlace ./legion_linux/legion_gui.desktop \
+      --replace-fail "Icon=/usr/share/pixmaps/legion_logo.png" "Icon=legion_logo"
   '';
 
   dontWrapQtApps = true;
diff --git a/pkgs/os-specific/linux/mwprocapture/default.nix b/pkgs/os-specific/linux/mwprocapture/default.nix
index a90a8716cca92..2b4628762f105 100644
--- a/pkgs/os-specific/linux/mwprocapture/default.nix
+++ b/pkgs/os-specific/linux/mwprocapture/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
 
   src = fetchurl {
     url = "https://www.magewell.com/files/drivers/ProCaptureForLinux_${subVersion}.tar.gz";
-    sha256 = "sha256-HOVAR9auc8ulENPLoI0scdCMZoSbDYkTaCLgZoFG7eU=";
+    sha256 = "sha256-a2cU7PYQh1KR5eeMhMNx2Sc3HHd7QvCG9+BoJyVPp1Y=";
   };
 
   nativeBuildInputs = kernel.moduleBuildDependencies;
diff --git a/pkgs/os-specific/linux/r8125/default.nix b/pkgs/os-specific/linux/r8125/default.nix
index 1c261355954ad..9b5210350bdd2 100644
--- a/pkgs/os-specific/linux/r8125/default.nix
+++ b/pkgs/os-specific/linux/r8125/default.nix
@@ -4,7 +4,7 @@ stdenv.mkDerivation rec {
   pname = "r8125";
   # On update please verify (using `diff -r`) that the source matches the
   # realtek version.
-  version = "9.012.03";
+  version = "9.013.02";
 
   # This is a mirror. The original website[1] doesn't allow non-interactive
   # downloads, instead emailing you a download link.
@@ -13,7 +13,7 @@ stdenv.mkDerivation rec {
     owner = "louistakepillz";
     repo = "r8125";
     rev = version;
-    sha256 = "sha256-+CrxvKB96QOcOo87McZOt/XUhriTtTV8jTQgpBG3ejs=";
+    sha256 = "sha256-i45xKF5WVN+nNhpD6HWZHvGgxuaD/YhMHERqW8/bC5Y=";
   };
 
   hardeningDisable = [ "pic" ];
diff --git a/pkgs/os-specific/linux/rtl8852au/default.nix b/pkgs/os-specific/linux/rtl8852au/default.nix
new file mode 100644
index 0000000000000..d154fbe86a208
--- /dev/null
+++ b/pkgs/os-specific/linux/rtl8852au/default.nix
@@ -0,0 +1,52 @@
+{ lib, stdenv, fetchFromGitHub, kernel, bc, nukeReferences }:
+
+stdenv.mkDerivation {
+  pname = "rtl8852au";
+  version = "${kernel.version}-unstable-2023-11-24";
+
+  src = fetchFromGitHub {
+    owner = "lwfinger";
+    repo = "rtl8852au";
+    rev = "70bdde265b9ab002daf11d4bea1a42baa8da4325";
+    hash = "sha256-6ARS7/0iKYajpMH+f+jWDxIkPY9ZixJkk864oKom4l4=";
+  };
+
+  nativeBuildInputs = [ bc nukeReferences ] ++ kernel.moduleBuildDependencies;
+  hardeningDisable = [ "pic" "format" ];
+
+  postPatch = ''
+    substituteInPlace ./Makefile \
+      --replace-fail /sbin/depmod \# \
+      --replace-fail '$(MODDESTDIR)' "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/" \
+      --replace-fail '/usr/lib/systemd/system-sleep' "$out/usr/lib/systemd/system-sleep"
+    substituteInPlace ./platform/i386_pc.mk \
+      --replace-fail /lib/modules "${kernel.dev}/lib/modules"
+  '';
+
+  makeFlags = [
+    "ARCH=${stdenv.hostPlatform.linuxArch}"
+    ("CONFIG_PLATFORM_I386_PC=" + (if stdenv.hostPlatform.isx86 then "y" else "n"))
+    ("CONFIG_PLATFORM_ARM_RPI=" + (if stdenv.hostPlatform.isAarch then "y" else "n"))
+  ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
+    "CROSS_COMPILE=${stdenv.cc.targetPrefix}"
+  ];
+
+  preInstall = ''
+    mkdir -p "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+    mkdir -p "$out/usr/lib/systemd/system-sleep"
+  '';
+
+  postInstall = ''
+    nuke-refs $out/lib/modules/*/kernel/net/wireless/*.ko
+  '';
+
+  enableParallelBuilding = true;
+
+  meta = with lib; {
+    description = "Driver for Realtek 802.11ac, rtl8852au, provides the 8852au mod";
+    homepage = "https://github.com/lwfinger/rtl8852au";
+    license = licenses.gpl2Only;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ lonyelon ];
+  };
+}
diff --git a/pkgs/os-specific/linux/sgx/azure-dcap-client/default.nix b/pkgs/os-specific/linux/sgx/azure-dcap-client/default.nix
index 0ee191e868957..c21f8ea8a644b 100644
--- a/pkgs/os-specific/linux/sgx/azure-dcap-client/default.nix
+++ b/pkgs/os-specific/linux/sgx/azure-dcap-client/default.nix
@@ -35,13 +35,13 @@ let
 in
 stdenv.mkDerivation rec {
   pname = "azure-dcap-client";
-  version = "1.12.1";
+  version = "1.12.3";
 
   src = fetchFromGitHub {
     owner = "microsoft";
     repo = pname;
     rev = version;
-    hash = "sha256-q0dI4WdA1ue4sw+QfSherh31Ldf9gnhoft66o3E9gnU=";
+    hash = "sha256-zTDaICsSPXctgFRCZBiZwXV9dLk2pFL9kp5a8FkiTZA=";
   };
 
   patches = [
@@ -87,7 +87,7 @@ stdenv.mkDerivation rec {
   meta = with lib; {
     description = "Interfaces between SGX SDKs and the Azure Attestation SGX Certification Cache";
     homepage = "https://github.com/microsoft/azure-dcap-client";
-    maintainers = with maintainers; [ trundle veehaitch ];
+    maintainers = with maintainers; [ phlip9 trundle veehaitch ];
     platforms = [ "x86_64-linux" ];
     license = [ licenses.mit ];
   };
diff --git a/pkgs/os-specific/linux/sgx/psw/default.nix b/pkgs/os-specific/linux/sgx/psw/default.nix
index 22e52b6ec9fdb..42e00071d8101 100644
--- a/pkgs/os-specific/linux/sgx/psw/default.nix
+++ b/pkgs/os-specific/linux/sgx/psw/default.nix
@@ -14,7 +14,7 @@
 , debug ? false
 }:
 stdenv.mkDerivation rec {
-  inherit (sgx-sdk) version versionTag src;
+  inherit (sgx-sdk) patches src version versionTag;
   pname = "sgx-psw";
 
   postUnpack =
@@ -24,16 +24,16 @@ stdenv.mkDerivation rec {
       # attestation quotes, and do platform certification.
       ae.prebuilt = fetchurl {
         url = "https://download.01.org/intel-sgx/sgx-linux/${versionTag}/prebuilt_ae_${versionTag}.tar.gz";
-        hash = "sha256-IckW4p1XWkWCDCErXyTtnKYKeAUaCrp5iAMsRBMjLX0=";
+        hash = "sha256-IGV9VEwY/cQBV4Vz2sps4JgRweWRl/l08ocb9P4SH8Q=";
       };
       # Also include the Data Center Attestation Primitives (DCAP) platform
       # enclaves.
       dcap = rec {
-        version = "1.18";
+        version = "1.20";
         filename = "prebuilt_dcap_${version}.tar.gz";
         prebuilt = fetchurl {
           url = "https://download.01.org/intel-sgx/sgx-dcap/${version}/linux/${filename}";
-          hash = "sha256-9ceys7ozOEienug+9MTZ6dw3nx7VBfxLNiwhZYv4SzY=";
+          hash = "sha256-nPsI89KSBA3cSNTMWyktZP5dkf+BwL3NZ4MuUf6G98o=";
         };
       };
     in
@@ -181,7 +181,7 @@ stdenv.mkDerivation rec {
   meta = with lib; {
     description = "Intel SGX Architectural Enclave Service Manager";
     homepage = "https://github.com/intel/linux-sgx";
-    maintainers = with maintainers; [ veehaitch citadelcore ];
+    maintainers = with maintainers; [ phlip9 veehaitch citadelcore ];
     platforms = [ "x86_64-linux" ];
     license = with licenses; [ bsd3 ];
   };
diff --git a/pkgs/os-specific/linux/sgx/sdk/cppmicroservices-no-mtime.patch b/pkgs/os-specific/linux/sgx/sdk/cppmicroservices-no-mtime.patch
new file mode 100644
index 0000000000000..019f58927152a
--- /dev/null
+++ b/pkgs/os-specific/linux/sgx/sdk/cppmicroservices-no-mtime.patch
@@ -0,0 +1,26 @@
+diff --git a/external/CppMicroServices/framework/src/bundle/BundleResourceContainer.cpp b/external/CppMicroServices/framework/src/bundle/BundleResourceContainer.cpp
+index aee499e9..13fa89d4 100644
+--- a/external/CppMicroServices/framework/src/bundle/BundleResourceContainer.cpp
++++ b/external/CppMicroServices/framework/src/bundle/BundleResourceContainer.cpp
+@@ -105,7 +105,7 @@ bool BundleResourceContainer::GetStat(int index,
+                    const_cast<mz_zip_archive*>(&m_ZipArchive), index)
+                    ? true
+                    : false;
+-    stat.modifiedTime = zipStat.m_time;
++    stat.modifiedTime = 0;
+     stat.crc32 = zipStat.m_crc32;
+     // This will limit the size info from uint64 to uint32 on 32-bit
+     // architectures. We don't care because we assume resources > 2GB
+diff --git a/external/CppMicroServices/third_party/miniz.c b/external/CppMicroServices/third_party/miniz.c
+index 6b0ebd7a..fa2aebca 100644
+--- a/external/CppMicroServices/third_party/miniz.c
++++ b/external/CppMicroServices/third_party/miniz.c
+@@ -170,7 +170,7 @@
+ // If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or
+ // get/set file times, and the C run-time funcs that get/set times won't be called.
+ // The current downside is the times written to your archives will be from 1979.
+-//#define MINIZ_NO_TIME
++#define MINIZ_NO_TIME
+
+ // Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's.
+ //#define MINIZ_NO_ARCHIVE_APIS
diff --git a/pkgs/os-specific/linux/sgx/sdk/default.nix b/pkgs/os-specific/linux/sgx/sdk/default.nix
index 2570406a7112e..67489ee3c07c4 100644
--- a/pkgs/os-specific/linux/sgx/sdk/default.nix
+++ b/pkgs/os-specific/linux/sgx/sdk/default.nix
@@ -1,7 +1,6 @@
 { lib
 , stdenv
 , fetchFromGitHub
-, fetchpatch
 , autoconf
 , automake
 , binutils
@@ -27,15 +26,15 @@
 stdenv.mkDerivation rec {
   pname = "sgx-sdk";
   # Version as given in se_version.h
-  version = "2.21.100.1";
+  version = "2.23.100.2";
   # Version as used in the Git tag
-  versionTag = "2.21";
+  versionTag = "2.23";
 
   src = fetchFromGitHub {
     owner = "intel";
     repo = "linux-sgx";
     rev = "sgx_${versionTag}";
-    hash = "sha256-Yo2G0H0XUI2p9W7lDRLkFHw2t8X1220brGohQJ0r2WY=";
+    hash = "sha256-i+fE6xKiuljG8LY8TIHgrW15DVpdp46bZdNo/BjgT/I=";
     fetchSubmodules = true;
   };
 
@@ -46,39 +45,28 @@ stdenv.mkDerivation rec {
   '';
 
   patches = [
-    # Fix missing pthread_compat.h, see https://github.com/intel/linux-sgx/pull/784
-    (fetchpatch {
-      url = "https://github.com/intel/linux-sgx/commit/254b58f922a6bd49c308a4f47f05f525305bd760.patch";
-      sha256 = "sha256-sHU++K7NJ+PdITx3y0PwstA9MVh10rj2vrLn01N9F4w=";
-    })
+    # There's a `make preparation` step that downloads some prebuilt binaries
+    # and applies some patches to the in-repo git submodules. This patch removes
+    # the parts that download things, since we can't do that inside the sandbox.
+    ./disable-downloads.patch
+
+    # This patch disable mtime in bundled zip file for reproducible builds.
+    #
+    # Context: The `aesm_service` binary depends on a vendored library called
+    # `CppMicroServices`. At build time, this lib creates and then bundles
+    # service resources into a zip file and then embeds this zip into the
+    # binary. Without changes, the `aesm_service` will be different after every
+    # build because the embedded zip file contents have different modified times.
+    ./cppmicroservices-no-mtime.patch
   ];
 
-  # There's a `make preparation` step that downloads some prebuilt binaries and
-  # applies some patches to the in-repo git submodules. We can't just run it,
-  # since it downloads things, so this step just extracts the patching steps.
   postPatch = ''
     patchShebangs linux/installer/bin/build-installpkg.sh \
       linux/installer/common/sdk/createTarball.sh \
       linux/installer/common/sdk/install.sh \
       external/sgx-emm/create_symlink.sh
 
-    echo "Running 'make preparation' but without download steps"
-
-    # Seems to download something. Build currently uses ipp-crypto and not
-    # sgxssl so probably not an issue.
-    # $ ./external/dcap_source/QuoteVerification/prepare_sgxssl.sh nobuild
-
-    pushd external/openmp/openmp_code
-      git apply ../0001-Enable-OpenMP-in-SGX.patch >/dev/null 2>&1 \
-        || git apply ../0001-Enable-OpenMP-in-SGX.patch --check -R
-    popd
-
-    pushd external/protobuf/protobuf_code
-      git apply ../sgx_protobuf.patch >/dev/null 2>&1 \
-        || git apply ../sgx_protobuf.patch --check -R
-    popd
-
-    ./external/sgx-emm/create_symlink.sh
+    make preparation
   '';
 
   # We need `cmake` as a build input but don't use it to kick off the build phase
@@ -300,7 +288,7 @@ stdenv.mkDerivation rec {
   meta = with lib; {
     description = "Intel SGX SDK for Linux built with IPP Crypto Library";
     homepage = "https://github.com/intel/linux-sgx";
-    maintainers = with maintainers; [ sbellem arturcygan veehaitch ];
+    maintainers = with maintainers; [ phlip9 sbellem arturcygan veehaitch ];
     platforms = [ "x86_64-linux" ];
     license = with licenses; [ bsd3 ];
   };
diff --git a/pkgs/os-specific/linux/sgx/sdk/disable-downloads.patch b/pkgs/os-specific/linux/sgx/sdk/disable-downloads.patch
new file mode 100644
index 0000000000000..bdf9b9f9136e9
--- /dev/null
+++ b/pkgs/os-specific/linux/sgx/sdk/disable-downloads.patch
@@ -0,0 +1,26 @@
+diff --git a/Makefile b/Makefile
+index 32433051..2e480efb 100644
+--- a/Makefile
++++ b/Makefile
+@@ -50,8 +50,8 @@ tips:
+ preparation:
+ # As SDK build needs to clone and patch openmp, we cannot support the mode that download the source from github as zip.
+ # Only enable the download from git
+-	git submodule update --init --recursive
+-	./external/dcap_source/QuoteVerification/prepare_sgxssl.sh nobuild
++	# git submodule update --init --recursive
++	# ./external/dcap_source/QuoteVerification/prepare_sgxssl.sh nobuild
+ 	cd external/openmp/openmp_code && git apply ../0001-Enable-OpenMP-in-SGX.patch >/dev/null 2>&1 ||  git apply ../0001-Enable-OpenMP-in-SGX.patch --check -R
+ 	cd external/protobuf/protobuf_code && git apply ../sgx_protobuf.patch >/dev/null 2>&1 ||  git apply ../sgx_protobuf.patch --check -R
+ 	./external/sgx-emm/create_symlink.sh
+@@ -59,8 +59,8 @@ preparation:
+ 	cd external/cbor && cp -r libcbor sgx_libcbor
+ 	cd external/cbor/libcbor && git apply ../raw_cbor.patch >/dev/null 2>&1 || git apply ../raw_cbor.patch --check -R
+ 	cd external/cbor/sgx_libcbor && git apply ../sgx_cbor.patch >/dev/null 2>&1 || git apply ../sgx_cbor.patch --check -R
+-	./download_prebuilt.sh
+-	./external/dcap_source/QuoteGeneration/download_prebuilt.sh
++	# ./download_prebuilt.sh
++	# ./external/dcap_source/QuoteGeneration/download_prebuilt.sh
+ 
+ psw:
+ 	$(MAKE) -C psw/ USE_OPT_LIBS=$(USE_OPT_LIBS)
diff --git a/pkgs/os-specific/linux/sgx/sdk/ipp-crypto.nix b/pkgs/os-specific/linux/sgx/sdk/ipp-crypto.nix
index 5a4c941a22b99..c72a0c5285164 100644
--- a/pkgs/os-specific/linux/sgx/sdk/ipp-crypto.nix
+++ b/pkgs/os-specific/linux/sgx/sdk/ipp-crypto.nix
@@ -8,13 +8,13 @@
 }:
 gcc11Stdenv.mkDerivation rec {
   pname = "ipp-crypto";
-  version = "2021.9.0";
+  version = "2021.10.0";
 
   src = fetchFromGitHub {
     owner = "intel";
     repo = "ipp-crypto";
     rev = "ippcp_${version}";
-    hash = "sha256-+ITnxyrkDQp4xRa+PVzXdYsSkI5sMNwQGfGU+lFJ6co=";
+    hash = "sha256-DfXsJ+4XqyjCD+79LUD53Cx8D46o1a4fAZa2UxGI1Xg=";
   };
 
   cmakeFlags = [ "-DARCH=intel64" ] ++ extraCmakeFlags;
diff --git a/pkgs/os-specific/linux/sgx/ssl/default.nix b/pkgs/os-specific/linux/sgx/ssl/default.nix
index 9d1905e09d1f7..94d7e20b21c41 100644
--- a/pkgs/os-specific/linux/sgx/ssl/default.nix
+++ b/pkgs/os-specific/linux/sgx/ssl/default.nix
@@ -1,8 +1,8 @@
 { stdenv
+, callPackage
 , fetchFromGitHub
 , fetchurl
 , lib
-, openssl
 , perl
 , sgx-sdk
 , which
@@ -10,7 +10,7 @@
 }:
 let
   sgxVersion = sgx-sdk.versionTag;
-  opensslVersion = "1.1.1u";
+  opensslVersion = "3.0.12";
 in
 stdenv.mkDerivation {
   pname = "sgx-ssl" + lib.optionalString debug "-debug";
@@ -19,15 +19,15 @@ stdenv.mkDerivation {
   src = fetchFromGitHub {
     owner = "intel";
     repo = "intel-sgx-ssl";
-    rev = "lin_${sgxVersion}_${opensslVersion}";
-    hash = "sha256-zbXEQz72VUPqnGrboX6oXliaLpbcos7tV6K9lX+zleg=";
+    rev = "3.0_Rev2";
+    hash = "sha256-dmLyaG6v+skjSa0KxLAfIfSBOxp9grrI7ds6WdGPe0I=";
   };
 
   postUnpack =
     let
       opensslSourceArchive = fetchurl {
         url = "https://www.openssl.org/source/openssl-${opensslVersion}.tar.gz";
-        hash = "sha256-4vjYS1I+7NBse+diaDA3AwD7zBU4a/UULXJ1j2lj68Y=";
+        hash = "sha256-+Tyejt3l6RZhGd4xdV/Ie0qjSGNmL2fd/LoU0La2m2E=";
       };
     in
     ''
@@ -37,7 +37,7 @@ stdenv.mkDerivation {
   postPatch = ''
     patchShebangs Linux/build_openssl.sh
 
-    # Run the test in the `installCheckPhase`, not the `buildPhase`
+    # Skip the tests. Build and run separately (see below).
     substituteInPlace Linux/sgx/Makefile \
       --replace '$(MAKE) -C $(TEST_DIR) all' \
                 'bash -c "true"'
@@ -46,7 +46,6 @@ stdenv.mkDerivation {
   nativeBuildInputs = [
     perl
     sgx-sdk
-    stdenv.cc.libc
     which
   ];
 
@@ -60,21 +59,22 @@ stdenv.mkDerivation {
     "DESTDIR=$(out)"
   ];
 
-  # Build the test app
-  doInstallCheck = true;
-  installCheckTarget = "test";
-  installCheckFlags = [
-    "SGX_MODE=SIM"
-    "-j 1" # Makefile doesn't support multiple jobs
-  ];
-  nativeInstallCheckInputs = [
-    openssl
-  ];
+  # These tests build on any x86_64-linux but BOTH SIM and HW will only _run_ on
+  # real Intel hardware. Split these out so OfBorg doesn't choke on this pkg.
+  #
+  # ```
+  # nix run .#sgx-ssl.tests.HW
+  # nix run .#sgx-ssl.tests.SIM
+  # ```
+  passthru.tests = {
+    HW = callPackage ./tests.nix { sgxMode = "HW"; inherit opensslVersion; };
+    SIM = callPackage ./tests.nix { sgxMode = "SIM"; inherit opensslVersion; };
+  };
 
   meta = with lib; {
     description = "Cryptographic library for Intel SGX enclave applications based on OpenSSL";
     homepage = "https://github.com/intel/intel-sgx-ssl";
-    maintainers = with maintainers; [ trundle veehaitch ];
+    maintainers = with maintainers; [ phlip9 trundle veehaitch ];
     platforms = [ "x86_64-linux" ];
     license = [ licenses.bsd3 licenses.openssl ];
   };
diff --git a/pkgs/os-specific/linux/sgx/ssl/tests.nix b/pkgs/os-specific/linux/sgx/ssl/tests.nix
new file mode 100644
index 0000000000000..d9357ba043102
--- /dev/null
+++ b/pkgs/os-specific/linux/sgx/ssl/tests.nix
@@ -0,0 +1,95 @@
+# This package _builds_ (but doesn't run!) the sgx-ssl test enclave + harness.
+# The whole package effectively does:
+#
+# ```
+# SGX_MODE=${sgxMode} make -C Linux/sgx/test_app
+# cp Linux/sgx/{TestApp,TestEnclave.signed.so} $out/bin
+# ```
+#
+# OfBorg fails to run these tests since they require real Intel HW. That
+# includes the simulation mode! The tests appears to do something fancy with
+# cpuid and exception trap handlers that make them very non-portable.
+#
+# These tests are split out from the parent pkg since recompiling the parent
+# takes like 30 min : )
+
+{ lib
+, openssl
+, sgx-psw
+, sgx-sdk
+, sgx-ssl
+, stdenv
+, which
+, opensslVersion ? throw "required parameter"
+, sgxMode ? throw "required parameter" # "SIM" or "HW"
+}:
+stdenv.mkDerivation {
+  inherit (sgx-ssl) postPatch src version;
+  pname = sgx-ssl.pname + "-tests-${sgxMode}";
+
+  postUnpack = sgx-ssl.postUnpack + ''
+    sourceRootAbs=$(readlink -e $sourceRoot)
+    packageDir=$sourceRootAbs/Linux/package
+
+    # Do the inverse of 'make install' and symlink built artifacts back into
+    # '$src/Linux/package/' to avoid work.
+    mkdir $packageDir/lib $packageDir/lib64
+    ln -s ${lib.getLib sgx-ssl}/lib/* $packageDir/lib/
+    ln -s ${lib.getLib sgx-ssl}/lib64/* $packageDir/lib64/
+    ln -sf ${lib.getDev sgx-ssl}/include/* $packageDir/include/
+
+    # test_app needs some internal openssl headers.
+    # See: tail end of 'Linux/build_openssl.sh'
+    tar -C $sourceRootAbs/openssl_source -xf $sourceRootAbs/openssl_source/openssl-${opensslVersion}.tar.gz
+    echo '#define OPENSSL_VERSION_STR "${opensslVersion}"' > $sourceRootAbs/Linux/sgx/osslverstr.h
+    ln -s $sourceRootAbs/openssl_source/openssl-${opensslVersion}/include/crypto $sourceRootAbs/Linux/sgx/test_app/enclave/
+    ln -s $sourceRootAbs/openssl_source/openssl-${opensslVersion}/include/internal $sourceRootAbs/Linux/sgx/test_app/enclave/
+  '';
+
+  nativeBuildInputs = [
+    openssl.bin
+    sgx-sdk
+    which
+  ];
+
+  preBuild = ''
+    # Need to regerate the edl header
+    make -C Linux/sgx/libsgx_tsgxssl sgx_tsgxssl_t.c
+  '';
+
+  makeFlags = [
+    "-C Linux/sgx/test_app"
+    "SGX_MODE=${sgxMode}"
+  ];
+
+  installPhase = ''
+    runHook preInstall
+
+    # Enclaves can't be stripped after signing.
+    install -Dm 755 Linux/sgx/test_app/TestEnclave.signed.so -t $TMPDIR/enclaves
+
+    install -Dm 755 Linux/sgx/test_app/TestApp -t $out/bin
+
+    runHook postInstall
+  '';
+
+  postFixup = ''
+    # Move the enclaves where they actually belong.
+    mv $TMPDIR/enclaves/*.signed.so* $out/bin/
+
+    # HW SGX must runs against sgx-psw, not sgx-sdk.
+    if [[ "${sgxMode}" == "HW" ]]; then
+      patchelf \
+        --set-rpath "$( \
+          patchelf --print-rpath $out/bin/TestApp \
+            | sed 's|${lib.getLib sgx-sdk}|${lib.getLib sgx-psw}|' \
+        )" \
+        $out/bin/TestApp
+    fi
+  '';
+
+  meta = {
+    platforms = [ "x86_64-linux" ];
+    mainProgram = "TestApp";
+  };
+}