Skip to content

Commit

Permalink
Various fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
angerman committed Mar 17, 2023
1 parent 5fcd22a commit 4180476
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 73 deletions.
52 changes: 26 additions & 26 deletions dynamic.nix
@@ -1,5 +1,5 @@
# define a development shell for dynamically linked applications (default)
{ pkgs, compiler, compiler-nix-name, withHLS ? true, withHlint ? true }:
{ pkgs, compiler, compiler-nix-name, withHLS ? true, withHlint ? true, withIOG ? true }:
let tool-version-map = import ./tool-map.nix;
tool = tool-name: pkgs.haskell-nix.tool compiler-nix-name tool-name (tool-version-map compiler-nix-name tool-name);
cabal-install = tool "cabal"; in
Expand All @@ -9,42 +9,39 @@ pkgs.mkShell {
# consistency with the one in static.nix.
shellHook = with pkgs; ''
export PS1="\[\033[01;33m\][\w]$\[\033[00m\] "
${figlet}/bin/figlet -f rectangles 'IOG Haskell Shell'
function cabal() {
case "$1" in
build)
${cabal-install}/bin/cabal "$@"
;;
clean)
${cabal-install}/bin/cabal "$@"
;;
*)
${cabal-install}/bin/cabal "$@"
;;
esac
}
'' ++ (if pkgs.stdenv.targetPlatform.isMacOS then ''
''
# this one is only needed on macOS right now, due to a bug in loading libcrypto.
export DYLD_LIBRARY_PATH=$(pkg-config --libs-only-L libcrypto|cut -c 3-)
'' else "");
+ lib.optionalString stdenv.hostPlatform.isMacOS
''
export DYLD_LIBRARY_PATH="${lib.getLib openssl}"
'';

buildInputs = [
(pkgs.writeShellApplication {
name = "cabal";
runtimeInputs = [ cabal-install ];
text = ''
case "$1" in
build) cabal "$@"
;;
clean) cabal "$@"
;;
*) cabal "$@"
;;
esac
'';
})
compiler
cabal-install
# cabal-install
pkgs.pkgconfig
# for libstdc++; ghc not being able to find this properly is bad,
# it _should_ probably call out to a g++ or clang++ but doesn't.
pkgs.stdenv.cc.cc.lib

pkgs.cddl
pkgs.cbor-diag

] ++ map pkgs.lib.getDev (
with pkgs;
[
libsodium-vrf
secp256k1
R_4_1_3
zlib
openssl
pcre
Expand All @@ -53,5 +50,8 @@ pkgs.mkShell {
)
++ pkgs.lib.optional withHLS (tool "haskell-language-server")
++ pkgs.lib.optional withHlint (tool "hlint")
++ pkgs.lib.optional withIOG
(with pkgs; [ cddl cbor-diag ]
++ map pkgs.lib.getDev (with pkgs; [ libsodium-vrf secp256k1 R_4_1_3]))
;
}
}
24 changes: 20 additions & 4 deletions flake.nix
Expand Up @@ -107,19 +107,35 @@
else pkgs.pkgsCross.musl64
else pkgs;
in (builtins.mapAttrs (compiler-nix-name: compiler:
import ./dynamic.nix { inherit pkgs compiler compiler-nix-name; }
import ./dynamic.nix { inherit pkgs compiler compiler-nix-name; withIOG = false; }
) (compilers pkgs)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-minimal" (
import ./dynamic.nix { inherit pkgs compiler compiler-nix-name; withHLS = false; withHlint = false; }
import ./dynamic.nix { inherit pkgs compiler compiler-nix-name; withHLS = false; withHlint = false; withIOG = false; }
)) (compilers pkgs)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-static" (
import ./static.nix { pkgs = static-pkgs; inherit compiler compiler-nix-name; }
import ./static.nix { pkgs = static-pkgs; inherit compiler compiler-nix-name; withIOG = false; }
)) (compilers static-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-static-minimal" (
import ./static.nix { pkgs = static-pkgs; inherit compiler compiler-nix-name; withHLS = false; withHlint = false; }
import ./static.nix { pkgs = static-pkgs; inherit compiler compiler-nix-name; withHLS = false; withHlint = false; withIOG = false; }
)) (compilers static-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-iog" (
import ./dynamic.nix { inherit pkgs compiler compiler-nix-name; withIOG = true; }
)) (compilers pkgs)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-minimal-iog" (
import ./dynamic.nix { inherit pkgs compiler compiler-nix-name; withHLS = false; withHlint = false; withIOG = true; }
)) (compilers pkgs)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-static-iog" (
import ./static.nix { pkgs = static-pkgs; inherit compiler compiler-nix-name; withIOG = true; }
)) (compilers static-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-static-minimal-iog" (
import ./static.nix { pkgs = static-pkgs; inherit compiler compiler-nix-name; withHLS = false; withHlint = false; withIOG = true; }
)) (compilers static-pkgs.buildPackages)
);
hydraJobs = devShells;
Expand Down
98 changes: 55 additions & 43 deletions static.nix
@@ -1,4 +1,4 @@
{ pkgs, compiler, compiler-nix-name, withHLS ? true, withHlint ? true }:
{ pkgs, compiler, compiler-nix-name, withHLS ? true, withHlint ? true, withIOG ? true }:
let tool-version-map = import ./tool-map.nix;
tool = tool-name: pkgs.haskell-nix.tool compiler-nix-name tool-name (tool-version-map compiler-nix-name tool-name);
cabal-install = tool "cabal"; in
Expand Down Expand Up @@ -43,61 +43,73 @@ pkgs.mkShell ({
echo "Quirks:"
echo -e "\tif you have the zlib, HsOpenSSL, or digest package in your dependency tree, please make sure to"
echo -e "\techo \"\$CABAL_PROJECT_LOCAL_TEMPLATE\" > cabal.project.local"
function cabal() {
case "$1" in
build)
${cabal-install}/bin/cabal \
"$@" \
$NIX_CABAL_FLAGS \
--disable-shared --enable-static \
--ghc-option=-L${lib.getLib static-gmp}/lib \
--ghc-option=-L${lib.getLib static-libsodium-vrf}/lib \
--ghc-option=-L${lib.getLib static-secp256k1}/lib \
--ghc-option=-L${lib.getLib static-openssl}/lib
;;
clean)
${cabal-install}/bin/cabal "$@"
;;
*)
${cabal-install}/bin/cabal $NIX_CABAL_FLAGS "$@"
;;
esac
}
function fixup-nix-deps() {
for nixlib in $(otool -L "$1" |awk '/nix\/store/{ print $1 }'); do
case "$nixlib" in
*libiconv.dylib) install_name_tool -change "$nixlib" /usr/lib/libiconv.dylib "$1" ;;
*libffi.*.dylib) install_name_tool -change "$nixlib" /usr/lib/libffi.dylib "$1" ;;
*libz.dylib) install_name_tool -change "$nixlib" /usr/lib/libz.dylib "$1" ;;
*) ;;
esac
done
}
'' ++ (if pkgs.stdenv.targetPlatform.isMacOS then ''
# this one is only needed on macOS right now, due to a bug in loading libcrypto.
export DYLD_LIBRARY_PATH=$(pkg-config --libs-only-L libcrypto|cut -c 3-)
'' else "");
'';
buildInputs = (with pkgs; [
# for libstdc++; ghc not being able to find this properly is bad,
# it _should_ probably call out to a g++ or clang++ but doesn't.
stdenv.cc.cc.lib
]) ++ map pkgs.lib.getDev (with pkgs; [ libsodium-vrf secp256k1 static-gmp
# R_4_1_3
]) ++ map pkgs.lib.getDev (with pkgs; [
static-gmp

zlib
pcre
openssl
]);

