Skip to content

Commit

Permalink
Nix: Wrap GHC and HLS, specifically, to provide (DY)?LD_LIBRARY_PATH.
Browse files Browse the repository at this point in the history
We clearly do need this environment variable (at least on macOS); otherwise GHC spits out a slew of errors along the lines of "cannot find libodbc.dylib".

However, adding it directly to the shell causes serious problems. Wrapping GHC should limit the damage.

We've seen similar issues on macOS.

PR-URL: hasura/graphql-engine-mono#9203
Co-authored-by: Philip Lykke Carlsen <[email protected]>
GitOrigin-RevId: 9468d31e5b8ec86196809844842a1668386054bc
  • Loading branch information
2 people authored and hasura-bot committed May 22, 2023
1 parent 4b50704 commit 3287181
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

formatter = pkgs.nixpkgs-fmt;

devShells.default = import ./nix/shell.nix { inherit pkgs; };
devShells.default = import ./nix/shell.nix { inherit pkgs system; };
}
);
}
48 changes: 44 additions & 4 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{ pkgs }:
{ pkgs, system }:
let
versions = import ./versions.nix { inherit pkgs; };

# empty package, for shenanigans
empty = builtins.derivation {
inherit system;
name = "empty";
builder = pkgs.writeShellScript "null.sh" "${pkgs.coreutils}/bin/mkdir $out";
};

# Unix ODBC Support
freetdsWithODBC = pkgs.freetds.override {
odbcSupport = true;
Expand All @@ -28,6 +35,40 @@ let
configureFlags = [ "--disable-gui" "--sysconfdir=${odbcConfiguration}" ];
});

# Ensure that GHC and HLS have access to all the dynamic libraries we have kicking around.
ghc =
let original = pkgs.haskell.compiler.${pkgs.ghcName};
in pkgs.stdenv.mkDerivation
{
name = original.name;
src = empty;
buildInputs = [ original pkgs.makeWrapper ];
installPhase = ''
mkdir -p "$out/bin"
makeWrapper ${original}/bin/ghc "$out/bin/ghc" \
--set LD_LIBRARY_PATH ${pkgs.lib.strings.makeLibraryPath dynamicLibraries} \
--set DYLD_LIBRARY_PATH ${pkgs.lib.strings.makeLibraryPath dynamicLibraries}
'';
};

hls =
let original = pkgs.haskell.packages.${pkgs.ghcName}.haskell-language-server;
in pkgs.stdenv.mkDerivation
{
name = original.name;
src = empty;
buildInputs = [ original pkgs.makeWrapper ];
installPhase = ''
mkdir -p "$out/bin"
makeWrapper ${original}/bin/haskell-language-server "$out/bin/haskell-language-server" \
--set LD_LIBRARY_PATH ${pkgs.lib.strings.makeLibraryPath dynamicLibraries} \
--set DYLD_LIBRARY_PATH ${pkgs.lib.strings.makeLibraryPath dynamicLibraries}
makeWrapper ${original}/bin/haskell-language-server-wrapper "$out/bin/haskell-language-server-wrapper" \
--set LD_LIBRARY_PATH ${pkgs.lib.strings.makeLibraryPath dynamicLibraries} \
--set DYLD_LIBRARY_PATH ${pkgs.lib.strings.makeLibraryPath dynamicLibraries}
'';
};

baseInputs = [
pkgs.stdenv
pkgs.jq
Expand Down Expand Up @@ -56,15 +97,14 @@ let
haskellInputs = [
pkgs.cabal2nix

# The correct version of GHC.
pkgs.haskell.compiler.${pkgs.ghcName}
ghc
hls

pkgs.haskell.packages.${pkgs.ghcName}.alex
pkgs.haskell.packages.${pkgs.ghcName}.apply-refact
(versions.ensureVersion pkgs.haskell.packages.${pkgs.ghcName}.cabal-install)
pkgs.haskell.packages.${pkgs.ghcName}.ghcid
pkgs.haskell.packages.${pkgs.ghcName}.happy
pkgs.haskell.packages.${pkgs.ghcName}.haskell-language-server
(versions.ensureVersion pkgs.haskell.packages.${pkgs.ghcName}.hlint)
pkgs.haskell.packages.${pkgs.ghcName}.hoogle
pkgs.haskell.packages.${pkgs.ghcName}.hspec-discover
Expand Down

0 comments on commit 3287181

Please sign in to comment.