Skip to content

Commit 61c678f

Browse files
authored
Merge pull request #311836 from obsidiansystems/aa-openbsd-1
openbsd: init at 7.5
2 parents a36653d + 888dee4 commit 61c678f

File tree

26 files changed

+604
-65
lines changed

26 files changed

+604
-65
lines changed

lib/systems/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ let
9393
else if final.isAndroid then "bionic"
9494
else if final.isLinux /* default */ then "glibc"
9595
else if final.isFreeBSD then "fblibc"
96+
else if final.isOpenBSD then "oblibc"
9697
else if final.isNetBSD then "nblibc"
9798
else if final.isAvr then "avrlibc"
9899
else if final.isGhcjs then null

lib/systems/examples.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ rec {
342342
useLLVM = true;
343343
};
344344

345+
x86_64-openbsd = {
346+
config = "x86_64-unknown-openbsd";
347+
useLLVM = true;
348+
};
349+
345350
#
346351
# WASM
347352
#

lib/systems/parse.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ rec {
469469
elem (elemAt l 2) [ "wasi" "redox" "mmixware" "ghcjs" "mingw32" ] ||
470470
hasPrefix "freebsd" (elemAt l 2) ||
471471
hasPrefix "netbsd" (elemAt l 2) ||
472+
hasPrefix "openbsd" (elemAt l 2) ||
472473
hasPrefix "genode" (elemAt l 2)
473474
then {
474475
cpu = elemAt l 0;

pkgs/development/compilers/llvm/18/default.nix

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{ lowPrio, newScope, pkgs, lib, stdenv, cmake, ninja
22
, preLibcCrossHeaders
3-
, libxml2, python3, fetchFromGitHub, substituteAll, overrideCC, wrapCCWith, wrapBintoolsWith
3+
, libxml2, python3, fetchFromGitHub, fetchpatch, substituteAll, overrideCC, wrapCCWith, wrapBintoolsWith
44
, buildLlvmTools # tools, but from the previous stage, for cross
55
, targetLlvmLibraries # libraries, but from the next stage, for cross
66
, targetLlvm
@@ -146,6 +146,11 @@ in let
146146
# https://reviews.llvm.org/D51899
147147
./clang/gnu-install-dirs.patch
148148
../common/clang/add-nostdlibinc-flag.patch
149+
(fetchpatch {
150+
url = "https://github.com/llvm/llvm-project/commit/48c1364200b5649dda2f9ccbe382b0bd908b99de.patch";
151+
sha256 = "sha256-beSydky0P/06YDLk0GJDtcREpMcU2FspxuYU6EnQGfA=";
152+
stripLen = 1;
153+
})
149154
(substituteAll {
150155
src = ../common/clang/clang-at-least-16-LLVMgold-path.patch;
151156
libllvmLibdir = "${tools.libllvm.lib}/lib";
@@ -391,7 +396,12 @@ in let
391396
# so: we use the clang from this LLVM package set instead of the regular
392397
# stdenv's compiler.
393398
libcxx = callPackage ../common/libcxx {
394-
patches = lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [
399+
patches = [
400+
(fetchpatch {
401+
url = "https://github.com/llvm/llvm-project/commit/1118c2e05e67a36ed8ca250524525cdb66a55256.patch";
402+
sha256 = "sha256-2lDO9UsglvYAxDG3/iTXqGVHn1Hq3O7wtkCUb9I/Buc=";
403+
})
404+
] ++ lib.optionals (stdenv.isDarwin && lib.versionOlder stdenv.hostPlatform.darwinMinVersion "10.13") [
395405
# https://github.com/llvm/llvm-project/issues/64226
396406
./libcxx/0001-darwin-10.12-mbstate_t-fix.patch
397407
];

pkgs/development/compilers/llvm/common/compiler-rt/default.nix

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@
1414
, libllvm
1515
, linuxHeaders
1616
, libxcrypt
17+
18+
# Some platforms have switched to using compiler-rt, but still want a
19+
# libgcc.a for ABI compat purposes. The use case would be old code that
20+
# expects to link `-lgcc` but doesn't care exactly what its contents
21+
# are, so long as it provides some builtins.
1722
, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD
23+
24+
# In recent releases, the compiler-rt build seems to produce
25+
# many `libclang_rt*` libraries, but not a single unified
26+
# `libcompiler_rt` library, at least under certain configurations. Some
27+
# platforms stil expect this, however, so we symlink one into place.
28+
, forceLinkCompilerRt ? stdenv.hostPlatform.isOpenBSD
1829
}:
1930

2031
let
@@ -149,7 +160,9 @@ stdenv.mkDerivation ({
149160
ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o
150161
ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o
151162
'' + lib.optionalString doFakeLibgcc ''
152-
ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a
163+
ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libgcc.a
164+
'' + lib.optionalString forceLinkCompilerRt ''
165+
ln -s $out/lib/*/libclang_rt.builtins-*.a $out/lib/libcompiler_rt.a
153166
'';
154167

155168
meta = llvm_meta // {

pkgs/development/compilers/llvm/common/libcxx/default.nix

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ let
9393

9494
cmakeFlags = [
9595
"-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}"
96-
] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [
97-
# libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib,
98-
# but that does not appear to be the case for example when building
99-
# pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc).
100-
"-DCMAKE_EXE_LINKER_FLAGS=-nostdlib"
101-
"-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib"
10296
] ++ lib.optionals stdenv.hostPlatform.isWasm [
10397
"-DCMAKE_C_COMPILER_WORKS=ON"
10498
"-DCMAKE_CXX_COMPILER_WORKS=ON"

pkgs/os-specific/bsd/freebsd/lib/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
}
1515
.${stdenv'.hostPlatform.parsed.cpu.name} or stdenv'.hostPlatform.parsed.cpu.name;
1616

17-
install-wrapper = builtins.readFile ./install-wrapper.sh;
17+
install-wrapper = builtins.readFile ../../lib/install-wrapper.sh;
1818
}

pkgs/os-specific/bsd/netbsd/pkgs/install/package.nix

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
# HACK: to ensure parent directories exist. This emulates GNU
1818
# install’s -D option. No alternative seems to exist in BSD install.
1919
let
20-
binstall = writeShellScript "binstall" ''
21-
set -eu
22-
for last in "$@"; do true; done
23-
mkdir -p $(dirname $last)
24-
@out@/bin/xinstall "$@"
25-
'';
20+
binstall = writeShellScript "binstall" (
21+
builtins.readFile ../../../lib/install-wrapper.sh
22+
+ ''
23+
@out@/bin/xinstall "''${args[@]}"
24+
''
25+
);
2626
in
2727
mkDerivation {
2828
path = "usr.bin/xinstall";
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{
2+
lib,
3+
mkDerivation,
4+
fetchNetBSD,
5+
stdenv,
6+
bsdSetupHook,
7+
netbsdSetupHook,
8+
rsync,
9+
}:
10+
11+
mkDerivation {
12+
path = "share/mk";
13+
sha256 = "0w9x77cfnm6zwy40slradzi0ip9gz80x6lk7pvnlxzsr2m5ra5sy";
14+
version = "9.2";
15+
noCC = true;
16+
17+
buildInputs = [ ];
18+
nativeBuildInputs = [
19+
bsdSetupHook
20+
netbsdSetupHook
21+
rsync
22+
];
23+
24+
dontBuild = true;
25+
26+
postPatch =
27+
''
28+
substituteInPlace $BSDSRCDIR/share/mk/bsd.doc.mk \
29+
--replace '-o ''${DOCOWN}' "" \
30+
--replace '-g ''${DOCGRP}' ""
31+
for mk in $BSDSRCDIR/share/mk/bsd.inc.mk $BSDSRCDIR/share/mk/bsd.kinc.mk; do
32+
substituteInPlace $mk \
33+
--replace '-o ''${BINOWN}' "" \
34+
--replace '-g ''${BINGRP}' ""
35+
done
36+
substituteInPlace $BSDSRCDIR/share/mk/bsd.kmodule.mk \
37+
--replace '-o ''${KMODULEOWN}' "" \
38+
--replace '-g ''${KMODULEGRP}' ""
39+
substituteInPlace $BSDSRCDIR/share/mk/bsd.lib.mk \
40+
--replace '-o ''${LIBOWN}' "" \
41+
--replace '-g ''${LIBGRP}' "" \
42+
--replace '-o ''${DEBUGOWN}' "" \
43+
--replace '-g ''${DEBUGGRP}' ""
44+
substituteInPlace $BSDSRCDIR/share/mk/bsd.lua.mk \
45+
--replace '-o ''${LIBOWN}' "" \
46+
--replace '-g ''${LIBGRP}' ""
47+
substituteInPlace $BSDSRCDIR/share/mk/bsd.man.mk \
48+
--replace '-o ''${MANOWN}' "" \
49+
--replace '-g ''${MANGRP}' ""
50+
substituteInPlace $BSDSRCDIR/share/mk/bsd.nls.mk \
51+
--replace '-o ''${NLSOWN}' "" \
52+
--replace '-g ''${NLSGRP}' ""
53+
substituteInPlace $BSDSRCDIR/share/mk/bsd.prog.mk \
54+
--replace '-o ''${BINOWN}' "" \
55+
--replace '-g ''${BINGRP}' "" \
56+
--replace '-o ''${RUMPBINOWN}' "" \
57+
--replace '-g ''${RUMPBINGRP}' "" \
58+
--replace '-o ''${DEBUGOWN}' "" \
59+
--replace '-g ''${DEBUGGRP}' ""
60+
61+
substituteInPlace $BSDSRCDIR/share/mk/bsd.lib.mk \
62+
--replace '_INSTRANLIB=''${empty(PRESERVE):?-a "''${RANLIB} -t":}' '_INSTRANLIB='
63+
substituteInPlace $BSDSRCDIR/share/mk/bsd.kinc.mk \
64+
--replace /bin/rm rm
65+
''
66+
+ lib.optionalString stdenv.targetPlatform.isDarwin ''
67+
substituteInPlace $BSDSRCDIR/share/mk/bsd.sys.mk \
68+
--replace '-Wl,--fatal-warnings' "" \
69+
--replace '-Wl,--warn-shared-textrel' ""
70+
'';
71+
72+
installPhase = ''
73+
cp -r . $out
74+
'';
75+
}

pkgs/os-specific/bsd/netbsd/pkgs/make.nix

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
mkDerivation,
44
fetchNetBSD,
55
stdenv,
6+
make-rules,
67
}:
78

89
mkDerivation {
@@ -11,53 +12,12 @@ mkDerivation {
1112
version = "9.2";
1213

1314
postPatch =
14-
''
15-
substituteInPlace $BSDSRCDIR/share/mk/bsd.doc.mk \
16-
--replace '-o ''${DOCOWN}' "" \
17-
--replace '-g ''${DOCGRP}' ""
18-
for mk in $BSDSRCDIR/share/mk/bsd.inc.mk $BSDSRCDIR/share/mk/bsd.kinc.mk; do
19-
substituteInPlace $mk \
20-
--replace '-o ''${BINOWN}' "" \
21-
--replace '-g ''${BINGRP}' ""
22-
done
23-
substituteInPlace $BSDSRCDIR/share/mk/bsd.kmodule.mk \
24-
--replace '-o ''${KMODULEOWN}' "" \
25-
--replace '-g ''${KMODULEGRP}' ""
26-
substituteInPlace $BSDSRCDIR/share/mk/bsd.lib.mk \
27-
--replace '-o ''${LIBOWN}' "" \
28-
--replace '-g ''${LIBGRP}' "" \
29-
--replace '-o ''${DEBUGOWN}' "" \
30-
--replace '-g ''${DEBUGGRP}' ""
31-
substituteInPlace $BSDSRCDIR/share/mk/bsd.lua.mk \
32-
--replace '-o ''${LIBOWN}' "" \
33-
--replace '-g ''${LIBGRP}' ""
34-
substituteInPlace $BSDSRCDIR/share/mk/bsd.man.mk \
35-
--replace '-o ''${MANOWN}' "" \
36-
--replace '-g ''${MANGRP}' ""
37-
substituteInPlace $BSDSRCDIR/share/mk/bsd.nls.mk \
38-
--replace '-o ''${NLSOWN}' "" \
39-
--replace '-g ''${NLSGRP}' ""
40-
substituteInPlace $BSDSRCDIR/share/mk/bsd.prog.mk \
41-
--replace '-o ''${BINOWN}' "" \
42-
--replace '-g ''${BINGRP}' "" \
43-
--replace '-o ''${RUMPBINOWN}' "" \
44-
--replace '-g ''${RUMPBINGRP}' "" \
45-
--replace '-o ''${DEBUGOWN}' "" \
46-
--replace '-g ''${DEBUGGRP}' ""
47-
48-
# make needs this to pick up our sys make files
49-
export NIX_CFLAGS_COMPILE+=" -D_PATH_DEFSYSPATH=\"$out/share/mk\""
50-
51-
substituteInPlace $BSDSRCDIR/share/mk/bsd.lib.mk \
52-
--replace '_INSTRANLIB=''${empty(PRESERVE):?-a "''${RANLIB} -t":}' '_INSTRANLIB='
53-
substituteInPlace $BSDSRCDIR/share/mk/bsd.kinc.mk \
54-
--replace /bin/rm rm
55-
''
56-
+ lib.optionalString stdenv.isDarwin ''
57-
substituteInPlace $BSDSRCDIR/share/mk/bsd.sys.mk \
58-
--replace '-Wl,--fatal-warnings' "" \
59-
--replace '-Wl,--warn-shared-textrel' ""
15+
make-rules.postPatch
16+
+ ''
17+
# make needs this to pick up our sys make files
18+
appendToVar NIX_CFLAGS_COMPILE "-D_PATH_DEFSYSPATH=\"$out/share/mk\""
6019
'';
20+
6121
postInstall = ''
6222
make -C $BSDSRCDIR/share/mk FILESDIR=$out/share/mk install
6323
'';

pkgs/os-specific/bsd/netbsd/pkgs/makeMinimal.nix

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
netbsdSetupHook,
55
rsync,
66
make,
7+
make-rules,
78
}:
89

910
mkDerivation {
@@ -22,7 +23,9 @@ mkDerivation {
2223

2324
postPatch = ''
2425
patchShebangs $COMPONENT_PATH/configure
25-
${make.postPatch}
26+
27+
# make needs this to pick up our sys make files
28+
appendToVar NIX_CFLAGS_COMPILE "-D_PATH_DEFSYSPATH=\"$out/share/mk\""
2629
'';
2730

2831
buildPhase = ''
@@ -39,10 +42,10 @@ mkDerivation {
3942
install -D nbmake $out/bin/nbmake
4043
ln -s $out/bin/nbmake $out/bin/make
4144
mkdir -p $out/share
42-
cp -r $BSDSRCDIR/share/mk $out/share/mk
45+
cp -r ${make-rules} $out/share/mk
4346
4447
runHook postInstall
4548
'';
4649

47-
extraPaths = [ make.src ] ++ make.extraPaths;
50+
extraPaths = [ make.src ];
4851
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
stdenv,
3+
lib,
4+
stdenvNoCC,
5+
makeScopeWithSplicing',
6+
generateSplicesForMkScope,
7+
pkgs,
8+
buildPackages,
9+
netbsd,
10+
}:
11+
12+
makeScopeWithSplicing' {
13+
otherSplices = generateSplicesForMkScope "openbsd";
14+
f = (
15+
self:
16+
lib.packagesFromDirectoryRecursive {
17+
callPackage = self.callPackage;
18+
directory = ./pkgs;
19+
}
20+
// {
21+
libc = self.callPackage ./pkgs/libc/package.nix {
22+
inherit (self) csu include lorder;
23+
inherit (buildPackages.openbsd) makeMinimal;
24+
inherit (buildPackages.netbsd)
25+
install
26+
gencat
27+
rpcgen
28+
tsort
29+
;
30+
};
31+
makeMinimal = buildPackages.netbsd.makeMinimal.override { inherit (self) make-rules; };
32+
mkDerivation = self.callPackage ./pkgs/mkDerivation.nix {
33+
inherit stdenv;
34+
inherit (buildPackages.netbsd) install;
35+
};
36+
include = self.callPackage ./pkgs/include/package.nix {
37+
inherit (buildPackages.openbsd) makeMinimal;
38+
inherit (buildPackages.netbsd) install rpcgen mtree;
39+
};
40+
csu = self.callPackage ./pkgs/csu.nix {
41+
inherit (self) include;
42+
inherit (buildPackages.openbsd) makeMinimal;
43+
inherit (buildPackages.netbsd) install;
44+
};
45+
make-rules = self.callPackage ./pkgs/make-rules/package.nix { };
46+
lorder = self.callPackage ./pkgs/lorder.nix { inherit (buildPackages.netbsd) install; };
47+
}
48+
);
49+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
lib,
3+
mkDerivation,
4+
bsdSetupHook,
5+
openbsdSetupHook,
6+
makeMinimal,
7+
install,
8+
include,
9+
}:
10+
11+
mkDerivation {
12+
path = "lib/csu";
13+
nativeBuildInputs = [
14+
bsdSetupHook
15+
openbsdSetupHook
16+
makeMinimal
17+
install
18+
];
19+
buildInputs = [ include ];
20+
meta.platforms = lib.platforms.openbsd;
21+
extraPaths = [ "libexec/ld.so" ];
22+
}

0 commit comments

Comments
 (0)