Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
914 changes: 46 additions & 868 deletions pkgs/os-specific/bsd/freebsd/default.nix

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions pkgs/os-specific/bsd/freebsd/lib/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ version }:

{
inherit version;

mkBsdArch = stdenv': {
x86_64 = "amd64";
aarch64 = "arm64";
i486 = "i386";
i586 = "i386";
i686 = "i386";
}.${stdenv'.hostPlatform.parsed.cpu.name}
or stdenv'.hostPlatform.parsed.cpu.name;

install-wrapper = builtins.readFile ./install-wrapper.sh;
}
30 changes: 30 additions & 0 deletions pkgs/os-specific/bsd/freebsd/lib/install-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
set -eu

args=()
declare -i path_args=0

while (( $# )); do
if (( $# == 1 )); then
if (( path_args > 1)) || [[ "$1" = */ ]]; then
mkdir -p "$1"
else
mkdir -p "$(dirname "$1")"
fi
fi
case $1 in
-C) ;;
-o | -g) shift ;;
-s) ;;
-m | -l)
# handle next arg so not counted as path arg
args+=("$1" "$2")
shift
;;
-*) args+=("$1") ;;
*)
path_args+=1
args+=("$1")
;;
esac
shift
done
7 changes: 7 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/boot-install.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ buildPackages, freebsd-lib }:

# Wrap NetBSD's install
buildPackages.writeShellScriptBin "boot-install" (freebsd-lib.install-wrapper + ''

${buildPackages.netbsd.install}/bin/xinstall "''${args[@]}"
'')
135 changes: 135 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/compat/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
{ lib, stdenv, mkDerivation
, bsdSetupHook, freebsdSetupHook
, makeMinimal, boot-install
, which
, freebsd-lib
, expat, zlib,
}:

let
inherit (freebsd-lib) mkBsdArch;
in

mkDerivation rec {
pname = "compat";
path = "tools/build";
extraPaths = [
"lib/libc/db"
"lib/libc/stdlib" # getopt
"lib/libc/gen" # getcap
"lib/libc/locale" # rpmatch
] ++ lib.optionals stdenv.hostPlatform.isLinux [
"lib/libc/string" # strlcpy
"lib/libutil"
] ++ [
"contrib/libc-pwcache"
"contrib/libc-vis"
"sys/libkern"
"sys/kern/subr_capability.c"

# Take only individual headers, or else we will clobber native libc, etc.

"sys/rpc/types.h"

# Listed in Makekfile as INC
"include/mpool.h"
"include/ndbm.h"
"include/err.h"
"include/stringlist.h"
"include/a.out.h"
"include/nlist.h"
"include/db.h"
"include/getopt.h"
"include/nl_types.h"
"include/elf.h"
"sys/sys/ctf.h"

# Listed in Makekfile as SYSINC

"sys/sys/capsicum.h"
"sys/sys/caprights.h"
"sys/sys/imgact_aout.h"
"sys/sys/nlist_aout.h"
"sys/sys/nv.h"
"sys/sys/dnv.h"
"sys/sys/cnv.h"

"sys/sys/elf32.h"
"sys/sys/elf64.h"
"sys/sys/elf_common.h"
"sys/sys/elf_generic.h"
"sys/${mkBsdArch stdenv}/include"
] ++ lib.optionals stdenv.hostPlatform.isx86 [
"sys/x86/include"
] ++ [

"sys/sys/queue.h"
"sys/sys/md5.h"
"sys/sys/sbuf.h"
"sys/sys/tree.h"
"sys/sys/font.h"
"sys/sys/consio.h"
"sys/sys/fnv_hash.h"

"sys/crypto/chacha20/_chacha.h"
"sys/crypto/chacha20/chacha.h"
# included too, despite ".c"
"sys/crypto/chacha20/chacha.c"

"sys/fs"
"sys/ufs"
"sys/sys/disk"

"lib/libcapsicum"
"lib/libcasper"
];

patches = [
./compat-install-dirs.patch
./compat-fix-typedefs-locations.patch
];

preBuild = ''
NIX_CFLAGS_COMPILE+=' -I../../include -I../../sys'

cp ../../sys/${mkBsdArch stdenv}/include/elf.h ../../sys/sys
cp ../../sys/${mkBsdArch stdenv}/include/elf.h ../../sys/sys/${mkBsdArch stdenv}
'' + lib.optionalString stdenv.hostPlatform.isx86 ''
cp ../../sys/x86/include/elf.h ../../sys/x86
'';

setupHooks = [
../../../../../build-support/setup-hooks/role.bash
./compat-setup-hook.sh
];

# This one has an ifdefed `#include_next` that makes it annoying.
postInstall = ''
rm ''${!outputDev}/0-include/libelf.h
'';

nativeBuildInputs = [
bsdSetupHook freebsdSetupHook
makeMinimal
boot-install

which
];
buildInputs = [ expat zlib ];

makeFlags = [
"STRIP=-s" # flag to install, not command
"MK_WERROR=no"
"HOST_INCLUDE_ROOT=${lib.getDev stdenv.cc.libc}/include"
"INSTALL=boot-install"
];

preIncludes = ''
mkdir -p $out/{0,1}-include
cp --no-preserve=mode -r cross-build/include/common/* $out/0-include
'' + lib.optionalString stdenv.hostPlatform.isLinux ''
cp --no-preserve=mode -r cross-build/include/linux/* $out/1-include
'' + lib.optionalString stdenv.hostPlatform.isDarwin ''
cp --no-preserve=mode -r cross-build/include/darwin/* $out/1-include
'';
}
17 changes: 17 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/config.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ mkDerivation
, bsdSetupHook, freebsdSetupHook
, makeMinimal, install, mandoc, groff
, flex, byacc, file2c
, compatIfNeeded, libnv, libsbuf
}:

mkDerivation {
path = "usr.sbin/config";
nativeBuildInputs = [
bsdSetupHook freebsdSetupHook
makeMinimal install mandoc groff

flex byacc file2c
];
buildInputs = compatIfNeeded ++ [ libnv libsbuf ];
}
25 changes: 25 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/csu.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ lib, mkDerivation
, bsdSetupHook, freebsdSetupHook
, makeMinimal
, install
, flex, byacc, gencat
, include
}:

mkDerivation {
path = "lib/csu";
extraPaths = [
"lib/Makefile.inc"
"lib/libc/include/libc_private.h"
];
nativeBuildInputs = [
bsdSetupHook freebsdSetupHook
makeMinimal
install

flex byacc gencat
];
buildInputs = [ include ];
MK_TESTS = "no";
meta.platforms = lib.platforms.freebsd;
}
28 changes: 28 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/ctfconvert.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ lib, stdenv, mkDerivation
, bsdSetupHook, freebsdSetupHook
, makeMinimal, install, mandoc, groff
, compatIfNeeded, libelf, libdwarf, zlib, libspl
}:

mkDerivation {
path = "cddl/usr.bin/ctfconvert";
extraPaths = [
"cddl/compat/opensolaris"
"cddl/contrib/opensolaris"
"sys/cddl/compat/opensolaris"
"sys/cddl/contrib/opensolaris"
"sys/contrib/openzfs"
];
OPENSOLARIS_USR_DISTDIR = "$(SRCTOP)/cddl/contrib/opensolaris";
OPENSOLARIS_SYS_DISTDIR = "$(SRCTOP)/sys/cddl/contrib/opensolaris";
nativeBuildInputs = [
bsdSetupHook freebsdSetupHook
makeMinimal install mandoc groff

# flex byacc file2c
];
buildInputs = compatIfNeeded ++ [
libelf libdwarf zlib libspl
];
meta.license = lib.licenses.cddl;
}
6 changes: 6 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/file2c.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ mkDerivation }:

mkDerivation {
path = "usr.bin/file2c";
MK_TESTS = "no";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ makeSetupHook }:

makeSetupHook {
name = "freebsd-setup-hook";
} ./setup-hook.sh
5 changes: 5 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/gencat.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{ mkDerivation }:

mkDerivation {
path = "usr.bin/gencat";
}
56 changes: 56 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/include/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{ lib, mkDerivation
, buildPackages
, bsdSetupHook, freebsdSetupHook
, makeMinimal
, install
, mandoc, groff, rsync /*, nbperf*/, rpcgen
}:

mkDerivation {
path = "include";

extraPaths = [
"contrib/libc-vis"
"etc/mtree/BSD.include.dist"
"sys"
];

nativeBuildInputs = [
bsdSetupHook freebsdSetupHook
makeMinimal
install
mandoc groff rsync /*nbperf*/ rpcgen

# HACK use NetBSD's for now
buildPackages.netbsd.mtree
];

patches = [
./no-perms-BSD.include.dist.patch
];

# 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}_' \
{} \;
'';

makeFlags = [
"RPCGEN_CPP=${buildPackages.stdenv.cc.cc}/bin/cpp"
];

# multiple header dirs, see above
postConfigure = ''
makeFlags=''${makeFlags/INCSDIR/INCSDIR0}
'';

headersOnly = true;

MK_HESIOD = "yes";

meta.platforms = lib.platforms.freebsd;
}
41 changes: 41 additions & 0 deletions pkgs/os-specific/bsd/freebsd/pkgs/install.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{ lib, stdenv, mkDerivation, writeShellScript
, freebsd-lib
, mtree
, bsdSetupHook, freebsdSetupHook
, makeMinimal, mandoc, groff
, boot-install, install
, compatIfNeeded, libmd, libnetbsd
}:

# 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" (freebsd-lib.install-wrapper + ''

@out@/bin/xinstall "''${args[@]}"
'');
in mkDerivation {
path = "usr.bin/xinstall";
extraPaths = [ mtree.path ];
nativeBuildInputs = [
bsdSetupHook freebsdSetupHook
makeMinimal mandoc groff
(if stdenv.hostPlatform == stdenv.buildPlatform
then boot-install
else install)
];
skipIncludesPhase = true;
buildInputs = compatIfNeeded ++ [ libmd libnetbsd ];
makeFlags = [
"STRIP=-s" # flag to install, not command
"MK_WERROR=no"
"TESTSDIR=${builtins.placeholder "test"}"
] ++ lib.optional (stdenv.hostPlatform == stdenv.buildPlatform) "INSTALL=boot-install";
postInstall = ''
install -D -m 0550 ${binstall} $out/bin/binstall
substituteInPlace $out/bin/binstall --subst-var out
mv $out/bin/install $out/bin/xinstall
ln -s ./binstall $out/bin/install
'';
outputs = [ "out" "man" "test" ];
}
Loading