about summary refs log tree commit diff
path: root/pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix')
-rw-r--r--pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix149
1 files changed, 112 insertions, 37 deletions
diff --git a/pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix b/pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix
index 81cf4114e8737..62a78dcded91e 100644
--- a/pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix
+++ b/pkgs/os-specific/bsd/freebsd/pkgs/sys/package.nix
@@ -1,26 +1,90 @@
-{ lib, stdenv, mkDerivation, freebsd-lib
-, buildPackages
-, bsdSetupHook, freebsdSetupHook
-, makeMinimal, install, mandoc, groff
-, config, rpcgen, file2c, gawk, uudecode, xargs-j #, ctfconvert
+{
+  lib,
+  mkDerivation,
+  stdenv,
+  buildPackages,
+  freebsd-lib,
+  patches,
+  filterSource,
+  applyPatches,
+  baseConfig ? "GENERIC",
+  extraFlags ? { },
+  bsdSetupHook,
+  mandoc,
+  groff,
+  gawk,
+  freebsdSetupHook,
+  makeMinimal,
+  install,
+  config,
+  rpcgen,
+  file2c,
+  bintrans,
+  xargs-j,
+  kldxref,
 }:
-
-mkDerivation (let
-  cfg = "MINIMAL";
-in rec {
+let
+  hostArchBsd = freebsd-lib.mkBsdArch stdenv;
+  filteredSource = filterSource {
+    pname = "sys";
+    path = "sys";
+    extraPaths = [ "include" ];
+  };
+  patchedSource = applyPatches {
+    src = filteredSource;
+    patches = freebsd-lib.filterPatches patches [
+      "sys"
+      "include"
+    ];
+    postPatch = ''
+      for f in sys/conf/kmod.mk sys/contrib/dev/acpica/acpica_prep.sh; do
+        substituteInPlace "$f" --replace-warn 'xargs -J' 'xargs-j '
+      done
+
+      for f in sys/conf/*.mk; do
+        substituteInPlace "$f" --replace-quiet 'KERN_DEBUGDIR}''${' 'KERN_DEBUGDIR_'
+      done
+
+      sed -i sys/${hostArchBsd}/conf/${baseConfig} \
+        -e 's/WITH_CTF=1/WITH_CTF=0/' \
+        -e '/KDTRACE/d'
+    '';
+  };
+
+  # Kernel modules need this for kern.opts.mk
+  env =
+    {
+      MK_CTF = "no";
+    }
+    // (lib.flip lib.mapAttrs' extraFlags (
+      name: value: {
+        name = "MK_${lib.toUpper name}";
+        value = if value then "yes" else "no";
+      }
+    ));
+in
+mkDerivation rec {
+  pname = "sys";
+
+  # Patch source outside of this derivation so out-of-tree modules can use it
+  src = patchedSource;
   path = "sys";
+  autoPickPatches = false;
 
   nativeBuildInputs = [
-    bsdSetupHook freebsdSetupHook
-    makeMinimal install mandoc groff
-
-    config rpcgen file2c gawk uudecode xargs-j
-    #ctfconvert
-  ];
-
-  patches = [
-    ./sys-gnu-date.patch
-    ./sys-no-explicit-intrinsics-dep.patch
+    bsdSetupHook
+    mandoc
+    groff
+    gawk
+    freebsdSetupHook
+    makeMinimal
+    install
+    config
+    rpcgen
+    file2c
+    bintrans
+    xargs-j
+    kldxref
   ];
 
   # --dynamic-linker /red/herring is used when building the kernel.
@@ -30,13 +94,25 @@ in rec {
 
   CWARNEXTRA = "-Wno-error=shift-negative-value -Wno-address-of-packed-member";
 
-  MK_CTF = "no";
+  hardeningDisable = [
+    "pic" # generates relocations the linker can't handle
+    "stackprotector" # generates stack protection for the function generating the stack canary
+  ];
+
+  # hardeningDisable = stackprotector doesn't seem to be enough, put it in cflags too
+  NIX_CFLAGS_COMPILE = [
+    "-fno-stack-protector"
+    "-Wno-unneeded-internal-declaration" # some openzfs code trips this
+  ];
+
+  inherit env;
+  passthru.env = env;
 
   KODIR = "${builtins.placeholder "out"}/kernel";
   KMODDIR = "${builtins.placeholder "out"}/kernel";
-  DTBDIR = "${builtins.placeholder"out"}/dbt";
+  DTBDIR = "${builtins.placeholder "out"}/dbt";
 
-  KERN_DEBUGDIR = "${builtins.placeholder "out"}/debug";
+  KERN_DEBUGDIR = "${builtins.placeholder "debug"}/lib/debug";
   KERN_DEBUGDIR_KODIR = "${KERN_DEBUGDIR}/kernel";
   KERN_DEBUGDIR_KMODDIR = "${KERN_DEBUGDIR}/kernel";
 
@@ -45,23 +121,22 @@ in rec {
   configurePhase = ''
     runHook preConfigure
 
-    for f in conf/kmod.mk contrib/dev/acpica/acpica_prep.sh; do
-      substituteInPlace "$f" --replace 'xargs -J' 'xargs-j '
-    done
-
-    for f in conf/*.mk; do
-      substituteInPlace "$f" --replace 'KERN_DEBUGDIR}''${' 'KERN_DEBUGDIR_'
-    done
-
-    cd ${freebsd-lib.mkBsdArch stdenv}/conf
-    sed -i ${cfg} \
-      -e 's/WITH_CTF=1/WITH_CTF=0/' \
-      -e '/KDTRACE/d'
-    config ${cfg}
+    cd ${hostArchBsd}/conf
+    config ${baseConfig}
 
     runHook postConfigure
   '';
   preBuild = ''
-    cd ../compile/${cfg}
+    cd ../compile/${baseConfig}
   '';
-})
+
+  outputs = [
+    "out"
+    "debug"
+  ];
+
+  meta = {
+    description = "FreeBSD kernel and modules";
+    platforms = lib.platforms.freebsd;
+  };
+}