Skip to content

Commit

Permalink
Fix issue #26: [macOS] DYLD_LIBRARY_PATH env var needed for dev shell
Browse files Browse the repository at this point in the history
  • Loading branch information
yvan-sraka committed Mar 13, 2023
1 parent 7420ccb commit fafa4d1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
11 changes: 7 additions & 4 deletions dynamic.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# define a development shell for dynamically linked applications (default)
{ pkgs, compiler, compiler-nix-name, withHLS ? true, withHlint ? true }:
{ system, pkgs, compiler, compiler-nix-name, withHLS ? true, withHlint ? 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 @@ -12,8 +12,8 @@ pkgs.mkShell {
${figlet}/bin/figlet -f rectangles 'IOG Haskell Shell'
function cabal() {
case "$1" in
build)
case "$1" in
build)
${cabal-install}/bin/cabal "$@"
;;
clean)
Expand All @@ -24,7 +24,10 @@ pkgs.mkShell {
;;
esac
}
'';
'' ++ (if system == "darwin-aarch64" || system == "darwin-x86_64" 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 = [
compiler
cabal-install
Expand Down
26 changes: 13 additions & 13 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils, haskellNix }:
outputs = { self, nixpkgs, flake-utils, haskellNix }:
let overlays = {
crypto = final: prev: {
libsodium-vrf = final.callPackage ({ stdenv, lib, fetchFromGitHub, autoreconfHook }:
stdenv.mkDerivation rec {
stdenv.mkDerivation {
name = "libsodium-1.0.18";

src = fetchFromGitHub {
Expand Down Expand Up @@ -68,19 +68,19 @@
});
cddl-tools = (final: prev: {
cbor-diag = final.callPackage ./pkgs/cbor-diag { };
cddl = final.callPackage ./pkgs/cddl { };
cddl = final.callPackage ./pkgs/cddl { };
});
};
supportedSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
];
in flake-utils.lib.eachSystem supportedSystems (system:
let
let
pkgs = import nixpkgs {
overlays = [haskellNix.overlay] ++ __attrValues overlays;
overlays = [haskellNix.overlay] ++ builtins.attrValues overlays;
inherit system;
inherit (haskellNix) config;
};
Expand All @@ -106,20 +106,20 @@
then pkgs.pkgsCross.aarch64-multiplatform-musl
else pkgs.pkgsCross.musl64
else pkgs;
in (__mapAttrs (compiler-nix-name: compiler:
import ./dynamic.nix { inherit pkgs compiler compiler-nix-name; }
in (builtins.mapAttrs (compiler-nix-name: compiler:
import ./dynamic.nix { inherit system pkgs compiler compiler-nix-name; }
) (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 system pkgs compiler compiler-nix-name; withHLS = false; withHlint = false; }
)) (compilers pkgs)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
// 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 system compiler compiler-nix-name; }
)) (compilers static-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
// 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 system compiler compiler-nix-name; withHLS = false; withHlint = false; }
)) (compilers static-pkgs.buildPackages)
);
hydraJobs = devShells;
Expand Down
20 changes: 12 additions & 8 deletions static.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ pkgs, compiler, compiler-nix-name, withHLS ? true, withHlint ? true }:
{ system, pkgs, compiler, compiler-nix-name, withHLS ? true, withHlint ? 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
pkgs.mkShell (rec {
pkgs.mkShell ({
# Note [cabal override]:
#
# We need to override the `cabal` command and pass --ghc-options for the
Expand Down Expand Up @@ -34,7 +34,7 @@ pkgs.mkShell (rec {
'';

shellHook = with pkgs; ''
export PS1="\[\033[01;33m\][\w]$\[\033[00m\] "
export PS1="\[\033[01;33m\][\w]$\[\033[00m\] "
${figlet}/bin/figlet -f rectangles 'IOG Haskell Shell'
${figlet}/bin/figlet -f small "*= static edition =*"
echo "NOTE (macos): you can use fixup-nix-deps FILE, to fix iconv, ffi, and zlib dependencies that point to the /nix/store"
Expand All @@ -44,8 +44,8 @@ pkgs.mkShell (rec {
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)
case "$1" in
build)
${cabal-install}/bin/cabal \
"$@" \
$NIX_CABAL_FLAGS \
Expand Down Expand Up @@ -74,7 +74,11 @@ pkgs.mkShell (rec {
esac
done
}
'';
'' ++ (if system == "darwin-aarch64" || system == "darwin-x86_64" 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.
Expand All @@ -95,5 +99,5 @@ pkgs.mkShell (rec {
])
++ pkgs.lib.optional withHLS (tool "haskell-language-server")
++ pkgs.lib.optional withHlint (tool "hlint")
;
})
;
})

0 comments on commit fafa4d1

Please sign in to comment.