mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-21 14:32:59 +00:00
openbsd.sys (OpenBSD kernel): init (#353935)
This commit is contained in:
commit
63de88ed5f
32
pkgs/os-specific/bsd/openbsd/pkgs/boot-config.nix
Normal file
32
pkgs/os-specific/bsd/openbsd/pkgs/boot-config.nix
Normal file
@ -0,0 +1,32 @@
|
||||
{
|
||||
mkDerivation,
|
||||
lib,
|
||||
flex,
|
||||
byacc,
|
||||
compatHook,
|
||||
}:
|
||||
mkDerivation {
|
||||
path = "usr.sbin/config";
|
||||
|
||||
extraNativeBuildInputs = [
|
||||
flex
|
||||
byacc
|
||||
compatHook
|
||||
];
|
||||
|
||||
postPatch = ''
|
||||
rm $BSDSRCDIR/usr.sbin/config/ukc.c
|
||||
rm $BSDSRCDIR/usr.sbin/config/ukcutil.c
|
||||
rm $BSDSRCDIR/usr.sbin/config/cmd.c
|
||||
rm $BSDSRCDIR/usr.sbin/config/exec_elf.c
|
||||
'';
|
||||
|
||||
buildPhase = ''
|
||||
for f in *.l; do flex $f; done
|
||||
for f in *.y; do yacc -H ''${f%.y}.h $f; done
|
||||
for f in *.c; do $CC -I$TMP/include -DMAKE_BOOTSTRAP -c $f; done
|
||||
$CC *.o -o config
|
||||
'';
|
||||
|
||||
meta.platforms = lib.platforms.linux;
|
||||
}
|
25
pkgs/os-specific/bsd/openbsd/pkgs/boot-ctags.nix
Normal file
25
pkgs/os-specific/bsd/openbsd/pkgs/boot-ctags.nix
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
mkDerivation,
|
||||
lib,
|
||||
flex,
|
||||
byacc,
|
||||
compatHook,
|
||||
}:
|
||||
mkDerivation {
|
||||
path = "usr.bin/ctags";
|
||||
|
||||
extraNativeBuildInputs = [
|
||||
flex
|
||||
byacc
|
||||
compatHook
|
||||
];
|
||||
|
||||
buildPhase = ''
|
||||
for f in *.l; do flex $f; done
|
||||
for f in *.y; do yacc -H ''${f%.y}.h $f; done
|
||||
for f in *.c; do $CC -I$TMP/include -DMAKE_BOOTSTRAP -c $f; done
|
||||
$CC *.o -o ctags
|
||||
'';
|
||||
|
||||
meta.platforms = lib.platforms.linux;
|
||||
}
|
30
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/err.h
Normal file
30
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/err.h
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include_next <err.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
static inline void __attribute__((__format__(printf, 3, 4)))
|
||||
errc(int eval, int code, const char *fmt, ...) {
|
||||
// verr uses the error code from errno
|
||||
// No need to keep the old value since this is noreturn anyway
|
||||
errno = code;
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
verr(eval, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
static inline void __attribute__((__format__(printf, 2, 3)))
|
||||
warnc(int code, const char *fmt, ...) {
|
||||
// verr uses the error code from errno
|
||||
int old_errno = errno;
|
||||
errno = code;
|
||||
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vwarn(fmt, args);
|
||||
va_end(args);
|
||||
|
||||
errno = old_errno;
|
||||
}
|
6
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/fcntl.h
Normal file
6
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/fcntl.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include_next <fcntl.h>
|
||||
|
||||
// Linux doesn't let you lock during open, make these do nothing
|
||||
#define O_EXLOCK 0
|
||||
#define O_SHLOCK 0
|
@ -0,0 +1,4 @@
|
||||
#include_next <sys/cdefs.h>
|
||||
|
||||
#define __packed __attribute__((__packed__))
|
||||
#define __aligned(x) __attribute__((__aligned__(x)))
|
@ -0,0 +1 @@
|
||||
#include <dirent.h>
|
@ -0,0 +1,2 @@
|
||||
// Seems to be the only header for htonl
|
||||
#include <netinet/in.h>
|
10
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/types.h
Normal file
10
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/types.h
Normal file
@ -0,0 +1,10 @@
|
||||
#include_next <sys/types.h>
|
||||
|
||||
// for makedev, major, minor
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
// For htonl, htons, etc.
|
||||
#include <arpa/inet.h>
|
||||
|
||||
// for uint32_t etc.
|
||||
#include <stdint.h>
|
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include_next <unistd.h>
|
||||
|
||||
// Reimplementing pledge and unvail with seccomp would be a pain,
|
||||
// so do nothing but claim they succeeded
|
||||
static int pledge(const char *, const char *) { return 0; }
|
||||
static int unveil(const char *, const char *) { return 0; }
|
1
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/util.h
Normal file
1
pkgs/os-specific/bsd/openbsd/pkgs/compat/include/util.h
Normal file
@ -0,0 +1 @@
|
||||
#include <sys/types.h>
|
16
pkgs/os-specific/bsd/openbsd/pkgs/compat/package.nix
Normal file
16
pkgs/os-specific/bsd/openbsd/pkgs/compat/package.nix
Normal file
@ -0,0 +1,16 @@
|
||||
{ runCommand, lib }:
|
||||
|
||||
runCommand "openbsd-compat"
|
||||
{
|
||||
include = ./include;
|
||||
|
||||
meta = with lib; {
|
||||
description = "A header-only library for running OpenBSD software on Linux";
|
||||
platforms = lib.platforms.linux;
|
||||
maintainers = with lib.maintainers; [ artemist ];
|
||||
};
|
||||
}
|
||||
''
|
||||
mkdir -p $out
|
||||
cp -R $include $out/include
|
||||
''
|
13
pkgs/os-specific/bsd/openbsd/pkgs/compatHook/package.nix
Normal file
13
pkgs/os-specific/bsd/openbsd/pkgs/compatHook/package.nix
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
stdenv,
|
||||
makeSetupHook,
|
||||
compat,
|
||||
}:
|
||||
|
||||
makeSetupHook {
|
||||
name = "openbsd-compat-hook";
|
||||
substitutions = {
|
||||
inherit compat;
|
||||
inherit (stdenv.cc) suffixSalt;
|
||||
};
|
||||
} ./setup-hook.sh
|
@ -0,0 +1,5 @@
|
||||
useOpenBSDCompat () {
|
||||
export NIX_CFLAGS_COMPILE_@suffixSalt@+="-I@compat@/include"
|
||||
}
|
||||
|
||||
postHooks+=(useOpenBSDCompat)
|
@ -34,6 +34,8 @@ mkDerivation {
|
||||
sed -i -E \
|
||||
-e 's|/usr/lib|\$\{LIBDIR\}|' \
|
||||
share/mk/bsd.prog.mk
|
||||
|
||||
substituteInPlace share/mk/bsd.obj.mk --replace-fail /bin/pwd pwd
|
||||
'';
|
||||
|
||||
installPhase = ''
|
||||
|
@ -53,7 +53,7 @@ lib.makeOverridable (
|
||||
install
|
||||
tsort
|
||||
lorder
|
||||
];
|
||||
] ++ (attrs.extraNativeBuildInputs or [ ]);
|
||||
|
||||
HOST_SH = stdenv'.shell;
|
||||
|
||||
@ -93,6 +93,6 @@ lib.makeOverridable (
|
||||
dontBuild = true;
|
||||
}
|
||||
// lib.optionalAttrs stdenv'.hostPlatform.isStatic { NOLIBSHARED = true; }
|
||||
// attrs
|
||||
// (builtins.removeAttrs attrs [ "extraNativeBuildInputs" ])
|
||||
)
|
||||
)
|
||||
|
66
pkgs/os-specific/bsd/openbsd/pkgs/sys.nix
Normal file
66
pkgs/os-specific/bsd/openbsd/pkgs/sys.nix
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
mkDerivation,
|
||||
boot-config,
|
||||
pkgsBuildTarget,
|
||||
baseConfig ? "GENERIC",
|
||||
}:
|
||||
mkDerivation {
|
||||
path = "sys/arch/amd64";
|
||||
pname = "sys";
|
||||
extraPaths = [ "sys" ];
|
||||
noLibc = true;
|
||||
|
||||
extraNativeBuildInputs = [
|
||||
boot-config
|
||||
];
|
||||
|
||||
postPatch =
|
||||
# The in-kernel debugger (DDB) requires compiler flags not supported by clang, disable it
|
||||
''
|
||||
sed -E -i -e '/DDB/d' $BSDSRCDIR/sys/conf/GENERIC
|
||||
sed -E -i -e '/pseudo-device\tdt/d' $BSDSRCDIR/sys/arch/amd64/conf/GENERIC
|
||||
''
|
||||
+
|
||||
# Clang flags compatibility
|
||||
''
|
||||
find $BSDSRCDIR -name 'Makefile*' -exec sed -E -i -e 's/-fno-ret-protector/-fno-stack-protector/g' -e 's/-nopie/-no-pie/g' {} +
|
||||
sed -E -i -e 's_^\tinstall.*$_\tinstall bsd ''${out}/bsd_' -e s/update-link// $BSDSRCDIR/sys/arch/*/conf/Makefile.*
|
||||
''
|
||||
+
|
||||
# Remove randomness in build
|
||||
''
|
||||
sed -E -i -e 's/^PAGE_SIZE=.*$/PAGE_SIZE=4096/g' -e '/^random_uniform/a echo 0; return 0;' $BSDSRCDIR/sys/conf/makegap.sh
|
||||
sed -E -i -e 's/^v=.*$/v=0 u=nixpkgs h=nixpkgs t=`date -d @1`/g' $BSDSRCDIR/sys/conf/newvers.sh
|
||||
'';
|
||||
|
||||
postConfigure = ''
|
||||
export BSDOBJDIR=$TMP/obj
|
||||
mkdir $BSDOBJDIR
|
||||
make obj
|
||||
|
||||
cd conf
|
||||
config ${baseConfig}
|
||||
cd -
|
||||
'';
|
||||
|
||||
preBuild =
|
||||
# A lot of files insist on calling unprefixed GNU `ld` and `objdump`.
|
||||
# It's easier to add them to PATH than patch and substitute.
|
||||
''
|
||||
mkdir $TMP/bin
|
||||
export PATH=$TMP/bin:$PATH
|
||||
ln -s ${pkgsBuildTarget.binutils}/bin/${pkgsBuildTarget.binutils.targetPrefix}objdump $TMP/bin/objdump
|
||||
ln -s ${pkgsBuildTarget.binutils}/bin/${pkgsBuildTarget.binutils.targetPrefix}ld $TMP/bin/ld
|
||||
''
|
||||
+
|
||||
# The Makefile claims it needs includes, but it really doesn't.
|
||||
# Tell it includes aren't real and can't hurt it.
|
||||
''
|
||||
cd compile/${baseConfig}/obj
|
||||
echo 'includes:' >>Makefile
|
||||
'';
|
||||
|
||||
# stand is in a separate package
|
||||
env.SKIPDIR = "stand";
|
||||
env.NIX_CFLAGS_COMPILE = "-Wno-unused-command-line-argument -Wno-visibility";
|
||||
}
|
Loading…
Reference in New Issue
Block a user