diff --git a/pkgs/applications/science/physics/xfitter/default.nix b/pkgs/applications/science/physics/xfitter/default.nix index 230f2f0e0efb..51d6c9d68fe4 100644 --- a/pkgs/applications/science/physics/xfitter/default.nix +++ b/pkgs/applications/science/physics/xfitter/default.nix @@ -1,5 +1,6 @@ { lib, stdenv, fetchurl, apfel, apfelgrid, applgrid, blas, gfortran, lhapdf, lapack, libyaml, lynx , mela, root5, qcdnum, which, libtirpc +, memorymappingHook, memstreamHook }: stdenv.mkDerivation rec { @@ -36,9 +37,8 @@ stdenv.mkDerivation rec { nativeBuildInputs = [ gfortran which ]; buildInputs = - [ apfel apfelgrid applgrid blas lhapdf lapack mela root5 qcdnum ] - # pdf2yaml requires fmemopen and open_memstream which are not readily available on Darwin - ++ lib.optional (!stdenv.isDarwin) libyaml + [ apfel apfelgrid applgrid blas lhapdf libyaml lapack mela root5 qcdnum ] + ++ lib.optionals (stdenv.system == "x86_64-darwin") [ memorymappingHook memstreamHook ] ++ lib.optional (stdenv.hostPlatform.libc == "glibc") libtirpc ; propagatedBuildInputs = [ lynx ]; diff --git a/pkgs/development/libraries/memorymapping/default.nix b/pkgs/development/libraries/memorymapping/default.nix new file mode 100644 index 000000000000..ebab23fe471e --- /dev/null +++ b/pkgs/development/libraries/memorymapping/default.nix @@ -0,0 +1,43 @@ +{ lib, stdenv, fetchFromGitHub }: + +stdenv.mkDerivation { + pname = "memorymapping"; + version = "unstable-2014-02-20"; + + src = fetchFromGitHub { + owner = "NimbusKit"; + repo = "memorymapping"; + rev = "fc285afe13cb9d56a40c647b8ed6d6bd40636af7"; + sha256 = "sha256-9u/QvK9TDsKxcubINH2OAbx5fXXkKF0+YT7LoLDaF0M="; + }; + + dontConfigure = true; + + buildPhase = '' + runHook preBuild + + $CC -c src/fmemopen.c + $AR rcs libmemorymapping.a fmemopen.o + sed -e '1i#include ' -i src/fmemopen.h + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + install -D libmemorymapping.a "$out"/lib/libmemorymapping.a + install -D src/fmemopen.h "$out"/include/fmemopen.h + + runHook postInstall + ''; + + meta = with lib; { + homepage = "https://nimbuskit.github.io/memorymapping/"; + description = "fmemopen for Mac OS and iOS"; + license = licenses.asl20; + maintainers = with maintainers; [ veprbl ]; + platforms = platforms.unix; + broken = stdenv.isAarch64; + }; +} diff --git a/pkgs/development/libraries/memorymapping/setup-hook.sh b/pkgs/development/libraries/memorymapping/setup-hook.sh new file mode 100644 index 000000000000..5ee3470fe370 --- /dev/null +++ b/pkgs/development/libraries/memorymapping/setup-hook.sh @@ -0,0 +1,6 @@ +useMemorymapping () { + export NIX_CFLAGS_COMPILE="${NIX_CFLAGS_COMPILE-}${NIX_CFLAGS_COMPILE:+ }-include fmemopen.h"; + export NIX_LDFLAGS="${NIX_LDFLAGS-}${NIX_LDFLAGS:+ }-lmemorymapping"; +} + +postHooks+=(useMemorymapping) diff --git a/pkgs/development/libraries/memstream/default.nix b/pkgs/development/libraries/memstream/default.nix new file mode 100644 index 000000000000..90505a56a931 --- /dev/null +++ b/pkgs/development/libraries/memstream/default.nix @@ -0,0 +1,43 @@ +{ lib, stdenv, fetchurl }: + +stdenv.mkDerivation rec { + pname = "memstream"; + version = "0.1"; + + src = fetchurl { + url = "https://piumarta.com/software/memstream/memstream-${version}.tar.gz"; + sha256 = "0kvdb897g7nyviaz72arbqijk2g2wa61cmi3l5yh48rzr49r3a3a"; + }; + + dontConfigure = true; + + postBuild = '' + $AR rcs libmemstream.a memstream.o + ''; + + doCheck = true; + checkPhase = '' + runHook preCheck + + ./test | grep "This is a test of memstream" + + runHook postCheck + ''; + + installPhase = '' + runHook preInstall + + install -D libmemstream.a "$out"/lib/libmemstream.a + install -D memstream.h "$out"/include/memstream.h + + runHook postInstall + ''; + + meta = with lib; { + homepage = "https://www.piumarta.com/software/memstream/"; + description = "memstream.c is an implementation of the POSIX function open_memstream() for BSD and BSD-like operating systems"; + license = licenses.mit; + maintainers = with maintainers; [ veprbl ]; + platforms = platforms.unix; + }; +} diff --git a/pkgs/development/libraries/memstream/setup-hook.sh b/pkgs/development/libraries/memstream/setup-hook.sh new file mode 100644 index 000000000000..09aabe748841 --- /dev/null +++ b/pkgs/development/libraries/memstream/setup-hook.sh @@ -0,0 +1,6 @@ +useMemstream () { + export NIX_CFLAGS_COMPILE="${NIX_CFLAGS_COMPILE-}${NIX_CFLAGS_COMPILE:+ }-include memstream.h"; + export NIX_LDFLAGS="${NIX_LDFLAGS-}${NIX_LDFLAGS:+ }-lmemstream"; +} + +postHooks+=(useMemstream) diff --git a/pkgs/games/tintin/default.nix b/pkgs/games/tintin/default.nix index 73070db244f0..b813900ca39f 100644 --- a/pkgs/games/tintin/default.nix +++ b/pkgs/games/tintin/default.nix @@ -1,4 +1,5 @@ { stdenv, fetchurl, lib, zlib, pcre +, memorymappingHook, memstreamHook , tlsSupport ? true, gnutls ? null # ^ set { tlsSupport = false; } to reduce closure size by ~= 18.6 MB }: @@ -15,7 +16,9 @@ stdenv.mkDerivation rec { }; nativeBuildInputs = lib.optional tlsSupport gnutls.dev; - buildInputs = [ zlib pcre ] ++ lib.optional tlsSupport gnutls; + buildInputs = [ zlib pcre ] + ++ lib.optionals (stdenv.system == "x86_64-darwin") [ memorymappingHook memstreamHook ] + ++ lib.optional tlsSupport gnutls; preConfigure = '' cd src diff --git a/pkgs/tools/text/hyx/default.nix b/pkgs/tools/text/hyx/default.nix index c2b055be7df9..c287b37dd1b5 100644 --- a/pkgs/tools/text/hyx/default.nix +++ b/pkgs/tools/text/hyx/default.nix @@ -1,11 +1,5 @@ -{ lib, stdenv, fetchurl }: -let - # memstream — POSIX memory streams for BSD - memstream = fetchurl { - url = "https://piumarta.com/software/memstream/memstream-0.1.tar.gz"; - sha256 = "0kvdb897g7nyviaz72arbqijk2g2wa61cmi3l5yh48rzr49r3a3a"; - }; -in +{ lib, stdenv, fetchurl, memstreamHook }: + stdenv.mkDerivation rec { pname = "hyx"; version = "2020-06-09"; @@ -15,11 +9,12 @@ stdenv.mkDerivation rec { sha256 = "1x8dmll93hrnj24kn5knpwj36y6r1v2ygwynpjwrg2hwd4c1a8hi"; }; - postUnpack = lib.optionalString stdenv.isDarwin '' - tar --strip=1 -C $sourceRoot -xf ${memstream} --wildcards "memstream-0.1/memstream.[hc]" + postPatch = lib.optionalString stdenv.isDarwin '' + substituteInPlace Makefile \ + --replace "-Wl,-z,relro,-z,now -fpic -pie" "" ''; - patches = lib.optional stdenv.isDarwin ./memstream.patch; + buildInputs = lib.optional (stdenv.system == "x86_64-darwin") memstreamHook; installPhase = '' install -vD hyx $out/bin/hyx diff --git a/pkgs/tools/text/hyx/memstream.patch b/pkgs/tools/text/hyx/memstream.patch deleted file mode 100644 index a02509ced762..000000000000 --- a/pkgs/tools/text/hyx/memstream.patch +++ /dev/null @@ -1,31 +0,0 @@ -diff -Naur hyx-2020.06.09.org/Makefile hyx-2020.06.09/Makefile ---- hyx-2020.06.09.org/Makefile 2020-06-09 15:19:50.000000000 +0300 -+++ hyx-2020.06.09/Makefile 2020-07-22 11:46:40.000000000 +0300 -@@ -1,6 +1,6 @@ - - all: CFLAGS ?= -O2 -Wl,-s \ -- -Wl,-z,relro,-z,now -fpic -pie -D_FORTIFY_SOURCE=2 -fstack-protector-all -+ -D_FORTIFY_SOURCE=2 -fstack-protector-all - all: CFLAGS += -std=c99 -pedantic -Wall -Wextra -DNDEBUG - all: hyx - -@@ -13,7 +13,7 @@ - hyx: *.h *.c - $(CC) \ - $(CFLAGS) \ -- hyx.c common.c blob.c history.c view.c input.c \ -+ hyx.c common.c blob.c history.c view.c input.c memstream.c \ - -o hyx - - clean: -diff -Naur hyx-2020.06.09.org/view.c hyx-2020.06.09/view.c ---- hyx-2020.06.09.org/view.c 2020-06-09 15:19:50.000000000 +0300 -+++ hyx-2020.06.09/view.c 2020-07-22 11:49:09.000000000 +0300 -@@ -4,6 +4,7 @@ - #include "view.h" - #include "input.h" - #include "ansi.h" -+#include "memstream.h" - - #include - #include diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index a8fe12adc5ad..61132b5c4924 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -17896,6 +17896,16 @@ with pkgs; mediastreamer-openh264 = callPackage ../development/libraries/mediastreamer/msopenh264.nix { }; + memorymapping = callPackage ../development/libraries/memorymapping { }; + memorymappingHook = makeSetupHook { + deps = [ memorymapping ]; + } ../development/libraries/memorymapping/setup-hook.sh; + + memstream = callPackage ../development/libraries/memstream { }; + memstreamHook = makeSetupHook { + deps = [ memstream ]; + } ../development/libraries/memstream/setup-hook.sh; + menu-cache = callPackage ../development/libraries/menu-cache { }; mergerfs = callPackage ../tools/filesystems/mergerfs { };