about summary refs log tree commit diff
path: root/pkgs/os-specific/bsd/openbsd
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/os-specific/bsd/openbsd')
-rw-r--r--pkgs/os-specific/bsd/openbsd/default.nix50
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/csu.nix23
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/include/package.nix57
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/libc/disable-librebuild.patch12
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/libc/netbsd-make-to-lower.patch16
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/libc/package.nix121
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/lorder.nix21
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/make-rules/netbsd-make-sinclude.patch15
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/make-rules/package.nix35
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/mkDerivation.nix98
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/package.nix3
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/setup-hook.sh21
-rw-r--r--pkgs/os-specific/bsd/openbsd/pkgs/source.nix8
13 files changed, 480 insertions, 0 deletions
diff --git a/pkgs/os-specific/bsd/openbsd/default.nix b/pkgs/os-specific/bsd/openbsd/default.nix
new file mode 100644
index 0000000000000..bfc88f097865f
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/default.nix
@@ -0,0 +1,50 @@
+{
+  lib,
+  makeScopeWithSplicing',
+  generateSplicesForMkScope,
+  buildPackages,
+}:
+
+let
+  otherSplices = generateSplicesForMkScope "openbsd";
+  buildOpenbsd = otherSplices.selfBuildHost;
+in
+
+makeScopeWithSplicing' {
+  inherit otherSplices;
+  f = (
+    self:
+    lib.packagesFromDirectoryRecursive {
+      callPackage = self.callPackage;
+      directory = ./pkgs;
+    }
+    // {
+      libc = self.callPackage ./pkgs/libc/package.nix {
+        inherit (self) csu include;
+        inherit (buildOpenbsd) makeMinimal;
+        inherit (buildPackages.netbsd)
+          install
+          gencat
+          rpcgen
+          tsort
+          ;
+      };
+      makeMinimal = buildPackages.netbsd.makeMinimal.override { inherit (self) make-rules; };
+      mkDerivation = self.callPackage ./pkgs/mkDerivation.nix {
+        inherit (buildPackages.netbsd) install;
+        inherit (buildPackages.buildPackages) rsync;
+      };
+      include = self.callPackage ./pkgs/include/package.nix {
+        inherit (buildOpenbsd) makeMinimal;
+        inherit (buildPackages.netbsd) install rpcgen mtree;
+      };
+      csu = self.callPackage ./pkgs/csu.nix {
+        inherit (self) include;
+        inherit (buildOpenbsd) makeMinimal;
+        inherit (buildPackages.netbsd) install;
+      };
+      make-rules = self.callPackage ./pkgs/make-rules/package.nix { };
+      lorder = self.callPackage ./pkgs/lorder.nix { inherit (buildPackages.netbsd) install; };
+    }
+  );
+}
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/csu.nix b/pkgs/os-specific/bsd/openbsd/pkgs/csu.nix
new file mode 100644
index 0000000000000..03a7180425684
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/csu.nix
@@ -0,0 +1,23 @@
+{
+  lib,
+  mkDerivation,
+  bsdSetupHook,
+  openbsdSetupHook,
+  makeMinimal,
+  install,
+  include,
+}:
+
+mkDerivation {
+  noLibc = true;
+  path = "lib/csu";
+  nativeBuildInputs = [
+    bsdSetupHook
+    openbsdSetupHook
+    makeMinimal
+    install
+  ];
+  buildInputs = [ include ];
+  meta.platforms = lib.platforms.openbsd;
+  extraPaths = [ "libexec/ld.so" ];
+}
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/include/package.nix b/pkgs/os-specific/bsd/openbsd/pkgs/include/package.nix
new file mode 100644
index 0000000000000..481e302065fc4
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/include/package.nix
@@ -0,0 +1,57 @@
+{
+  lib,
+  mkDerivation,
+  makeMinimal,
+  bsdSetupHook,
+  openbsdSetupHook,
+  install,
+  rpcgen,
+  mtree,
+  pax,
+  buildPackages,
+}:
+mkDerivation {
+  path = "include";
+  noCC = true;
+
+  extraPaths = [
+    "lib"
+    #"sys"
+    "sys/arch"
+    # LDIRS from the mmakefile
+    "sys/crypto"
+    "sys/ddb"
+    "sys/dev"
+    "sys/isofs"
+    "sys/miscfs"
+    "sys/msdosfs"
+    "sys/net"
+    "sys/netinet"
+    "sys/netinet6"
+    "sys/netmpls"
+    "sys/net80211"
+    "sys/nfs"
+    "sys/ntfs"
+    "sys/scsi"
+    "sys/sys"
+    "sys/ufs"
+    "sys/uvm"
+  ];
+
+  nativeBuildInputs = [
+    bsdSetupHook
+    install
+    makeMinimal
+    mtree
+    openbsdSetupHook
+    pax
+    rpcgen
+  ];
+
+  makeFlags = [
+    "RPCGEN_CPP=${buildPackages.stdenv.cc.cc}/bin/cpp"
+    "-B"
+  ];
+
+  headersOnly = true;
+}
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/libc/disable-librebuild.patch b/pkgs/os-specific/bsd/openbsd/pkgs/libc/disable-librebuild.patch
new file mode 100644
index 0000000000000..58633861a826f
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/libc/disable-librebuild.patch
@@ -0,0 +1,12 @@
+diff --git a/lib/libc/Makefile b/lib/libc/Makefile
+index 4bb4b67fcbb..1c8a8e08e60 100644
+--- a/lib/libc/Makefile
++++ b/lib/libc/Makefile
+@@ -6,7 +6,6 @@
+ .include <bsd.own.mk>
+
+ LIB=c
+-LIBREBUILD=y
+ CLEANFILES+=tags Symbols.map
+ CFLAGS+=-Wimplicit
+ #CFLAGS+=-Werror
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/libc/netbsd-make-to-lower.patch b/pkgs/os-specific/bsd/openbsd/pkgs/libc/netbsd-make-to-lower.patch
new file mode 100644
index 0000000000000..e8d016ceead5a
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/libc/netbsd-make-to-lower.patch
@@ -0,0 +1,16 @@
+NetBSD's make uses `${variable:tl}` not `${variable:L}`.
+
+diff --git a/lib/libc/Makefile b/lib/libc/Makefile
+index 4bb4b67fcbb..ffb35c196ea 100644
+--- a/lib/libc/Makefile
++++ b/lib/libc/Makefile
+@@ -11,8 +11,8 @@ CLEANFILES+=tags Symbols.map
+ CFLAGS+=-Wimplicit
+ #CFLAGS+=-Werror
+ LDADD=-nostdlib
+-.if ${COMPILER_VERSION:L} == "clang"
++.if ${COMPILER_VERSION:tl} == "clang"
+ LDADD+=-lcompiler_rt
+ .else
+ LDADD+=-lgcc
+ .endif
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/libc/package.nix b/pkgs/os-specific/bsd/openbsd/pkgs/libc/package.nix
new file mode 100644
index 0000000000000..1a6b6d06a1936
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/libc/package.nix
@@ -0,0 +1,121 @@
+{
+  lib,
+  crossLibcStdenv,
+  mkDerivation,
+  bsdSetupHook,
+  openbsdSetupHook,
+  makeMinimal,
+  install,
+  flex,
+  byacc,
+  gencat,
+  rpcgen,
+  csu,
+  include,
+  ctags,
+  tsort,
+  llvmPackages,
+  fetchpatch,
+}:
+
+mkDerivation {
+  noLibc = true;
+  pname = "libc";
+  path = "lib/libc";
+  extraPaths = [
+    "lib/csu/os-note-elf.h"
+    "sys/arch"
+
+    "lib/libm"
+    "lib/libpthread"
+    "lib/librpcsvc"
+    "lib/librpcsvc"
+    "lib/librthread"
+    "lib/libutil"
+  ];
+
+  patches = [
+    ./netbsd-make-to-lower.patch
+    ./disable-librebuild.patch
+    (fetchpatch {
+      url = "https://marc.info/?l=openbsd-tech&m=171575286706032&q=raw";
+      sha256 = "sha256-2fqabJZLUvXUIWe5WZ4NrTOwgQCXqH49Wo0hAPu5lu0=";
+    })
+  ];
+
+  nativeBuildInputs = [
+    bsdSetupHook
+    openbsdSetupHook
+    makeMinimal
+    install
+    flex
+    byacc
+    gencat
+    rpcgen
+    ctags
+    tsort
+  ];
+
+  buildInputs = [
+    include
+    csu
+  ];
+
+  env.NIX_CFLAGS_COMPILE = builtins.toString [
+    "-B${csu}/lib"
+    "-Wno-error"
+  ];
+
+  # Suppress lld >= 16 undefined version errors
+  # https://github.com/freebsd/freebsd-src/commit/2ba84b4bcdd6012e8cfbf8a0d060a4438623a638
+  env.NIX_LDFLAGS = lib.optionalString (
+    crossLibcStdenv.hostPlatform.linker == "lld"
+  ) "--undefined-version";
+
+  makeFlags = [
+    "STRIP=-s" # flag to install, not command
+    "COMPILER_VERSION=clang"
+    "LIBC_TAGS=no"
+  ];
+
+  postInstall = ''
+    symlink_so () {
+      pushd $out/lib
+      ln -s "lib$1".so.* "lib$1.so"
+      popd
+    }
+
+    symlink_so c
+
+    pushd ${include}
+    find . -type d -exec mkdir -p $out/\{} \;
+    find . \( -type f -o -type l \) -exec cp -pr \{} $out/\{} \;
+    popd
+    substituteInPlace $out/include/sys/time.h --replace "defined (_LIBC)" "true"
+
+    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/libm $makeFlags
+    make -C $BSDSRCDIR/lib/libm $makeFlags install
+    symlink_so m
+
+    make -C $BSDSRCDIR/lib/librthread $makeFlags
+    make -C $BSDSRCDIR/lib/librthread $makeFlags install
+    symlink_so pthread
+
+    make -C $BSDSRCDIR/lib/librpcsvc $makeFlags
+    make -C $BSDSRCDIR/lib/librpcsvc $makeFlags install
+    symlink_so rpcsv
+
+    make -C $BSDSRCDIR/lib/libutil $makeFlags
+    make -C $BSDSRCDIR/lib/libutil $makeFlags install
+    symlink_so util
+  '';
+}
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/lorder.nix b/pkgs/os-specific/bsd/openbsd/pkgs/lorder.nix
new file mode 100644
index 0000000000000..c923a84317682
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/lorder.nix
@@ -0,0 +1,21 @@
+{
+  lib,
+  mkDerivation,
+  bsdSetupHook,
+  openbsdSetupHook,
+  makeMinimal,
+  install,
+}:
+
+mkDerivation {
+  noCC = true;
+  path = "usr.bin/lorder";
+  nativeBuildInputs = [
+    bsdSetupHook
+    openbsdSetupHook
+    makeMinimal
+    install
+  ];
+
+  meta.platforms = lib.platforms.unix;
+}
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/make-rules/netbsd-make-sinclude.patch b/pkgs/os-specific/bsd/openbsd/pkgs/make-rules/netbsd-make-sinclude.patch
new file mode 100644
index 0000000000000..daaaff56e9b7d
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/make-rules/netbsd-make-sinclude.patch
@@ -0,0 +1,15 @@
+NetBSD make prefers `.-include` to `sinclude` (without a dot)
+
+diff --git a/share/mk/bsd.dep.mk b/share/mk/bsd.dep.mk
+index 7019adb57f7..277064eb5c2 100644
+--- a/share/mk/bsd.dep.mk
++++ b/share/mk/bsd.dep.mk
+@@ -11,7 +11,7 @@ depend:
+ # catch22: don't include potentially bogus files we are going to clean
+ .  if !(make(clean) || make(cleandir) || make(obj))
+ .    for o in ${DEPS}
+-       sinclude $o
++.      -include "$o"
+ .    endfor
+ .  endif
+ .endif
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/make-rules/package.nix b/pkgs/os-specific/bsd/openbsd/pkgs/make-rules/package.nix
new file mode 100644
index 0000000000000..fefa1136eb76d
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/make-rules/package.nix
@@ -0,0 +1,35 @@
+{
+  fetchpatch,
+  lib,
+  mkDerivation,
+}:
+
+mkDerivation {
+  path = "share/mk";
+  noCC = true;
+
+  buildInputs = [ ];
+  nativeBuildInputs = [ ];
+
+  dontBuild = true;
+
+  patches = [
+    (fetchpatch {
+      url = "https://marc.info/?l=openbsd-tech&m=171575284906018&q=raw";
+      sha256 = "sha256-bigxJGbaf9mCmFXxLVzQpnUUaEMMDfF3eZkTXVzd6B8=";
+    })
+    ./netbsd-make-sinclude.patch
+  ];
+
+  postPatch = ''
+    sed -i -E \
+      -e 's|/usr/lib|\$\{LIBDIR\}|' \
+      share/mk/bsd.prog.mk
+  '';
+
+  installPhase = ''
+    cp -r share/mk $out
+  '';
+
+  meta.platforms = lib.platforms.unix;
+}
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/mkDerivation.nix b/pkgs/os-specific/bsd/openbsd/pkgs/mkDerivation.nix
new file mode 100644
index 0000000000000..371c6c58b91fb
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/mkDerivation.nix
@@ -0,0 +1,98 @@
+{
+  lib,
+  stdenv,
+  stdenvNoCC,
+  crossLibcStdenv,
+  runCommand,
+  rsync,
+  source,
+  bsdSetupHook,
+  openbsdSetupHook,
+  makeMinimal,
+  install,
+}:
+
+lib.makeOverridable (
+  attrs:
+  let
+    stdenv' =
+      if attrs.noCC or false then
+        stdenvNoCC
+      else if attrs.noLibc or false then
+        crossLibcStdenv
+      else
+        stdenv;
+  in
+  stdenv'.mkDerivation (
+    rec {
+      pname = "${attrs.pname or (baseNameOf attrs.path)}-openbsd";
+      version = "0";
+      src = runCommand "${pname}-filtered-src" { nativeBuildInputs = [ rsync ]; } ''
+        for p in ${lib.concatStringsSep " " ([ attrs.path ] ++ attrs.extraPaths or [ ])}; do
+          set -x
+          path="$out/$p"
+          mkdir -p "$(dirname "$path")"
+          src_path="${source}/$p"
+          if [[ -d "$src_path" ]]; then src_path+=/; fi
+          rsync --chmod="+w" -r "$src_path" "$path"
+          set +x
+        done
+      '';
+
+      extraPaths = [ ];
+
+      nativeBuildInputs = [
+        bsdSetupHook
+        openbsdSetupHook
+        makeMinimal
+        install
+      ];
+
+      HOST_SH = stdenv'.shell;
+
+      makeFlags = [
+        "STRIP=-s" # flag to install, not command
+        "-B"
+      ];
+
+      MACHINE_ARCH =
+        {
+          # amd64 not x86_64 for this on unlike NetBSD
+          x86_64 = "amd64";
+          aarch64 = "arm64";
+          i486 = "i386";
+          i586 = "i386";
+          i686 = "i386";
+        }
+        .${stdenv'.hostPlatform.parsed.cpu.name} or stdenv'.hostPlatform.parsed.cpu.name;
+
+      MACHINE = MACHINE_ARCH;
+
+      MACHINE_CPU = MACHINE_ARCH;
+
+      MACHINE_CPUARCH = MACHINE_ARCH;
+
+      COMPONENT_PATH = attrs.path or null;
+
+      strictDeps = true;
+
+      meta = with lib; {
+        maintainers = with maintainers; [ ericson2314 ];
+        platforms = platforms.openbsd;
+        license = licenses.bsd2;
+      };
+    }
+    // lib.optionalAttrs stdenv'.hasCC {
+      # TODO should CC wrapper set this?
+      CPP = "${stdenv'.cc.targetPrefix}cpp";
+
+      # Since STRIP in `makeFlags` has to be a flag, not the binary itself
+      STRIPBIN = "${stdenv'.cc.bintools.targetPrefix}strip";
+    }
+    // lib.optionalAttrs (attrs.headersOnly or false) {
+      installPhase = "includesPhase";
+      dontBuild = true;
+    }
+    // attrs
+  )
+)
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/package.nix b/pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/package.nix
new file mode 100644
index 0000000000000..61147954812fd
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/package.nix
@@ -0,0 +1,3 @@
+{ makeSetupHook }:
+
+makeSetupHook { name = "openbsd-setup-hook"; } ./setup-hook.sh
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/setup-hook.sh b/pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/setup-hook.sh
new file mode 100644
index 0000000000000..50e79bc2928a9
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/openbsdSetupHook/setup-hook.sh
@@ -0,0 +1,21 @@
+addOpenBSDMakeFlags() {
+  makeFlags="INCSDIR=${!outputDev}/include $makeFlags"
+  makeFlags="MANDIR=${!outputMan}/share/man $makeFlags"
+}
+
+fixOpenBSDInstallDirs() {
+  find "$BSDSRCDIR" -name Makefile -exec \
+    sed -i -E \
+      -e 's|/usr/include|${INCSDIR}|' \
+      -e 's|/usr/bin|${BINDIR}|' \
+      -e 's|/usr/lib|${LIBDIR}|' \
+      {} \;
+}
+
+setBinownBingrp() {
+  export BINOWN=$(id -u)
+  export BINGRP=$(id -g)
+}
+
+preConfigureHooks+=(addOpenBSDMakeFlags)
+postPatchHooks+=(fixOpenBSDInstallDirs setBinownBingrp)
diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/source.nix b/pkgs/os-specific/bsd/openbsd/pkgs/source.nix
new file mode 100644
index 0000000000000..359c3f2fbc919
--- /dev/null
+++ b/pkgs/os-specific/bsd/openbsd/pkgs/source.nix
@@ -0,0 +1,8 @@
+{ fetchcvs }:
+
+fetchcvs {
+  cvsRoot = "anoncvs@anoncvs.fr.openbsd.org/cvs";
+  module = "src";
+  tag = "OPENBSD_7_5";
+  sha256 = "sha256-hzdATew6h/FQV72SWtg3YvUXdPoGjm2SoUS7m3c3fSU=";
+}