···11+{ lib
22+, stdenv
33+, fetchgit
44+, pkg-config
55+, patches ? [ ]
66+, pkgsBuildHost
77+, enableStatic ? stdenv.hostPlatform.isStatic
88+}:
99+1010+stdenv.mkDerivation {
1111+ pname = "9base";
1212+ version = "unstable-2019-09-11";
1313+1414+ src = fetchgit {
1515+ url = "https://git.suckless.org/9base";
1616+ rev = "63916da7bd6d73d9a405ce83fc4ca34845667cce";
1717+ hash = "sha256-CNK7Ycmcl5vkmtA5VKwKxGZz8AoIG1JH/LTKoYmWSBI=";
1818+ };
1919+2020+ patches = [
2121+ # expects to be used with getcallerpc macro or stub patch
2222+ # AR env var is now the location of `ar` not including the arg (`ar rc`)
2323+ ./config-substitutions.patch
2424+ ./dont-strip.patch
2525+ # plan9port dropped their own getcallerpc implementations
2626+ # in favour of using gcc/clang's macros or a stub
2727+ # we can do this here too to extend platform support
2828+ # https://github.com/9fans/plan9port/commit/540caa5873bcc3bc2a0e1896119f5b53a0e8e630
2929+ # https://github.com/9fans/plan9port/commit/323e1a8fac276f008e6d5146a83cbc88edeabc87
3030+ ./getcallerpc-use-macro-or-stub.patch
3131+ ] ++ patches;
3232+3333+ # the 9yacc script needs to be executed to build other items
3434+ preBuild = lib.optionalString (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
3535+ substituteInPlace ./yacc/9yacc \
3636+ --replace "../yacc/yacc" "${lib.getExe' pkgsBuildHost._9base "yacc"}"
3737+ '';
3838+3939+ enableParallelBuilding = true;
4040+ strictDeps = true;
4141+ nativeBuildInputs = [ pkg-config ];
4242+ NIX_CFLAGS_COMPILE = [
4343+ # workaround build failure on -fno-common toolchains like upstream
4444+ # gcc-10. Otherwise build fails as:
4545+ # ld: diffio.o:(.bss+0x16): multiple definition of `bflag'; diffdir.o:(.bss+0x6): first defined here
4646+ "-fcommon"
4747+ # hide really common warning that floods the logs:
4848+ # warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
4949+ "-D_DEFAULT_SOURCE"
5050+ ];
5151+ LDFLAGS = lib.optionalString enableStatic "-static";
5252+ makeFlags = [
5353+ "PREFIX=${placeholder "out"}"
5454+ ];
5555+ installFlags = [
5656+ "PREFIX_TROFF=${placeholder "troff"}"
5757+ ];
5858+5959+ outputs = [ "out" "man" "troff" ];
6060+6161+ meta = with lib; {
6262+ homepage = "https://tools.suckless.org/9base/";
6363+ description = "9base is a port of various original Plan 9 tools for Unix, based on plan9port";
6464+ longDescription = ''
6565+ 9base is a port of various original Plan 9 tools for Unix, based on plan9port.
6666+ It also contains the Plan 9 libc, libbio, libregexp, libfmt and libutf.
6767+ The overall SLOC is about 66kSLOC, so this userland + all libs is much smaller than, e.g. bash.
6868+ 9base can be used to run werc instead of the full blown plan9port.
6969+ '';
7070+ license = with licenses; [ mit /* and */ lpl-102 ];
7171+ maintainers = with maintainers; [ jk ];
7272+ platforms = platforms.unix;
7373+ # needs additional work to support aarch64-darwin
7474+ # due to usage of _DARWIN_NO_64_BIT_INODE
7575+ broken = stdenv.isAarch64 && stdenv.isDarwin;
7676+ };
7777+}