nativeBuildInputs = [ (compiler.override { enableShared = true; }) ] ++ (with pkgs; [
haskell-nix.cabal-install.${compiler-nix-name}
nativeBuildInputs = [
(pkgs.writeShellApplication {
name = "cabal";
runtimeInputs = [ cabal-install ];
text = with pkgs; ''
# We do not want to quote NIX_CABAL_FLAGS
# it will leave an empty argument, if they are empty.
# shellcheck disable=SC2086
case "$1" in
build)
cabal \
"$@" \
$NIX_CABAL_FLAGS \
--disable-shared --enable-static \
--ghc-option=-L${lib.getLib static-gmp}/lib \
--ghc-option=-L${lib.getLib static-libsodium-vrf}/lib \
--ghc-option=-L${lib.getLib static-secp256k1}/lib \
--ghc-option=-L${lib.getLib static-openssl}/lib
;;
clean)
cabal "$@"
;;
*)
cabal $NIX_CABAL_FLAGS "$@"
;;
esac
'';
})
(pkgs.writeShellApplication {
name = "fixup-nix-deps";
text = ''
for nixlib in $(otool -L "$1" |awk '/nix\/store/{ print $1 }'); do
case "$nixlib" in
*libiconv.dylib) install_name_tool -change "$nixlib" /usr/lib/libiconv.dylib "$1" ;;
*libffi.*.dylib) install_name_tool -change "$nixlib" /usr/lib/libffi.dylib "$1" ;;
*libz.dylib) install_name_tool -change "$nixlib" /usr/lib/libz.dylib "$1" ;;
*) ;;
esac
done
'';
})
(compiler.override { enableShared = true; })
] ++ (with pkgs; [
# haskell-nix.cabal-install.${compiler-nix-name}
pkgconfig
stdenv.cc.cc.lib ]) ++ (with pkgs.buildPackages; [
cddl
cbor-diag
])
++ pkgs.lib.optional withHLS (tool "haskell-language-server")
++ pkgs.lib.optional withHlint (tool "hlint")
++ pkgs.lib.optional withIOG
(with pkgs; [ cddl cbor-diag ]
++ map pkgs.lib.getDev (with pkgs; [
libsodium-vrf secp256k1 #R_4_1_3
]))

;
})

0 comments on commit 4180476

Please sign in to comment.