diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/err.h b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/err.h new file mode 100644 index 000000000000..8ff38a621743 --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/err.h @@ -0,0 +1,30 @@ +#pragma once +#include_next + +#include +#include +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; +} diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/fcntl.h b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/fcntl.h new file mode 100644 index 000000000000..d8bb61a2291d --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/fcntl.h @@ -0,0 +1,6 @@ +#pragma once +#include_next + +// Linux doesn't let you lock during open, make these do nothing +#define O_EXLOCK 0 +#define O_SHLOCK 0 diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/cdefs.h b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/cdefs.h new file mode 100644 index 000000000000..ea433160ad7c --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/cdefs.h @@ -0,0 +1,4 @@ +#include_next + +#define __packed __attribute__((__packed__)) +#define __aligned(x) __attribute__((__aligned__(x))) diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/dirent.h b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/dirent.h new file mode 100644 index 000000000000..d66bbdf7b613 --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/dirent.h @@ -0,0 +1 @@ +#include diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/endian.h b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/endian.h new file mode 100644 index 000000000000..9abc15484c51 --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/endian.h @@ -0,0 +1,2 @@ +// Seems to be the only header for htonl +#include diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/types.h b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/types.h new file mode 100644 index 000000000000..dc2578a8a1bb --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/sys/types.h @@ -0,0 +1,10 @@ +#include_next + +// for makedev, major, minor +#include + +// For htonl, htons, etc. +#include + +// for uint32_t etc. +#include diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/unistd.h b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/unistd.h new file mode 100644 index 000000000000..a52d202801f9 --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/unistd.h @@ -0,0 +1,8 @@ +#pragma once + +#include_next + +// 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; } diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/util.h b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/util.h new file mode 100644 index 000000000000..a12c43b15a9e --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/compat/include/util.h @@ -0,0 +1 @@ +#include diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/compat/package.nix b/pkgs/os-specific/bsd/openbsd/pkgs/compat/package.nix new file mode 100644 index 000000000000..69d457a180d8 --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/compat/package.nix @@ -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 + '' diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/compatHook/package.nix b/pkgs/os-specific/bsd/openbsd/pkgs/compatHook/package.nix new file mode 100644 index 000000000000..3678b60f658b --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/compatHook/package.nix @@ -0,0 +1,13 @@ +{ + stdenv, + makeSetupHook, + compat, +}: + +makeSetupHook { + name = "openbsd-compat-hook"; + substitutions = { + inherit compat; + inherit (stdenv.cc) suffixSalt; + }; +} ./setup-hook.sh diff --git a/pkgs/os-specific/bsd/openbsd/pkgs/compatHook/setup-hook.sh b/pkgs/os-specific/bsd/openbsd/pkgs/compatHook/setup-hook.sh new file mode 100644 index 000000000000..af70cb4bcc8a --- /dev/null +++ b/pkgs/os-specific/bsd/openbsd/pkgs/compatHook/setup-hook.sh @@ -0,0 +1,5 @@ +useOpenBSDCompat () { + export NIX_CFLAGS_COMPILE_@suffixSalt@+="-I@compat@/include" +} + +postHooks+=(useOpenBSDCompat)