2022-01-24 19:42:41 +00:00
{
description = " n i x f l a k e f o r s i m p l e x - c h a t " ;
2022-03-01 07:01:52 +00:00
inputs . nixpkgs . url = " g i t h u b : n i x o s / n i x p k g s / n i x p k g s - u n s t a b l e " ; #angerman/nixpkgs/patch-1"; # based on 21.11, still need this, until everything is merged into 21.11.
inputs . haskellNix . url = " g i t h u b : i n p u t - o u t p u t - h k / h a s k e l l . n i x ? r e f = a n g e r m a n / t r y - n o - l i b c h a r s e t " ;
2022-01-24 19:42:41 +00:00
inputs . haskellNix . inputs . nixpkgs . follows = " n i x p k g s " ;
2022-07-19 13:34:03 +01:00
inputs . hackage = {
url = " g i t h u b : i n p u t - o u t p u t - h k / h a c k a g e . n i x " ;
flake = false ;
} ;
inputs . haskellNix . inputs . hackage . follows = " h a c k a g e " ;
2022-01-24 19:42:41 +00:00
inputs . flake-utils . url = " g i t h u b : n u m t i d e / f l a k e - u t i l s " ;
2022-07-19 13:34:03 +01:00
outputs = { self , haskellNix , nixpkgs , flake-utils , . . . }:
2022-01-24 19:42:41 +00:00
let systems = [ " x 8 6 _ 6 4 - l i n u x " " x 8 6 _ 6 4 - d a r w i n " " a a r c h 6 4 - l i n u x " " a a r c h 6 4 - d a r w i n " ] ; in
flake-utils . lib . eachSystem systems ( system :
let pkgs = haskellNix . legacyPackages . ${ system } ; in
2022-04-07 16:12:54 +08:00
let drv' = { extra-modules , pkgs' , . . . }: pkgs' . haskell-nix . project {
2022-01-24 19:42:41 +00:00
compiler-nix-name = " g h c 8 1 0 7 " ;
2022-07-19 13:34:03 +01:00
index-state = " 2 0 2 2 - 0 6 - 2 0 T 0 0 : 0 0 : 0 0 Z " ;
2022-01-24 19:42:41 +00:00
# We need this, to specify we want the cabal project.
# If the stack.yaml was dropped, this would not be necessary.
projectFileName = " c a b a l . p r o j e c t " ;
src = pkgs . haskell-nix . haskellLib . cleanGit {
name = " s i m p l e x - c h a t " ;
src = ./. ;
} ;
2022-04-11 15:53:44 +01:00
sha256map = import ./scripts/nix/sha256map.nix ;
2022-01-24 19:42:41 +00:00
modules = [ {
2022-04-11 15:53:44 +01:00
packages . direct-sqlite . patches = [ ./scripts/nix/direct-sqlite-2.3.26.patch ] ;
packages . entropy . patches = [ ./scripts/nix/entropy.patch ] ;
2022-01-24 19:42:41 +00:00
}
( { pkgs , lib , . . . }: lib . mkIf ( pkgs . stdenv . hostPlatform . isAndroid ) {
packages . simplex-chat . components . library . ghcOptions = [ " - p i e " ] ;
2022-04-07 16:12:54 +08:00
} ) ] ++ extra-modules ;
2022-01-24 19:42:41 +00:00
} ; in
2022-04-07 16:12:54 +08:00
# by defualt we don't need to pass extra-modules.
2022-04-07 10:33:32 +01:00
let drv = pkgs' : drv' { extra-modules = [ ] ; inherit pkgs' ; } ; in
2022-01-24 19:42:41 +00:00
# This will package up all *.a in $out into a pkg.zip that can
# be downloaded from hydra.
let withHydraLibPkg = pkg : pkg . overrideAttrs ( old : {
postInstall = ''
mkdir - p $ out/_pkg
find $ out/lib - name " * . a " - exec cp { } $ out/_pkg \ ;
( cd $ out/_pkg ; $ { pkgs . zip } /bin/zip - r -9 $ out/pkg.zip * )
rm - fR $ out/_pkg
mkdir - p $ out/nix-support
echo " f i l e b i n a r y - d i s t \" $ ( e c h o $ o u t / * . z i p ) \" " \
> $ out/nix-support/hydra-build-products
'' ;
} ) ; in
rec {
packages = {
" l i b : s i m p l e x - c h a t " = ( drv pkgs ) . simplex-chat . components . library ;
" e x e : s i m p l e x - c h a t " = ( drv pkgs ) . simplex-chat . components . exes . simplex-chat ;
} // ( {
" x 8 6 _ 6 4 - l i n u x " =
2022-02-28 13:52:20 +00:00
let
androidPkgs = pkgs . pkgsCross . aarch64-android ;
# For some reason building libiconv with nixpgks android setup produces
# LANGINFO_CODESET to be found, which is not compatible with android sdk 23;
# so we'll patch up iconv to not include that.
androidIconv = ( androidPkgs . libiconv . override { enableStatic = true ; } ) . overrideAttrs ( old : {
postConfigure = ''
echo " # u n d e f H A V E _ L A N G I N F O _ C O D E S E T " > > libcharset/config.h
echo " # u n d e f H A V E _ L A N G I N F O _ C O D E S E T " > > lib/config.h
'' ;
} ) ;
# Similarly to icovn, for reasons beyond my current knowledge, nixpkgs andorid
# toolchain makes configure believe we have MEMFD_CREATE, which we don't in
# sdk 23.
androidFFI = androidPkgs . libffi . overrideAttrs ( old : {
dontDisableStatic = true ;
hardeningDisable = [ " f o r t i f y " ] ;
postConfigure = ''
echo " # u n d e f H A V E _ M E M F D _ C R E A T E " > > aarch64-unknown-linux-android/fficonfig.h
'' ;
}
) ; in {
" a a r c h 6 4 - a n d r o i d : l i b : s u p p o r t " = ( drv androidPkgs ) . android-support . components . library . override {
smallAddressSpace = true ; enableShared = false ;
setupBuildFlags = map ( x : " - - g h c - o p t i o n = ${ x } " ) [ " - s h a r e d " " - o " " l i b s u p p o r t . s o " ] ;
postInstall = ''
2022-01-24 19:42:41 +00:00
2022-02-28 13:52:20 +00:00
mkdir - p $ out/_pkg
cp libsupport . so $ out/_pkg
$ { pkgs . patchelf } /bin/patchelf - - remove-needed libunwind . so .1 $ out/_pkg/libsupport.so
( cd $ out/_pkg ; $ { pkgs . zip } /bin/zip - r -9 $ out/pkg-aarch64-android-libsupport.zip * )
rm - fR $ out/_pkg
2022-01-24 19:42:41 +00:00
2022-02-28 13:52:20 +00:00
mkdir - p $ out/nix-support
echo " f i l e b i n a r y - d i s t \" $ ( e c h o $ o u t / * . z i p ) \" " \
> $ out/nix-support/hydra-build-products
'' ;
} ;
" a a r c h 6 4 - a n d r o i d : l i b : s i m p l e x - c h a t " = ( drv androidPkgs ) . simplex-chat . components . library . override {
smallAddressSpace = true ; enableShared = false ;
# for android we build a shared library, passing these arguments is a bit tricky, as
# we want only the threaded rts (HSrts_thr) and ffi to be linked, but not fed into iserv for
# template haskell cross compilation. Thus we just pass them as linker options (-optl).
setupBuildFlags = map ( x : " - - g h c - o p t i o n = ${ x } " ) [ " - s h a r e d " " - o " " l i b s i m p l e x . s o " " - o p t l - l H S r t s _ t h r " " - o p t l - l f f i " ] ;
postInstall = ''
$ { pkgs . tree } /bin/tree $ out
mkdir - p $ out/_pkg
# copy over includes, we might want those, but maybe not.
# cp -r $out/lib/*/*/include $out/_pkg/
# find the libHS...ghc-X.Y.Z.a static library; this is the
# rolled up one with all dependencies included.
cp libsimplex . so $ out/_pkg
# find ./dist -name "lib*.so" -exec cp {} $out/_pkg \;
# find ./dist -name "libHS*-ghc*.a" -exec cp {} $out/_pkg \;
# find ${androidFFI}/lib -name "*.a" -exec cp {} $out/_pkg \;
# find ${androidPkgs.gmp6.override { withStatic = true; }}/lib -name "*.a" -exec cp {} $out/_pkg \;
# find ${androidIconv}/lib -name "*.a" -exec cp {} $out/_pkg \;
# find ${androidPkgs.stdenv.cc.libc}/lib -name "*.a" -exec cp {} $out/_pkg \;
2022-01-24 19:42:41 +00:00
2022-02-28 13:52:20 +00:00
$ { pkgs . patchelf } /bin/patchelf - - remove-needed libunwind . so .1 $ out/_pkg/libsimplex.so
2022-01-24 19:42:41 +00:00
2022-02-28 13:52:20 +00:00
$ { pkgs . tree } /bin/tree $ out/_pkg
( cd $ out/_pkg ; $ { pkgs . zip } /bin/zip - r -9 $ out/pkg-aarch64-android-libsimplex.zip * )
rm - fR $ out/_pkg
mkdir - p $ out/nix-support
echo " f i l e b i n a r y - d i s t \" $ ( e c h o $ o u t / * . z i p ) \" " \
> $ out/nix-support/hydra-build-products
'' ;
} ;
" x 8 6 _ 6 4 - a n d r o i d : l i b : s u p p o r t " = ( drv androidPkgs ) . android-support . components . library . override {
smallAddressSpace = true ; enableShared = false ;
setupBuildFlags = map ( x : " - - g h c - o p t i o n = ${ x } " ) [ " - s h a r e d " " - o " " l i b s u p p o r t . s o " ] ;
postInstall = ''
mkdir - p $ out/_pkg
cp libsupport . so $ out/_pkg
$ { pkgs . patchelf } /bin/patchelf - - remove-needed libunwind . so .1 $ out/_pkg/libsupport.so
( cd $ out/_pkg ; $ { pkgs . zip } /bin/zip - r -9 $ out/pkg-x86_64-android-libsupport.zip * )
rm - fR $ out/_pkg
mkdir - p $ out/nix-support
echo " f i l e b i n a r y - d i s t \" $ ( e c h o $ o u t / * . z i p ) \" " \
> $ out/nix-support/hydra-build-products
'' ;
} ;
" x 8 6 _ 6 4 - a n d r o i d : l i b : s i m p l e x - c h a t " = ( drv androidPkgs ) . simplex-chat . components . library . override {
smallAddressSpace = true ; enableShared = false ;
# for android we build a shared library, passing these arguments is a bit tricky, as
# we want only the threaded rts (HSrts_thr) and ffi to be linked, but not fed into iserv for
# template haskell cross compilation. Thus we just pass them as linker options (-optl).
setupBuildFlags = map ( x : " - - g h c - o p t i o n = ${ x } " ) [ " - s h a r e d " " - o " " l i b s i m p l e x . s o " " - o p t l - l H S r t s _ t h r " " - o p t l - l f f i " ] ;
postInstall = ''
$ { pkgs . tree } /bin/tree $ out
mkdir - p $ out/_pkg
# copy over includes, we might want those, but maybe not.
# cp -r $out/lib/*/*/include $out/_pkg/
# find the libHS...ghc-X.Y.Z.a static library; this is the
# rolled up one with all dependencies included.
cp libsimplex . so $ out/_pkg
# find ./dist -name "lib*.so" -exec cp {} $out/_pkg \;
# find ./dist -name "libHS*-ghc*.a" -exec cp {} $out/_pkg \;
# find ${androidFFI}/lib -name "*.a" -exec cp {} $out/_pkg \;
# find ${androidPkgs.gmp6.override { withStatic = true; }}/lib -name "*.a" -exec cp {} $out/_pkg \;
# find ${androidIconv}/lib -name "*.a" -exec cp {} $out/_pkg \;
# find ${androidPkgs.stdenv.cc.libc}/lib -name "*.a" -exec cp {} $out/_pkg \;
$ { pkgs . patchelf } /bin/patchelf - - remove-needed libunwind . so .1 $ out/_pkg/libsimplex.so
$ { pkgs . tree } /bin/tree $ out/_pkg
( cd $ out/_pkg ; $ { pkgs . zip } /bin/zip - r -9 $ out/pkg-x86_64-android-libsimplex.zip * )
rm - fR $ out/_pkg
mkdir - p $ out/nix-support
echo " f i l e b i n a r y - d i s t \" $ ( e c h o $ o u t / * . z i p ) \" " \
> $ out/nix-support/hydra-build-products
'' ;
} ;
" x 8 6 _ 6 4 - l i n u x : l i b : s u p p o r t " = ( drv androidPkgs ) . android-support . components . library . override {
smallAddressSpace = true ; enableShared = false ;
setupBuildFlags = map ( x : " - - g h c - o p t i o n = ${ x } " ) [ " - s h a r e d " " - o " " l i b s u p p o r t . s o " ] ;
postInstall = ''
mkdir - p $ out/_pkg
cp libsupport . so $ out/_pkg
$ { pkgs . patchelf } /bin/patchelf - - remove-needed libunwind . so .1 $ out/_pkg/libsupport.so
( cd $ out/_pkg ; $ { pkgs . zip } /bin/zip - r -9 $ out/pkg-x86_64-linux-libsupport.zip * )
rm - fR $ out/_pkg
mkdir - p $ out/nix-support
echo " f i l e b i n a r y - d i s t \" $ ( e c h o $ o u t / * . z i p ) \" " \
> $ out/nix-support/hydra-build-products
'' ;
} ;
" x 8 6 _ 6 4 - l i n u x : l i b : s i m p l e x - c h a t " = ( drv androidPkgs ) . simplex-chat . components . library . override {
smallAddressSpace = true ; enableShared = false ;
# for android we build a shared library, passing these arguments is a bit tricky, as
# we want only the threaded rts (HSrts_thr) and ffi to be linked, but not fed into iserv for
# template haskell cross compilation. Thus we just pass them as linker options (-optl).
setupBuildFlags = map ( x : " - - g h c - o p t i o n = ${ x } " ) [ " - s h a r e d " " - o " " l i b s i m p l e x . s o " " - o p t l - l H S r t s _ t h r " " - o p t l - l f f i " ] ;
postInstall = ''
$ { pkgs . tree } /bin/tree $ out
mkdir - p $ out/_pkg
# copy over includes, we might want those, but maybe not.
# cp -r $out/lib/*/*/include $out/_pkg/
# find the libHS...ghc-X.Y.Z.a static library; this is the
# rolled up one with all dependencies included.
cp libsimplex . so $ out/_pkg
# find ./dist -name "lib*.so" -exec cp {} $out/_pkg \;
# find ./dist -name "libHS*-ghc*.a" -exec cp {} $out/_pkg \;
# find ${androidFFI}/lib -name "*.a" -exec cp {} $out/_pkg \;
# find ${androidPkgs.gmp6.override { withStatic = true; }}/lib -name "*.a" -exec cp {} $out/_pkg \;
# find ${androidIconv}/lib -name "*.a" -exec cp {} $out/_pkg \;
# find ${androidPkgs.stdenv.cc.libc}/lib -name "*.a" -exec cp {} $out/_pkg \;
$ { pkgs . patchelf } /bin/patchelf - - remove-needed libunwind . so .1 $ out/_pkg/libsimplex.so
$ { pkgs . tree } /bin/tree $ out/_pkg
( cd $ out/_pkg ; $ { pkgs . zip } /bin/zip - r -9 $ out/pkg-x86_64-linux-libsimplex.zip * )
rm - fR $ out/_pkg
mkdir - p $ out/nix-support
echo " f i l e b i n a r y - d i s t \" $ ( e c h o $ o u t / * . z i p ) \" " \
> $ out/nix-support/hydra-build-products
'' ;
} ;
} ;
2022-01-24 19:42:41 +00:00
" a a r c h 6 4 - d a r w i n " = {
2022-04-07 16:12:54 +08:00
# this is the aarch64-darwin iOS build (to be patched with mac2ios)
2022-09-02 11:26:14 +01:00
" a a r c h 6 4 - d a r w i n - i o s : l i b : s i m p l e x - c h a t " = ( drv' {
pkgs' = pkgs ;
extra-modules = [ {
packages . simplexmq . flags . swift = true ;
packages . direct-sqlcipher . flags . commoncrypto = true ;
} ] ;
} ) . simplex-chat . components . library . override {
2022-02-16 13:38:49 +04:00
smallAddressSpace = true ; enableShared = false ;
# we need threaded here, otherwise all the queing logic doesn't work properly.
# for iOS we also use -staticlib, to get one rolled up library.
# still needs mac2ios patching of the archives.
2022-02-17 08:40:08 +00:00
ghcOptions = [ " - s t a t i c l i b " " - t h r e a d e d " " - D I O S " ] ;
2022-02-16 13:38:49 +04:00
postInstall = ''
$ { pkgs . tree } /bin/tree $ out
mkdir - p $ out/_pkg
# copy over includes, we might want those, but maybe not.
# cp -r $out/lib/*/*/include $out/_pkg/
# find the libHS...ghc-X.Y.Z.a static library; this is the
# rolled up one with all dependencies included.
find ./dist - name " l i b H S * . a " - exec cp { } $ out/_pkg \ ;
find $ { pkgs . libffi . overrideAttrs ( old : { dontDisableStatic = true ; } ) } /lib - name " * . a " - exec cp { } $ out/_pkg \ ;
find $ { pkgs . gmp6 . override { withStatic = true ; } } /lib - name " * . a " - exec cp { } $ out/_pkg \ ;
# There is no static libc
$ { pkgs . tree } /bin/tree $ out/_pkg
2022-04-07 16:12:54 +08:00
( cd $ out/_pkg ; $ { pkgs . zip } /bin/zip - r -9 $ out/pkg-ios-aarch64-swift-json.zip * )
rm - fR $ out/_pkg
mkdir - p $ out/nix-support
echo " f i l e b i n a r y - d i s t \" $ ( e c h o $ o u t / * . z i p ) \" " \
> $ out/nix-support/hydra-build-products
'' ;
} ;
# This is the aarch64-darwin build with tagged JSON format (for Mac & Flutter)
" a a r c h 6 4 - d a r w i n : l i b : s i m p l e x - c h a t " = ( drv pkgs ) . simplex-chat . components . library . override {
smallAddressSpace = true ; enableShared = false ;
# we need threaded here, otherwise all the queing logic doesn't work properly.
# for iOS we also use -staticlib, to get one rolled up library.
# still needs mac2ios patching of the archives.
2022-04-10 10:52:36 +01:00
ghcOptions = [ " - s t a t i c l i b " " - t h r e a d e d " " - D I O S " ] ;
2022-04-07 16:12:54 +08:00
postInstall = ''
$ { pkgs . tree } /bin/tree $ out
mkdir - p $ out/_pkg
# copy over includes, we might want those, but maybe not.
# cp -r $out/lib/*/*/include $out/_pkg/
# find the libHS...ghc-X.Y.Z.a static library; this is the
# rolled up one with all dependencies included.
find ./dist - name " l i b H S * . a " - exec cp { } $ out/_pkg \ ;
find $ { pkgs . libffi . overrideAttrs ( old : { dontDisableStatic = true ; } ) } /lib - name " * . a " - exec cp { } $ out/_pkg \ ;
find $ { pkgs . gmp6 . override { withStatic = true ; } } /lib - name " * . a " - exec cp { } $ out/_pkg \ ;
# There is no static libc
$ { pkgs . tree } /bin/tree $ out/_pkg
( cd $ out/_pkg ; $ { pkgs . zip } /bin/zip - r -9 $ out/pkg-ios-aarch64-tagged-json.zip * )
2022-02-16 13:38:49 +04:00
rm - fR $ out/_pkg
mkdir - p $ out/nix-support
echo " f i l e b i n a r y - d i s t \" $ ( e c h o $ o u t / * . z i p ) \" " \
> $ out/nix-support/hydra-build-products
'' ;
} ;
} ;
" x 8 6 _ 6 4 - d a r w i n " = {
2022-04-10 10:52:36 +01:00
# this is the aarch64-darwin iOS build (to be patched with mac2ios)
2022-09-02 11:26:14 +01:00
" x 8 6 _ 6 4 - d a r w i n - i o s : l i b : s i m p l e x - c h a t " = ( drv' {
pkgs' = pkgs ;
extra-modules = [ {
packages . simplexmq . flags . swift = true ;
packages . direct-sqlcipher . flags . commoncrypto = true ;
} ] ;
} ) . simplex-chat . components . library . override {
2022-04-10 10:52:36 +01:00
smallAddressSpace = true ; enableShared = false ;
# we need threaded here, otherwise all the queing logic doesn't work properly.
# for iOS we also use -staticlib, to get one rolled up library.
# still needs mac2ios patching of the archives.
ghcOptions = [ " - s t a t i c l i b " " - t h r e a d e d " " - D I O S " ] ;
postInstall = ''
$ { pkgs . tree } /bin/tree $ out
mkdir - p $ out/_pkg
# copy over includes, we might want those, but maybe not.
# cp -r $out/lib/*/*/include $out/_pkg/
# find the libHS...ghc-X.Y.Z.a static library; this is the
# rolled up one with all dependencies included.
find ./dist - name " l i b H S * . a " - exec cp { } $ out/_pkg \ ;
find $ { pkgs . libffi . overrideAttrs ( old : { dontDisableStatic = true ; } ) } /lib - name " * . a " - exec cp { } $ out/_pkg \ ;
find $ { pkgs . gmp6 . override { withStatic = true ; } } /lib - name " * . a " - exec cp { } $ out/_pkg \ ;
# There is no static libc
$ { pkgs . tree } /bin/tree $ out/_pkg
( cd $ out/_pkg ; $ { pkgs . zip } /bin/zip - r -9 $ out/pkg-ios-x86_64-swift-json.zip * )
rm - fR $ out/_pkg
mkdir - p $ out/nix-support
echo " f i l e b i n a r y - d i s t \" $ ( e c h o $ o u t / * . z i p ) \" " \
> $ out/nix-support/hydra-build-products
'' ;
} ;
# This is the aarch64-darwin build with tagged JSON format (for Mac & Flutter)
2022-02-16 13:38:49 +04:00
" x 8 6 _ 6 4 - d a r w i n : l i b : s i m p l e x - c h a t " = ( drv pkgs ) . simplex-chat . components . library . override {
2022-01-24 19:42:41 +00:00
smallAddressSpace = true ; enableShared = false ;
# we need threaded here, otherwise all the queing logic doesn't work properly.
# for iOS we also use -staticlib, to get one rolled up library.
# still needs mac2ios patching of the archives.
2022-02-17 08:40:08 +00:00
ghcOptions = [ " - s t a t i c l i b " " - t h r e a d e d " " - D I O S " ] ;
2022-01-24 19:42:41 +00:00
postInstall = ''
$ { pkgs . tree } /bin/tree $ out
mkdir - p $ out/_pkg
# copy over includes, we might want those, but maybe not.
# cp -r $out/lib/*/*/include $out/_pkg/
# find the libHS...ghc-X.Y.Z.a static library; this is the
# rolled up one with all dependencies included.
find ./dist - name " l i b H S * . a " - exec cp { } $ out/_pkg \ ;
find $ { pkgs . libffi . overrideAttrs ( old : { dontDisableStatic = true ; } ) } /lib - name " * . a " - exec cp { } $ out/_pkg \ ;
find $ { pkgs . gmp6 . override { withStatic = true ; } } /lib - name " * . a " - exec cp { } $ out/_pkg \ ;
# There is no static libc
$ { pkgs . tree } /bin/tree $ out/_pkg
2022-04-10 10:52:36 +01:00
( cd $ out/_pkg ; $ { pkgs . zip } /bin/zip - r -9 $ out/pkg-ios-x86_64-tagged-json.zip * )
2022-01-24 19:42:41 +00:00
rm - fR $ out/_pkg
mkdir - p $ out/nix-support
echo " f i l e b i n a r y - d i s t \" $ ( e c h o $ o u t / * . z i p ) \" " \
> $ out/nix-support/hydra-build-products
'' ;
} ;
} ;
} . ${ system } or { } ) ;
# build all packages in hydra.
hydraJobs = packages ;
devShell = let
updateCmd = pkgs . writeShellApplication {
name = " u p d a t e - s h a 2 5 6 m a p " ;
runtimeInputs = [ pkgs . nix-prefetch-git pkgs . jq pkgs . gawk ] ;
text = ''
2022-04-11 15:53:44 +01:00
gawk - f ./scripts/nix/update-sha256.awk cabal . project > ./scripts/nix/sha256map.nix
2022-01-24 19:42:41 +00:00
'' ;
} ; in
pkgs . mkShell {
buildInputs = [ updateCmd ] ;
shellHook = ''
echo " w e l c o m e t o t h e s h e l l ! "
'' ;
} ;
}
) ;
}