git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #38822 from matthewbauer/netbsd

Introducing NetBSD userland

commitab92a474a9e38c5edb8ece0dd6774d966cd4557d authorMatthew Justin Bauer <mjbauer95@gmail.com> dateTue 24 Apr 2018, 14:46 (9 years ago) parent78d9bff31ef995
10 files changed+1375−3
pkgs/build-support/fetchcvs/builder.sh+5 pkgs/build-support/fetchcvs/default.nix+3−3 pkgs/os-specific/bsd/default.nix+8 pkgs/os-specific/bsd/netbsd/compat-setup-hook.sh+18 pkgs/os-specific/bsd/netbsd/default.nix+404 pkgs/os-specific/bsd/netbsd/fts-setup-hook.sh+16 pkgs/os-specific/bsd/netbsd/getent.patch+455 pkgs/os-specific/bsd/openbsd/default.nix+42 pkgs/os-specific/bsd/openbsd/nc.patch+421 pkgs/top-level/all-packages.nix+3
pkgs/build-support/fetchcvs/builder.sh+5
@@ -1,5 +1,10 @@
11source $stdenv/setup
22
3+(echo '#!/usr/bin/env sh'; \
4+ echo 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$@"') > ssh
5+chmod +x ssh
6+export CVS_RSH=$PWD/ssh
7+
38# creating the export drictory and checking out there only to be able to
49# move the content without the root directory into $out ...
510# cvs -f -d "$url" export $tag -d "$out" "$module"
pkgs/build-support/fetchcvs/default.nix+3−3
@@ -3,18 +3,18 @@
33# tag="<tagname>" (get version by tag name)
44# If you don't specify neither one date="NOW" will be used (get latest)
55
6−{stdenvNoCC, cvs}:
6+{stdenvNoCC, cvs, openssh}:
77
88{cvsRoot, module, tag ? null, date ? null, sha256}:
99
1010stdenvNoCC.mkDerivation {
1111 name = "cvs-export";
1212 builder = ./builder.sh;
13− nativeBuildInputs = [cvs];
13+ nativeBuildInputs = [cvs openssh];
1414
1515 outputHashAlgo = "sha256";
1616 outputHashMode = "recursive";
1717 outputHash = sha256;
18−
18+
1919 inherit cvsRoot module sha256 tag date;
2020}
pkgs/os-specific/bsd/default.nixnew file+8
@@ -0,0 +1,8 @@
1+{ callPackages, recurseIntoAttrs }:
2+
3+rec {
4+ netbsd = recurseIntoAttrs (callPackages ./netbsd {});
5+ openbsd = recurseIntoAttrs (callPackages ./openbsd {
6+ inherit (netbsd) compat netBSDDerivation libcurses;
7+ });
8+}
pkgs/os-specific/bsd/netbsd/compat-setup-hook.shnew file+18
@@ -0,0 +1,18 @@
1+setupCompatFlags() {
2+ # The `depHostOffset` describes how the host platform of the dependencies
3+ # are slid relative to the depending package. It is brought into scope of
4+ # the environment hook defined as the role of the dependency being applied.
5+ case $depHostOffset in
6+ -1) local role='BUILD_' ;;
7+ 0) local role='' ;;
8+ 1) local role='TARGET_' ;;
9+ *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2;
10+ return 1 ;;
11+ esac
12+
13+ export NIX_${role}LDFLAGS+=" -lnbcompat"
14+ export NIX_${role}CFLAGS_COMPILE+=" -DHAVE_NBTOOL_CONFIG_H"
15+ export NIX_${role}CFLAGS_COMPILE+=" -include nbtool_config.h"
16+}
17+
18+addEnvHooks "$hostOffset" setupCompatFlags
pkgs/os-specific/bsd/netbsd/default.nixnew file+404
@@ -0,0 +1,404 @@
1+{ stdenv, hostPlatform, fetchcvs, lib, groff, mandoc, zlib, coreutils
2+, yacc, flex, libressl, bash }:
3+
4+let
5+ fetchNetBSD = path: version: sha256: fetchcvs {
6+ cvsRoot = ":pserver:anoncvs@anoncvs.NetBSD.org:/cvsroot";
7+ module = "src/${path}";
8+ inherit sha256;
9+ tag = "netbsd-${builtins.replaceStrings ["."] ["-"] version}-RELEASE";
10+ };
11+
12+ netBSDDerivation = attrs: stdenv.mkDerivation ((rec {
13+ name = "${attrs.pname or (baseNameOf attrs.path)}-netbsd-${attrs.version}";
14+ src = fetchNetBSD attrs.path attrs.version attrs.sha256;
15+
16+ extraPaths = [ ];
17+
18+ nativeBuildInputs = [ makeMinimal mandoc groff install yacc flex ];
19+ buildInputs = [ compat ];
20+ installFlags = [ "includes" ];
21+
22+ # These should be coverd in nbcompat, but are missing, sadly
23+ NIX_CFLAGS_COMPILE = [
24+ "-D__noinline="
25+ "-D__warn_references(a,b)="
26+ "-D__strong_alias(a,b)="
27+ "-D__va_list=va_list"
28+ ];
29+
30+ # Definitions passed to share/mk/*.mk. Should be pretty simple -
31+ # eventually maybe move it to a configure script.
32+ DESTDIR = "$(out)";
33+ TOOLDIR = "$(out)";
34+ USETOOLS = "never";
35+ NOCLANGERROR="yes";
36+ NOGCCERROR="yes";
37+ LEX = "flex";
38+
39+ # libs will be provided by cc-wrapper
40+ LIBCRT0="";
41+ LIBCRTI="";
42+ LIBCRTEND="";
43+ LIBCRTBEGIN="";
44+ LIBC="";
45+ LIBUTIL="";
46+ LIBSSL = "";
47+ LIBCRYPTO = "";
48+ LIBCURSES = "";
49+ "LIBDO.terminfo" = "_external";
50+ _GCC_CRTBEGIN = "";
51+ _GCC_CRTBEGINS = "";
52+ _GCC_CRTEND = "";
53+ _GCC_CRTENDS = "";
54+ _GCC_LIBGCCDIR = "";
55+ _GCC_CRTI = "";
56+ _GCC_CRTDIR = "";
57+ _GCC_CRTN = "";
58+
59+ # all dirs will be prefixed with DESTDIR
60+ BINDIR = "/bin";
61+ LIBDIR = "/lib";
62+ SHLIBDIR = "/lib";
63+ MANDIR = "/share/man";
64+ INFODIR = "/share/info";
65+ DOCDIR = "/share/doc";
66+ LOCALEDIR = "/share/locale";
67+ X11BINDIR = "/bin";
68+ X11USRLIBDIR = "/lib";
69+ X11MANDIR = "/share/man";
70+ SHLINKDIR = "/usr/libexec";
71+
72+ HOST_SH = "${bash}/bin/sh";
73+
74+ # not using bsd binutils
75+ SHLIB_WARNTEXTREL = "no";
76+ SHLIB_MKMAP = "no";
77+ OBJCOPY = "true";
78+ PRESERVE = "-p";
79+
80+ MACHINE_ARCH = hostPlatform.parsed.cpu.name;
81+ MACHINE_CPU = hostPlatform.parsed.cpu.name;
82+
83+ # NetBSD makefiles should be able to detect this
84+ # but without they end up using gcc on Darwin stdenv
85+ preConfigure = ''
86+ export HAVE_${if stdenv.cc.isGNU then "GCC" else "LLVM"}=${lib.head (lib.splitString "." (lib.getVersion stdenv.cc.cc))}
87+ '' + lib.optionalString (!builtins.hasAttr "nativeBuildInputs" attrs) ''
88+ # hack until #38657 is fixed
89+ export PATH=${install}/bin:$PATH
90+ '';
91+
92+ postUnpack = ''
93+ # merge together all extra paths
94+ # there should be a better way to do this
95+ sourceRoot=$PWD/$sourceRoot
96+ export NETBSDSRCDIR=$sourceRoot
97+ export BSDSRCDIR=$NETBSDSRCDIR
98+ chmod -R u+w $sourceRoot
99+ for path in $extraPaths; do
100+ cd $path
101+ find . -type d -exec mkdir -p $sourceRoot/\{} \;
102+ find . -type f -exec cp -pr \{} $sourceRoot/\{} \;
103+ chmod -R u+w $sourceRoot
104+ done
105+
106+ cd $sourceRoot
107+ if [ -d ${attrs.path} ]
108+ then sourceRoot=$sourceRoot/${attrs.path}
109+ fi
110+ '';
111+
112+ # need to create directories for xinstall to work
113+ preInstall = ''
114+ mkdir -p $out$BINDIR $out$LIBDIR $out$INFODIR \
115+ $out$DOCDIR $out$LOCALEDIR
116+ for i in 1 2 3 4 5 6 7 8 9; do
117+ mkdir -p $out$MANDIR/man$i $out$MANDIR/html$i
118+ done
119+ mkdir -p $out/usr/include
120+ '';
121+
122+ postInstall = ''
123+ # Remove lingering /usr references
124+ if [ -d $out/usr ]; then
125+ cd $out/usr
126+ find . -type d -exec mkdir -p $out/\{} \;
127+ find . -type f -exec mv \{} $out/\{} \;
128+ find . -type d -delete
129+ fi
130+
131+ find $out -type d -empty -delete
132+ '';
133+
134+ meta = with lib; {
135+ maintainers = with maintainers; [matthewbauer];
136+ platforms = platforms.unix;
137+ license = licenses.bsd2;
138+ };
139+ }) // attrs);
140+
141+ # BOOTSTRAPPING
142+ makeMinimal = netBSDDerivation rec {
143+ path = "tools/make";
144+ sha256 = "0l4794zwj2haark3azf9xwcwqlkbrifhb2glaa9iba4dkg2mklsb";
145+ version = "7.1.2";
146+
147+ buildInputs = [];
148+ nativeBuildInputs = [];
149+ NIX_CFLAGS_COMPILE = "";
150+ NIX_LDFLAGS = "";
151+
152+ patchPhase = ''
153+ patchShebangs configure
154+ ${make.patchPhase}
155+ '';
156+ buildPhase = "sh ./buildmake.sh";
157+ installPhase = ''
158+ install -D nbmake $out/bin/nbmake
159+ ln -s $out/bin/nbmake $out/bin/make
160+ mkdir -p $out/share
161+ cp -r ../../share/mk $out/share/mk
162+ '';
163+ extraPaths = [ make.src ] ++ make.extraPaths;
164+ };
165+
166+ compat = netBSDDerivation {
167+ path = "tools/compat";
168+ sha256 = "17phkfafybxwhzng44k5bhmag6i55br53ky1nwcmw583kg2fa86z";
169+ version = "7.1.2";
170+
171+ setupHook = ./compat-setup-hook.sh;
172+
173+ # override defaults to prevent infinite recursion
174+ nativeBuildInputs = [ makeMinimal ];
175+ buildInputs = [ zlib ];
176+ NIX_CFLAGS_COMPILE = "";
177+ NIX_LDFLAGS = "";
178+
179+ # temporarily use gnuinstall for bootstrapping
180+ # bsdinstall will be built later
181+ makeFlags = "INSTALL=${coreutils}/bin/install";
182+ RENAME = "-D";
183+
184+ postInstall = ''
185+ mv $out/include/compat/* $out/include
186+ rmdir $out/include/compat
187+
188+ # why aren't these installed by netbsd?
189+ install -D compat_defs.h $out/include/compat_defs.h
190+ install -D $NETBSDSRCDIR/include/cdbw.h $out/include/cdbw.h
191+ install -D $NETBSDSRCDIR/sys/sys/cdbr.h $out/include/cdbr.h
192+ install -D $NETBSDSRCDIR/sys/sys/featuretest.h \
193+ $out/include/sys/featuretest.h
194+ install -D $NETBSDSRCDIR/sys/sys/md5.h $out/include/md5.h
195+ install -D $NETBSDSRCDIR/sys/sys/rmd160.h $out/include/rmd160.h
196+ install -D $NETBSDSRCDIR/sys/sys/sha1.h $out/include/sha1.h
197+ install -D $NETBSDSRCDIR/sys/sys/sha2.h $out/include/sha2.h
198+ '';
199+ extraPaths = [ libc.src libutil.src
200+ (fetchNetBSD "include" "7.1.2" "1vc58xrhrp202biiv1chhlh0jwnjr7k3qq91pm46k6v5j95j0qwp")
201+ (fetchNetBSD "external/bsd/flex" "7.1.2" "0m0m72r3zzc9gi432h3xkqdzspr4n0hj4m8h7j74pwbvpfg9d9qq")
202+ (fetchNetBSD "sys/sys" "7.1.2" "1vwnv5nk7rlgn5w9nkdqj9652hmwmfwqxj3ymcz0zk10abbaib93")
203+ ] ++ libutil.extraPaths ++ libc.extraPaths;
204+ };
205+
206+ install = netBSDDerivation {
207+ path = "usr.bin/xinstall";
208+ version = "7.1.2";
209+ sha256 = "0nzhyh714m19h61m45gzc5dszkbafp5iaphbp5mza6w020fzf2y8";
210+ extraPaths = [ mtree.src make.src ];
211+ nativeBuildInputs = [ makeMinimal mandoc groff compat ];
212+ RENAME = "-D";
213+ };
214+ # END BOOTSTRAPPING
215+
216+ libutil = netBSDDerivation {
217+ path = "lib/libutil";
218+ version = "7.1.2";
219+ sha256 = "12848ynizz13mvn2kndrkq482xhkw323b7c8fg0zli1nhfsmwsm8";
220+ extraPaths = [
221+ (fetchNetBSD "common/lib/libutil" "7.1.2" "0q3ixrf36lip1dx0gafs0a03qfs5cs7n0myqq7af4jpjd6kh1831")
222+ ];
223+ };
224+
225+ libc = netBSDDerivation {
226+ path = "lib/libc";
227+ version = "7.1.2";
228+ sha256 = "13rcx3mbx2644z01zgk9gggdfr0hqdbsvd7zrsm2l13yf9aix6pg";
229+ extraPaths = [
230+ (fetchNetBSD "common/lib/libc" "7.1.2" "1va8zd4lqyrc1d0c9q04r8y88cfxpkhwcxasggxxvhksd3khkpha")
231+ ];
232+ };
233+
234+ make = netBSDDerivation {
235+ path = "usr.bin/make";
236+ sha256 = "0srkkg6qdzqlccfi4xh19gl766ks6hpss76bnfvwmd0zg4q4zdar";
237+ version = "7.1.2";
238+ patchPhase = ''
239+ # make needs this to pick up our sys make files
240+ NIX_CFLAGS_COMPILE+=" -D_PATH_DEFSYSPATH=\"$out/share/mk\""
241+
242+ # can't set owner or group in Nix build
243+ # maybe there is a better way to trick it?
244+ substituteInPlace $NETBSDSRCDIR/share/mk/bsd.prog.mk \
245+ --replace '-o ''${SCRIPTSOWN_''${.ALLSRC:T}:U''${SCRIPTSOWN}}' "" \
246+ --replace '-g ''${SCRIPTSGRP_''${.ALLSRC:T}:U''${SCRIPTSGRP}}' "" \
247+ --replace '-o ''${RUMPBINOWN} -g ''${RUMPBINGRP}' "" \
248+ --replace '-o ''${BINOWN} -g ''${BINGRP}' "" \
249+ --replace '-o ''${RUMPBINOWN} -g ''${RUMPBINGRP}' "" \
250+ --replace '-o ''${DEBUGOWN} -g ''${DEBUGGRP}' ""
251+ substituteInPlace $NETBSDSRCDIR/share/mk/bsd.doc.mk \
252+ --replace '-o ''${DOCOWN} -g ''${DOCGRP}' ""
253+ substituteInPlace $NETBSDSRCDIR/share/mk/bsd.man.mk \
254+ --replace '-o ''${MANOWN} -g ''${MANGRP}' ""
255+ substituteInPlace $NETBSDSRCDIR/share/mk/bsd.files.mk \
256+ --replace '-o ''${FILESOWN_''${.ALLSRC:T}:U''${FILESOWN}}' "" \
257+ --replace '-g ''${FILESGRP_''${.ALLSRC:T}:U''${FILESGRP}}' ""
258+ substituteInPlace $NETBSDSRCDIR/share/mk/bsd.inc.mk \
259+ --replace '-o ''${BINOWN} -g ''${BINGRP}' ""
260+ substituteInPlace $NETBSDSRCDIR/share/mk/bsd.lib.mk \
261+ --replace '-o ''${DEBUGOWN} -g ''${DEBUGGRP}' "" \
262+ --replace '-o ''${LIBOWN} -g ''${LIBGRP}' ""
263+
264+ substituteInPlace $NETBSDSRCDIR/share/mk/Makefile \
265+ --replace /usr/share/mk /share/mk
266+ substituteInPlace $NETBSDSRCDIR/share/mk/bsd.sys.mk \
267+ --replace '-Wl,--fatal-warnings' ""
268+ substituteInPlace $NETBSDSRCDIR/share/mk/bsd.lib.mk \
269+ --replace ' ''${_ARFL} ''${.TARGET} `NM=''${NM} ''${LORDER} ''${.ALLSRC:M*o} | ''${TSORT}`' ' ''${_ARFL} ''${.TARGET} ''${.ALLSRC:M*o}' \
270+ --replace '-Wl,-soname,''${_LIB}.so.''${SHLIB_SOVERSION}' "" \
271+ --replace '-Wl,--whole-archive' "" \
272+ --replace '-Wl,--no-whole-archive' ""
273+ '';
274+ postInstall = ''
275+ (cd $NETBSDSRCDIR/share/mk && make install)
276+ '';
277+ extraPaths = [
278+ (fetchNetBSD "share/mk" "7.1.2" "0570v0siv0wygn8ygs1yy9pgk9xjw9x1axr5qg4xrddv3lskf9xa")
279+ ];
280+ };
281+
282+ mtree = netBSDDerivation {
283+ path = "usr.sbin/mtree";
284+ version = "7.1.2";
285+ sha256 = "1dhsyfvcm67kf5zdbg5dmx5y8fimnbll6qxwp3gjfmbxqigmc52m";
286+ };
287+
288+in rec {
289+ inherit compat libc libutil install make mtree netBSDDerivation;
290+
291+ getent = netBSDDerivation {
292+ path = "usr.bin/getent";
293+ sha256 = "1ylhw4dnpyrmcy8n5kjcxywm8qc9p124dqnm17x4magiqx1kh9iz";
294+ version = "7.1.2";
295+ patches = [ ./getent.patch ];
296+ };
297+
298+ getconf = netBSDDerivation {
299+ path = "usr.bin/getconf";
300+ sha256 = "122vslz4j3h2mfs921nr2s6m078zcj697yrb75rwp2hnw3qz4s8q";
301+ version = "7.1.2";
302+ };
303+
304+ fts = netBSDDerivation {
305+ pname = "fts";
306+ path = "include/fts.h";
307+ sha256 = "01d4fpxvz1pgzfk5xznz5dcm0x0gdzwcsfm1h3d0xc9kc6hj2q77";
308+ version = "7.1.2";
309+ nativeBuildInputs = [ ];
310+ extraPaths = [
311+ (fetchNetBSD "lib/libc/gen/fts.c" "7.1.2" "1yfd2liypj6xky2h0mgxi5lgpflmkkg4zf3ii3apz5cf8jq9gmn9")
312+ (fetchNetBSD "lib/libc/include/namespace.h" "7.1.2" "0kwd4v8y0mfjhmwplsk52pvzbcpvpp2qy2g8c0jmfraam63q6q1y")
313+ (fetchNetBSD "lib/libc/gen/fts.3" "7.1.2" "1asxw0n3fhjdadwkkq3xplfgqgl3q32w1lyrvbakfa3gs0wz5zc1")
314+ ];
315+ buildPhase = ''
316+ cc -c -Iinclude -Ilib/libc/include lib/libc/gen/fts.c \
317+ -o lib/libc/gen/fts.o
318+ ar -rsc libfts.a lib/libc/gen/fts.o
319+ '';
320+ installPhase = ''
321+ install -D lib/libc/gen/fts.3 $out/share/man/man3/fts.3
322+ install -D include/fts.h $out/include/fts.h
323+ install -D lib/libc/include/namespace.h $out/include/namespace.h
324+ install -D libfts.a $out/lib/libfts.a
325+ '';
326+ setupHook = ./fts-setup-hook.sh;
327+ };
328+
329+ games = netBSDDerivation {
330+ path = "games";
331+ sha256 = "04wjsang8f8kxsifiayklbxaaxmm3vx9rfr91hfbxj4hk8gkqzy1";
332+ version = "7.1.2";
333+ patchPhase = ''
334+ sed -i '1i #include <time.h>' adventure/save.c
335+ '';
336+ };
337+
338+ who = netBSDDerivation {
339+ path = "usr.bin/who";
340+ version = "7.1.2";
341+ sha256 = "17ffwww957m3qw0b6fkgjpp12pd5ydg2hs9dxkkw0qpv11j00d88";
342+ };
343+
344+ finger = netBSDDerivation {
345+ path = "usr.bin/finger";
346+ sha256 = "0jl672z50f2yf7ikp682b3xrarm6bnrrx9vi94xnp2fav8m8zfyi";
347+ version = "7.1.2";
348+ extraPaths = [ who.src ];
349+ };
350+
351+ fingerd = netBSDDerivation {
352+ path = "usr.bin/fingerd";
353+ sha256 = "04wjsang8f8kxsifiayklbxaaxmm3vx9rfr91hfbxj4hk8gkqz00";
354+ version = "7.1.2";
355+ };
356+
357+ libedit = netBSDDerivation {
358+ path = "lib/libedit";
359+ buildInputs = [ compat libterminfo ];
360+ patchPhase = ''
361+ sed -i '1i #undef bool_t' el.h
362+ '';
363+ version = "7.1.2";
364+ sha256 = "0qvr52j4qih10m7fa8nddn1psyjy9l0pa4ix02acyssjvgbz2kca";
365+ };
366+
367+ libterminfo = netBSDDerivation {
368+ path = "lib/libterminfo";
369+ version = "7.1.2";
370+ sha256 = "06plg0bjqgbb0aghpb9qlk8wkp1l2izdlr64vbr5laqyw8jg84zq";
371+ buildInputs = [ compat tic nbperf ];
372+ extraPaths = [
373+ (fetchNetBSD "share/terminfo" "7.1.2" "1z5vzq8cw24j05r6df4vd6r57cvdbv7vbm4h962kplp14xrbg2h3")
374+ ];
375+ };
376+
377+ libcurses = netBSDDerivation {
378+ path = "lib/libcurses";
379+ version = "7.1.2";
380+ sha256 = "04djah9dadzw74nswn0xydkxn900kav8xdvxlxdl50nbrynxg9yf";
381+ buildInputs = [ compat libterminfo ];
382+ MKDOC = "no"; # missing vfontedpr
383+ };
384+
385+ nbperf = netBSDDerivation {
386+ path = "usr.bin/nbperf";
387+ version = "7.1.2";
388+ sha256 = "0gzm0zv2400lasnsswnjw9bwzyizhxzdbrcjwcl1k65aj86aqyqb";
389+ };
390+
391+ tic = netBSDDerivation {
392+ path = "tools/tic";
393+ version = "7.1.2";
394+ sha256 = "092y7db7k4kh2jq8qc55126r5qqvlb8lq8mhmy5ipbi36hwb4zrz";
395+ HOSTPROG = "tic";
396+ buildInputs = [ compat nbperf ];
397+ extraPaths = [
398+ libterminfo.src
399+ (fetchNetBSD "usr.bin/tic" "7.1.2" "1ghwsaag4gbwvgp3lfxscnh8hn27n8cscwmgjwp3bkx5vl85nfsa")
400+ (fetchNetBSD "tools/Makefile.host" "7.1.2" "076r3amivb6xranpvqjmg7x5ibj4cbxaa3z2w1fh47h7d55dw9w8")
401+ ];
402+ };
403+
404+}
pkgs/os-specific/bsd/netbsd/fts-setup-hook.shnew file+16
@@ -0,0 +1,16 @@
1+ftsLdflags() {
2+ # The `depHostOffset` describes how the host platform of the dependencies
3+ # are slid relative to the depending package. It is brought into scope of
4+ # the environment hook defined as the role of the dependency being applied.
5+ case $depHostOffset in
6+ -1) local role='BUILD_' ;;
7+ 0) local role='' ;;
8+ 1) local role='TARGET_' ;;
9+ *) echo "cc-wrapper: Error: Cannot be used with $depHostOffset-offset deps" >2;
10+ return 1 ;;
11+ esac
12+
13+ export NIX_${role}LDFLAGS+=" -lfts"
14+}
15+
16+addEnvHooks "$hostOffset" ftsLdflags
pkgs/os-specific/bsd/netbsd/getent.patchnew file+455
@@ -0,0 +1,455 @@
1+Author: Matthew Bauer
2+Description: Remove unavailable getent databases
3+Version: 7.1.2
4+--- a/getent.c 2018-04-16 13:33:49.000000000 -0500
5++++ b/getent.c 2018-04-16 13:29:30.000000000 -0500
6+@@ -42,7 +42,6 @@
7+ #include <grp.h>
8+ #include <limits.h>
9+ #include <netdb.h>
10+-#include <netgroup.h>
11+ #include <pwd.h>
12+ #include <stdio.h>
13+ #include <stdarg.h>
14+@@ -57,27 +56,16 @@
15+ #include <arpa/nameser.h>
16+
17+ #include <net/if.h>
18+-#include <net/if_ether.h>
19+
20+ #include <netinet/in.h> /* for INET6_ADDRSTRLEN */
21+
22+-#include <rpc/rpcent.h>
23+-
24+-#include <disktab.h>
25+-
26+ static int usage(void) __attribute__((__noreturn__));
27+ static int parsenum(const char *, unsigned long *);
28+-static int disktab(int, char *[]);
29+-static int gettytab(int, char *[]);
30+-static int ethers(int, char *[]);
31+ static int group(int, char *[]);
32+ static int hosts(int, char *[]);
33+-static int netgroup(int, char *[]);
34+ static int networks(int, char *[]);
35+ static int passwd(int, char *[]);
36+-static int printcap(int, char *[]);
37+ static int protocols(int, char *[]);
38+-static int rpc(int, char *[]);
39+ static int services(int, char *[]);
40+ static int shells(int, char *[]);
41+
42+@@ -92,17 +80,11 @@
43+ const char *name;
44+ int (*callback)(int, char *[]);
45+ } databases[] = {
46+- { "disktab", disktab, },
47+- { "ethers", ethers, },
48+- { "gettytab", gettytab, },
49+ { "group", group, },
50+ { "hosts", hosts, },
51+- { "netgroup", netgroup, },
52+ { "networks", networks, },
53+ { "passwd", passwd, },
54+- { "printcap", printcap, },
55+ { "protocols", protocols, },
56+- { "rpc", rpc, },
57+ { "services", services, },
58+ { "shells", shells, },
59+
60+@@ -195,49 +177,6 @@
61+ (void)printf("\n");
62+ }
63+
64+-
65+- /*
66+- * ethers
67+- */
68+-
69+-static int
70+-ethers(int argc, char *argv[])
71+-{
72+- char hostname[MAXHOSTNAMELEN + 1], *hp;
73+- struct ether_addr ea, *eap;
74+- int i, rv;
75+-
76+- assert(argc > 1);
77+- assert(argv != NULL);
78+-
79+-#define ETHERSPRINT (void)printf("%-17s %s\n", ether_ntoa(eap), hp)
80+-
81+- rv = RV_OK;
82+- if (argc == 2) {
83+- warnx("Enumeration not supported on ethers");
84+- rv = RV_NOENUM;
85+- } else {
86+- for (i = 2; i < argc; i++) {
87+- if ((eap = ether_aton(argv[i])) == NULL) {
88+- eap = &ea;
89+- hp = argv[i];
90+- if (ether_hostton(hp, eap) != 0) {
91+- rv = RV_NOTFOUND;
92+- break;
93+- }
94+- } else {
95+- hp = hostname;
96+- if (ether_ntohost(hp, eap) != 0) {
97+- rv = RV_NOTFOUND;
98+- break;
99+- }
100+- }
101+- ETHERSPRINT;
102+- }
103+- }
104+- return rv;
105+-}
106+-
107+ /*
108+ * group
109+ */
110+@@ -298,7 +237,7 @@
111+ hosts(int argc, char *argv[])
112+ {
113+ struct hostent *he;
114+- char addr[IN6ADDRSZ];
115++ char addr[NS_IN6ADDRSZ];
116+ int i, rv;
117+
118+ assert(argc > 1);
119+@@ -312,9 +251,9 @@
120+ } else {
121+ for (i = 2; i < argc; i++) {
122+ if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0)
123+- he = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
124++ he = gethostbyaddr(addr, NS_IN6ADDRSZ, AF_INET6);
125+ else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0)
126+- he = gethostbyaddr(addr, INADDRSZ, AF_INET);
127++ he = gethostbyaddr(addr, NS_INADDRSZ, AF_INET);
128+ else
129+ he = gethostbyname(argv[i]);
130+ if (he != NULL)
131+@@ -330,48 +269,6 @@
132+ }
133+
134+ /*
135+- * netgroup
136+- */
137+-static int
138+-netgroup(int argc, char *argv[])
139+-{
140+- int rv, i;
141+- bool first;
142+- const char *host, *user, *domain;
143+-
144+- assert(argc > 1);
145+- assert(argv != NULL);
146+-
147+-#define NETGROUPPRINT(s) (((s) != NULL) ? (s) : "")
148+-
149+- rv = RV_OK;
150+- if (argc == 2) {
151+- warnx("Enumeration not supported on netgroup");
152+- rv = RV_NOENUM;
153+- } else {
154+- for (i = 2; i < argc; i++) {
155+- setnetgrent(argv[i]);
156+- first = true;
157+- while (getnetgrent(&host, &user, &domain) != 0) {
158+- if (first) {
159+- first = false;
160+- (void)fputs(argv[i], stdout);
161+- }
162+- (void)printf(" (%s,%s,%s)",
163+- NETGROUPPRINT(host),
164+- NETGROUPPRINT(user),
165+- NETGROUPPRINT(domain));
166+- }
167+- if (!first)
168+- (void)putchar('\n');
169+- endnetgrent();
170+- }
171+- }
172+-
173+- return rv;
174+-}
175+-
176+- /*
177+ * networks
178+ */
179+
180+@@ -464,227 +361,6 @@
181+ return rv;
182+ }
183+
184+-static char *
185+-mygetent(const char * const * db_array, const char *name)
186+-{
187+- char *buf = NULL;
188+- int error;
189+-
190+- switch (error = cgetent(&buf, db_array, name)) {
191+- case -3:
192+- warnx("tc= loop in record `%s' in `%s'", name, db_array[0]);
193+- break;
194+- case -2:
195+- warn("system error fetching record `%s' in `%s'", name,
196+- db_array[0]);
197+- break;
198+- case -1:
199+- case 0:
200+- break;
201+- case 1:
202+- warnx("tc= reference not found in record for `%s' in `%s'",
203+- name, db_array[0]);
204+- break;
205+- default:
206+- warnx("unknown error %d in record `%s' in `%s'", error, name,
207+- db_array[0]);
208+- break;
209+- }
210+- return buf;
211+-}
212+-
213+-static char *
214+-mygetone(const char * const * db_array, int first)
215+-{
216+- char *buf = NULL;
217+- int error;
218+-
219+- switch (error = (first ? cgetfirst : cgetnext)(&buf, db_array)) {
220+- case -2:
221+- warnx("tc= loop in `%s'", db_array[0]);
222+- break;
223+- case -1:
224+- warn("system error fetching record in `%s'", db_array[0]);
225+- break;
226+- case 0:
227+- case 1:
228+- break;
229+- case 2:
230+- warnx("tc= reference not found in `%s'", db_array[0]);
231+- break;
232+- default:
233+- warnx("unknown error %d in `%s'", error, db_array[0]);
234+- break;
235+- }
236+- return buf;
237+-}
238+-
239+-static void
240+-capprint(const char *cap)
241+-{
242+- char *c = strchr(cap, ':');
243+- if (c)
244+- if (c == cap)
245+- (void)printf("true\n");
246+- else {
247+- int l = (int)(c - cap);
248+- (void)printf("%*.*s\n", l, l, cap);
249+- }
250+- else
251+- (void)printf("%s\n", cap);
252+-}
253+-
254+-static void
255+-prettyprint(char *b)
256+-{
257+-#define TERMWIDTH 65
258+- int did = 0;
259+- size_t len;
260+- char *s, c;
261+-
262+- for (;;) {
263+- len = strlen(b);
264+- if (len <= TERMWIDTH) {
265+-done:
266+- if (did)
267+- printf("\t:");
268+- printf("%s\n", b);
269+- return;
270+- }
271+- for (s = b + TERMWIDTH; s > b && *s != ':'; s--)
272+- continue;
273+- if (*s++ != ':')
274+- goto done;
275+- c = *s;
276+- *s = '\0';
277+- if (did)
278+- printf("\t:");
279+- did++;
280+- printf("%s\\\n", b);
281+- *s = c;
282+- b = s;
283+- }
284+-}
285+-
286+-static void
287+-handleone(const char * const *db_array, char *b, int recurse, int pretty,
288+- int level)
289+-{
290+- char *tc;
291+-
292+- if (level && pretty)
293+- printf("\n");
294+- if (pretty)
295+- prettyprint(b);
296+- else
297+- printf("%s\n", b);
298+- if (!recurse || cgetstr(b, "tc", &tc) <= 0)
299+- return;
300+-
301+- b = mygetent(db_array, tc);
302+- free(tc);
303+-
304+- if (b == NULL)
305+- return;
306+-
307+- handleone(db_array, b, recurse, pretty, ++level);
308+- free(b);
309+-}
310+-
311+-static int
312+-handlecap(const char *db, int argc, char *argv[])
313+-{
314+- static const char sfx[] = "=#:";
315+- const char *db_array[] = { db, NULL };
316+- char *b, *cap;
317+- int i, rv, c;
318+- size_t j;
319+- int expand = 1, recurse = 0, pretty = 0;
320+-
321+- assert(argc > 1);
322+- assert(argv != NULL);
323+-
324+- argc--;
325+- argv++;
326+- while ((c = getopt(argc, argv, "pnr")) != -1)
327+- switch (c) {
328+- case 'n':
329+- expand = 0;
330+- break;
331+- case 'r':
332+- expand = 0;
333+- recurse = 1;
334+- break;
335+- case 'p':
336+- pretty = 1;
337+- break;
338+- default:
339+- usage();
340+- break;
341+- }
342+-
343+- argc -= optind;
344+- argv += optind;
345+- csetexpandtc(expand);
346+- rv = RV_OK;
347+- if (argc == 0) {
348+- for (b = mygetone(db_array, 1); b; b = mygetone(db_array, 0)) {
349+- handleone(db_array, b, recurse, pretty, 0);
350+- free(b);
351+- }
352+- } else {
353+- if ((b = mygetent(db_array, argv[0])) == NULL)
354+- return RV_NOTFOUND;
355+- if (argc == 1)
356+- handleone(db_array, b, recurse, pretty, 0);
357+- else {
358+- for (i = 2; i < argc; i++) {
359+- for (j = 0; j < sizeof(sfx) - 1; j++) {
360+- cap = cgetcap(b, argv[i], sfx[j]);
361+- if (cap) {
362+- capprint(cap);
363+- break;
364+- }
365+- }
366+- if (j == sizeof(sfx) - 1)
367+- printf("false\n");
368+- }
369+- }
370+- free(b);
371+- }
372+- return rv;
373+-}
374+-
375+- /*
376+- * gettytab
377+- */
378+-
379+-static int
380+-gettytab(int argc, char *argv[])
381+-{
382+- return handlecap(_PATH_GETTYTAB, argc, argv);
383+-}
384+-
385+- /*
386+- * printcap
387+- */
388+-
389+-static int
390+-printcap(int argc, char *argv[])
391+-{
392+- return handlecap(_PATH_PRINTCAP, argc, argv);
393+-}
394+-
395+- /*
396+- * disktab
397+- */
398+-
399+-static int
400+-disktab(int argc, char *argv[])
401+-{
402+- return handlecap(_PATH_DISKTAB, argc, argv);
403+-}
404+-
405+ /*
406+ * protocols
407+ */
408+@@ -726,47 +402,6 @@
409+ }
410+
411+ /*
412+- * rpc
413+- */
414+-
415+-static int
416+-rpc(int argc, char *argv[])
417+-{
418+- struct rpcent *re;
419+- unsigned long id;
420+- int i, rv;
421+-
422+- assert(argc > 1);
423+- assert(argv != NULL);
424+-
425+-#define RPCPRINT printfmtstrings(re->r_aliases, " ", " ", \
426+- "%-16s %6d", \
427+- re->r_name, re->r_number)
428+-
429+- setrpcent(1);
430+- rv = RV_OK;
431+- if (argc == 2) {
432+- while ((re = getrpcent()) != NULL)
433+- RPCPRINT;
434+- } else {
435+- for (i = 2; i < argc; i++) {
436+- if (parsenum(argv[i], &id))
437+- re = getrpcbynumber((int)id);
438+- else
439+- re = getrpcbyname(argv[i]);
440+- if (re != NULL)
441+- RPCPRINT;
442+- else {
443+- rv = RV_NOTFOUND;
444+- break;
445+- }
446+- }
447+- }
448+- endrpcent();
449+- return rv;
450+-}
451+-
452+- /*
453+ * services
454+ */
455+
pkgs/os-specific/bsd/openbsd/default.nixnew file+42
@@ -0,0 +1,42 @@
1+{ fetchcvs, netBSDDerivation, compat, libcurses, libressl }:
2+
3+let
4+ fetchOpenBSD = path: version: sha256: fetchcvs {
5+ cvsRoot = "anoncvs@anoncvs.ca.openbsd.org:/cvs";
6+ module = "src/${path}";
7+ inherit sha256;
8+ tag = "OPENBSD_${builtins.replaceStrings ["."] ["_"] version}";
9+ };
10+
11+ # OpenBSD is a fork of NetBSD
12+ # We can build it with minimal changes
13+ openBSDDerivation = attrs: netBSDDerivation (attrs // {
14+ name = "${attrs.pname or (baseNameOf attrs.path)}-openbsd-${attrs.version}";
15+ src = fetchOpenBSD attrs.path attrs.version attrs.sha256;
16+ });
17+
18+in {
19+
20+ mg = openBSDDerivation {
21+ path = "usr.bin/mg";
22+ version = "6.3";
23+ sha256 = "0n3hwa81c2mcjwbmidrbvi1l25jh8hy939kqrigbv78jixpynffc";
24+ buildInputs = [ compat libcurses ];
25+ patchPhase = ''
26+ NIX_CFLAGS_COMPILE+=" -I$BSDSRCDIR/sys"
27+ '';
28+ extraPaths = [
29+ (fetchOpenBSD "sys/sys/tree.h" "6.3" "0rimh41wn9wz5m510zk9i27z3s450qqgq2k5xn8kp3885hygbcj9")
30+ (fetchOpenBSD "sys/sys/_null.h" "6.3" "0l2rgg9ai4ivfl07zmbqli19vnm3lj7qkxpikqplmzrfp36qpzgr")
31+ ];
32+ };
33+
34+ nc = openBSDDerivation {
35+ path = "usr.bin/nc";
36+ version = "6.3";
37+ sha256 = "0fmnh6ccxab0qvhmgspyd3wra1ps2516i0j6hwkvna2lcny20xvr";
38+ patches = [ ./nc.patch ];
39+ buildInputs = [ compat libressl ];
40+ };
41+
42+}
pkgs/os-specific/bsd/openbsd/nc.patchnew file+421
@@ -0,0 +1,421 @@
1+--- a/nc.1
2++++ b/nc.1
3+@@ -204,9 +204,6 @@ Proxy authentication is only supported f
4+ Specifies the source port
5+ .Nm
6+ should use, subject to privilege restrictions and availability.
7+-It is an error to use this option in conjunction with the
8+-.Fl l
9+-option.
10+ .It Fl R Ar CAfile
11+ Specifies the filename from which the root CA bundle for certificate
12+ verification is loaded, in PEM format.
13+@@ -258,6 +255,7 @@ For IPv4 TOS value
14+ may be one of
15+ .Ar critical ,
16+ .Ar inetcontrol ,
17++.Ar lowcost ,
18+ .Ar lowdelay ,
19+ .Ar netcontrol ,
20+ .Ar throughput ,
21+--- a/netcat.c
22++++ b/netcat.c
23+@@ -32,6 +32,8 @@
24+ * *Hobbit* <hobbit@avian.org>.
25+ */
26+
27++#define _GNU_SOURCE
28++
29+ #include <sys/types.h>
30+ #include <sys/socket.h>
31+ #include <sys/uio.h>
32+@@ -41,6 +43,49 @@
33+ #include <netinet/tcp.h>
34+ #include <netinet/ip.h>
35+ #include <arpa/telnet.h>
36++#ifdef __linux__
37++# include <linux/in6.h>
38++#endif
39++
40++#ifndef IPTOS_LOWDELAY
41++# define IPTOS_LOWDELAY 0x10
42++# define IPTOS_THROUGHPUT 0x08
43++# define IPTOS_RELIABILITY 0x04
44++# define IPTOS_LOWCOST 0x02
45++# define IPTOS_MINCOST IPTOS_LOWCOST
46++#endif /* IPTOS_LOWDELAY */
47++
48++# ifndef IPTOS_DSCP_AF11
49++# define IPTOS_DSCP_AF11 0x28
50++# define IPTOS_DSCP_AF12 0x30
51++# define IPTOS_DSCP_AF13 0x38
52++# define IPTOS_DSCP_AF21 0x48
53++# define IPTOS_DSCP_AF22 0x50
54++# define IPTOS_DSCP_AF23 0x58
55++# define IPTOS_DSCP_AF31 0x68
56++# define IPTOS_DSCP_AF32 0x70
57++# define IPTOS_DSCP_AF33 0x78
58++# define IPTOS_DSCP_AF41 0x88
59++# define IPTOS_DSCP_AF42 0x90
60++# define IPTOS_DSCP_AF43 0x98
61++# define IPTOS_DSCP_EF 0xb8
62++#endif /* IPTOS_DSCP_AF11 */
63++
64++#ifndef IPTOS_DSCP_CS0
65++# define IPTOS_DSCP_CS0 0x00
66++# define IPTOS_DSCP_CS1 0x20
67++# define IPTOS_DSCP_CS2 0x40
68++# define IPTOS_DSCP_CS3 0x60
69++# define IPTOS_DSCP_CS4 0x80
70++# define IPTOS_DSCP_CS5 0xa0
71++# define IPTOS_DSCP_CS6 0xc0
72++# define IPTOS_DSCP_CS7 0xe0
73++#endif /* IPTOS_DSCP_CS0 */
74++
75++#ifndef IPTOS_DSCP_EF
76++# define IPTOS_DSCP_EF 0xb8
77++#endif /* IPTOS_DSCP_EF */
78++
79+
80+ #include <err.h>
81+ #include <errno.h>
82+@@ -268,10 +315,14 @@ main(int argc, char *argv[])
83+ uflag = 1;
84+ break;
85+ case 'V':
86++# if defined(RT_TABLEID_MAX)
87+ rtableid = (int)strtonum(optarg, 0,
88+ RT_TABLEID_MAX, &errstr);
89+ if (errstr)
90+ errx(1, "rtable %s: %s", errstr, optarg);
91++# else
92++ errx(1, "no alternate routing table support available");
93++# endif
94+ break;
95+ case 'v':
96+ vflag = 1;
97+@@ -320,7 +371,11 @@ main(int argc, char *argv[])
98+ oflag = optarg;
99+ break;
100+ case 'S':
101++# if defined(TCP_MD5SIG)
102+ Sflag = 1;
103++# else
104++ errx(1, "no TCP MD5 signature support available");
105++# endif
106+ break;
107+ case 'T':
108+ errstr = NULL;
109+@@ -345,35 +400,23 @@ main(int argc, char *argv[])
110+ argc -= optind;
111+ argv += optind;
112+
113++# if defined(RT_TABLEID_MAX)
114+ if (rtableid >= 0)
115+ if (setrtable(rtableid) == -1)
116+ err(1, "setrtable");
117+-
118+- if (family == AF_UNIX) {
119+- if (pledge("stdio rpath wpath cpath tmppath unix", NULL) == -1)
120+- err(1, "pledge");
121+- } else if (Fflag && Pflag) {
122+- if (pledge("stdio inet dns sendfd tty", NULL) == -1)
123+- err(1, "pledge");
124+- } else if (Fflag) {
125+- if (pledge("stdio inet dns sendfd", NULL) == -1)
126+- err(1, "pledge");
127+- } else if (Pflag && usetls) {
128+- if (pledge("stdio rpath inet dns tty", NULL) == -1)
129+- err(1, "pledge");
130+- } else if (Pflag) {
131+- if (pledge("stdio inet dns tty", NULL) == -1)
132+- err(1, "pledge");
133+- } else if (usetls) {
134+- if (pledge("stdio rpath inet dns", NULL) == -1)
135+- err(1, "pledge");
136+- } else if (pledge("stdio inet dns", NULL) == -1)
137+- err(1, "pledge");
138++# endif
139+
140+ /* Cruft to make sure options are clean, and used properly. */
141+ if (argv[0] && !argv[1] && family == AF_UNIX) {
142+ host = argv[0];
143+ uport = NULL;
144++ } else if (!argv[0] && lflag) {
145++ if (sflag)
146++ errx(1, "cannot use -s and -l");
147++ if (pflag)
148++ errx(1, "cannot use -p and -l");
149++ if (zflag)
150++ errx(1, "cannot use -z and -l");
151+ } else if (argv[0] && !argv[1]) {
152+ if (!lflag)
153+ usage(1);
154+@@ -385,12 +428,6 @@ main(int argc, char *argv[])
155+ } else
156+ usage(1);
157+
158+- if (lflag && sflag)
159+- errx(1, "cannot use -s and -l");
160+- if (lflag && pflag)
161+- errx(1, "cannot use -p and -l");
162+- if (lflag && zflag)
163+- errx(1, "cannot use -z and -l");
164+ if (!lflag && kflag)
165+ errx(1, "must use -l with -k");
166+ if (uflag && usetls)
167+@@ -425,8 +462,8 @@ main(int argc, char *argv[])
168+ } else {
169+ strlcpy(unix_dg_tmp_socket_buf, "/tmp/nc.XXXXXXXXXX",
170+ UNIX_DG_TMP_SOCKET_SIZE);
171+- if (mktemp(unix_dg_tmp_socket_buf) == NULL)
172+- err(1, "mktemp");
173++ if (mkstemp(unix_dg_tmp_socket_buf) == -1)
174++ err(1, "mkstemp");
175+ unix_dg_tmp_socket = unix_dg_tmp_socket_buf;
176+ }
177+ }
178+@@ -901,8 +938,10 @@ remote_connect(const char *host, const c
179+ if (sflag || pflag) {
180+ struct addrinfo ahints, *ares;
181+
182++# if defined (SO_BINDANY)
183+ /* try SO_BINDANY, but don't insist */
184+ setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on));
185++# endif
186+ memset(&ahints, 0, sizeof(struct addrinfo));
187+ ahints.ai_family = res->ai_family;
188+ ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
189+@@ -994,9 +1033,15 @@ local_listen(char *host, char *port, str
190+ res->ai_protocol)) < 0)
191+ continue;
192+
193++ ret = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
194++ if (ret == -1)
195++ err(1, NULL);
196++
197++# if defined(SO_REUSEPORT)
198+ ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
199+ if (ret == -1)
200+ err(1, NULL);
201++# endif
202+
203+ set_common_sockopts(s, res->ai_family);
204+
205+@@ -1452,11 +1497,13 @@ set_common_sockopts(int s, int af)
206+ {
207+ int x = 1;
208+
209++# if defined(TCP_MD5SIG)
210+ if (Sflag) {
211+ if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
212+ &x, sizeof(x)) == -1)
213+ err(1, NULL);
214+ }
215++# endif
216+ if (Dflag) {
217+ if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
218+ &x, sizeof(x)) == -1)
219+@@ -1467,9 +1514,14 @@ set_common_sockopts(int s, int af)
220+ IP_TOS, &Tflag, sizeof(Tflag)) == -1)
221+ err(1, "set IP ToS");
222+
223++#if defined(IPV6_TCLASS)
224+ else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
225+ IPV6_TCLASS, &Tflag, sizeof(Tflag)) == -1)
226+ err(1, "set IPv6 traffic class");
227++#else
228++ else if (af == AF_INET6)
229++ errx(1, "can't set IPv6 traffic class (unavailable)");
230++#endif
231+ }
232+ if (Iflag) {
233+ if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
234+@@ -1487,19 +1539,34 @@ set_common_sockopts(int s, int af)
235+ IP_TTL, &ttl, sizeof(ttl)))
236+ err(1, "set IP TTL");
237+
238++#if defined(IPV6_UNICAST_HOPS)
239+ else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
240+ IPV6_UNICAST_HOPS, &ttl, sizeof(ttl)))
241+ err(1, "set IPv6 unicast hops");
242++#else
243++ else if (af == AF_INET6)
244++ errx(1, "can't set IPv6 unicast hops (unavailable)");
245++#endif
246+ }
247+
248+ if (minttl != -1) {
249++#if defined(IP_MINTTL)
250+ if (af == AF_INET && setsockopt(s, IPPROTO_IP,
251+ IP_MINTTL, &minttl, sizeof(minttl)))
252+ err(1, "set IP min TTL");
253++#else
254++ if (af == AF_INET)
255++ errx(1, "can't set IP min TTL (unavailable)");
256++#endif
257+
258++#if defined(IPV6_MINHOPCOUNT)
259+ else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
260+ IPV6_MINHOPCOUNT, &minttl, sizeof(minttl)))
261+ err(1, "set IPv6 min hop count");
262++#else
263++ else if (af == AF_INET6)
264++ errx(1, "can't set IPv6 min hop count (unavailable)");
265++#endif
266+ }
267+ }
268+
269+@@ -1534,6 +1601,7 @@ process_tos_opt(char *s, int *val)
270+ { "cs7", IPTOS_DSCP_CS7 },
271+ { "ef", IPTOS_DSCP_EF },
272+ { "inetcontrol", IPTOS_PREC_INTERNETCONTROL },
273++ { "lowcost", IPTOS_LOWCOST },
274+ { "lowdelay", IPTOS_LOWDELAY },
275+ { "netcontrol", IPTOS_PREC_NETCONTROL },
276+ { "reliability", IPTOS_RELIABILITY },
277+@@ -1741,7 +1812,7 @@ help(void)
278+ \t-Z Peer certificate file\n\
279+ \t-z Zero-I/O mode [used for scanning]\n\
280+ Port numbers can be individual or ranges: lo-hi [inclusive]\n");
281+- exit(1);
282++ exit(0);
283+ }
284+
285+ void
286+--- a/socks.c
287++++ b/socks.c
288+@@ -219,11 +219,11 @@ socks_connect(const char *host, const ch
289+ buf[2] = SOCKS_NOAUTH;
290+ cnt = atomicio(vwrite, proxyfd, buf, 3);
291+ if (cnt != 3)
292+- err(1, "write failed (%zu/3)", cnt);
293++ err(1, "write failed (%zu/3)", (size_t)cnt);
294+
295+ cnt = atomicio(read, proxyfd, buf, 2);
296+ if (cnt != 2)
297+- err(1, "read failed (%zu/3)", cnt);
298++ err(1, "read failed (%zu/3)", (size_t)cnt);
299+
300+ if (buf[1] == SOCKS_NOMETHOD)
301+ errx(1, "authentication method negotiation failed");
302+@@ -272,11 +272,11 @@ socks_connect(const char *host, const ch
303+
304+ cnt = atomicio(vwrite, proxyfd, buf, wlen);
305+ if (cnt != wlen)
306+- err(1, "write failed (%zu/%zu)", cnt, wlen);
307++ err(1, "write failed (%zu/%zu)", (size_t)cnt, (size_t)wlen);
308+
309+ cnt = atomicio(read, proxyfd, buf, 4);
310+ if (cnt != 4)
311+- err(1, "read failed (%zu/4)", cnt);
312++ err(1, "read failed (%zu/4)", (size_t)cnt);
313+ if (buf[1] != 0) {
314+ errx(1, "connection failed, SOCKSv5 error: %s",
315+ socks5_strerror(buf[1]));
316+@@ -285,12 +285,12 @@ socks_connect(const char *host, const ch
317+ case SOCKS_IPV4:
318+ cnt = atomicio(read, proxyfd, buf + 4, 6);
319+ if (cnt != 6)
320+- err(1, "read failed (%zu/6)", cnt);
321++ err(1, "read failed (%zu/6)", (size_t)cnt);
322+ break;
323+ case SOCKS_IPV6:
324+ cnt = atomicio(read, proxyfd, buf + 4, 18);
325+ if (cnt != 18)
326+- err(1, "read failed (%zu/18)", cnt);
327++ err(1, "read failed (%zu/18)", (size_t)cnt);
328+ break;
329+ default:
330+ errx(1, "connection failed, unsupported address type");
331+@@ -310,11 +310,11 @@ socks_connect(const char *host, const ch
332+
333+ cnt = atomicio(vwrite, proxyfd, buf, wlen);
334+ if (cnt != wlen)
335+- err(1, "write failed (%zu/%zu)", cnt, wlen);
336++ err(1, "write failed (%zu/%zu)", (size_t)cnt, (size_t)wlen);
337+
338+ cnt = atomicio(read, proxyfd, buf, 8);
339+ if (cnt != 8)
340+- err(1, "read failed (%zu/8)", cnt);
341++ err(1, "read failed (%zu/8)", (size_t)cnt);
342+ if (buf[1] != 90) {
343+ errx(1, "connection failed, SOCKSv4 error: %s",
344+ socks4_strerror(buf[1]));
345+@@ -328,39 +328,39 @@ socks_connect(const char *host, const ch
346+
347+ /* Try to be sane about numeric IPv6 addresses */
348+ if (strchr(host, ':') != NULL) {
349+- r = snprintf(buf, sizeof(buf),
350++ r = snprintf((char*)buf, sizeof(buf),
351+ "CONNECT [%s]:%d HTTP/1.0\r\n",
352+ host, ntohs(serverport));
353+ } else {
354+- r = snprintf(buf, sizeof(buf),
355++ r = snprintf((char*)buf, sizeof(buf),
356+ "CONNECT %s:%d HTTP/1.0\r\n",
357+ host, ntohs(serverport));
358+ }
359+ if (r == -1 || (size_t)r >= sizeof(buf))
360+ errx(1, "hostname too long");
361+- r = strlen(buf);
362++ r = strlen((char*)buf);
363+
364+ cnt = atomicio(vwrite, proxyfd, buf, r);
365+ if (cnt != r)
366+- err(1, "write failed (%zu/%d)", cnt, r);
367++ err(1, "write failed (%zu/%d)", (size_t)cnt, (int)r);
368+
369+ if (authretry > 1) {
370+ char resp[1024];
371+
372+ proxypass = getproxypass(proxyuser, proxyhost);
373+- r = snprintf(buf, sizeof(buf), "%s:%s",
374++ r = snprintf((char*)buf, sizeof(buf), "%s:%s",
375+ proxyuser, proxypass);
376+ if (r == -1 || (size_t)r >= sizeof(buf) ||
377+- b64_ntop(buf, strlen(buf), resp,
378++ b64_ntop(buf, strlen((char*)buf), resp,
379+ sizeof(resp)) == -1)
380+ errx(1, "Proxy username/password too long");
381+- r = snprintf(buf, sizeof(buf), "Proxy-Authorization: "
382++ r = snprintf((char*)buf, sizeof(buf), "Proxy-Authorization: "
383+ "Basic %s\r\n", resp);
384+ if (r == -1 || (size_t)r >= sizeof(buf))
385+ errx(1, "Proxy auth response too long");
386+- r = strlen(buf);
387++ r = strlen((char*)buf);
388+ if ((cnt = atomicio(vwrite, proxyfd, buf, r)) != r)
389+- err(1, "write failed (%zu/%d)", cnt, r);
390++ err(1, "write failed (%zu/%d)", (size_t)cnt, r);
391+ }
392+
393+ /* Terminate headers */
394+@@ -368,22 +368,22 @@ socks_connect(const char *host, const ch
395+ err(1, "write failed (%zu/2)", cnt);
396+
397+ /* Read status reply */
398+- proxy_read_line(proxyfd, buf, sizeof(buf));
399++ proxy_read_line(proxyfd, (char*)buf, sizeof(buf));
400+ if (proxyuser != NULL &&
401+- strncmp(buf, "HTTP/1.0 407 ", 12) == 0) {
402++ strncmp((char*)buf, "HTTP/1.0 407 ", 12) == 0) {
403+ if (authretry > 1) {
404+ fprintf(stderr, "Proxy authentication "
405+ "failed\n");
406+ }
407+ close(proxyfd);
408+ goto again;
409+- } else if (strncmp(buf, "HTTP/1.0 200 ", 12) != 0 &&
410+- strncmp(buf, "HTTP/1.1 200 ", 12) != 0)
411++ } else if (strncmp((char*)buf, "HTTP/1.0 200 ", 12) != 0 &&
412++ strncmp((char*)buf, "HTTP/1.1 200 ", 12) != 0)
413+ errx(1, "Proxy error: \"%s\"", buf);
414+
415+ /* Headers continue until we hit an empty line */
416+ for (r = 0; r < HTTP_MAXHDRS; r++) {
417+- proxy_read_line(proxyfd, buf, sizeof(buf));
418++ proxy_read_line(proxyfd, (char*)buf, sizeof(buf));
419+ if (*buf == '\0')
420+ break;
421+ }
pkgs/top-level/all-packages.nix+3
@@ -21364,4 +21364,7 @@ with pkgs;
2136421364 unixtools = recurseIntoAttrs (callPackages ./unix-tools.nix { });
2136521365 inherit (unixtools) hexdump ps logger eject umount
2136621366 mount wall hostname more sysctl;
21367+
21368+ inherit (recurseIntoAttrs (callPackages ../os-specific/bsd { }))
21369+ netbsd openbsd;
2136721370}