Skip to content

Comments

Fix LD_LIBRARY_PATH usage in direnv build environment#1918

Merged
akshaymankar merged 2 commits intodevelopfrom
sysvinit/fix-direnv-build
Nov 9, 2021
Merged

Fix LD_LIBRARY_PATH usage in direnv build environment#1918
akshaymankar merged 2 commits intodevelopfrom
sysvinit/fix-direnv-build

Conversation

@sysvinit
Copy link
Contributor

@sysvinit sysvinit commented Nov 9, 2021

The direnv hook for wire-server uses the load_prefix function, which sets the LD_LIBRARY_PATH environment variable in development shells, so that cabal can pick up non-Haskell dependencies like zlib and cryptobox. However, this means that running programs inside the dev shell environment will cause libraries from the Nix store to be loaded, which can interfere with programs from the host system, especially for non-NixOS users. For example, I can't run nix-build inside a dev shell on Debian, as the dynamic loader tries to load an incompatible shared library from the Nix store instead of system libraries.

I've refactored the dev shell environment, and split everything but cabal into its own environment, wrapped cabal in a script which sets LD_LIBRARY_PATH to point to the everything-but-cabal environment, and made a second environment which encapsulates the everything-but-cabal env and the cabal wrapper. direnv then only exposes the bin/ directory of the second environment in PATH instead of setting all the LD_LIBRARY_PATH environment variables.

The .envrc used direnv's load_prefix function to make all the required tools
and dependency libraries visible within the development environment, which
sets a couple of environment variables in the dev shell including PATH and
LD_LIBRARY_PATH. The latter is required so that cabal can find non-Haskell
dependencies such as zlib and cryptobox.

However, adding paths inside the Nix store to LD_LIBRARY_PATH can interfere
with tools in the host system, especially on non-NixOS systems, as the dynamic
loader will attempt to load dynamic libraries from the Nix store before those
of the host system, which in some cases will cause some programs to fail to run
due to dynamic symbol mismatches.

This commit refactors the direnv build environment, splitting everything
but cabal into a separate environment, and exposing cabal through a wrapper
script which sets LD_LIBRARY_PATH appropriately only for cabal. Instead
of load_prefix, the .envrc reverts to using PATH_add, to avoid introducing
LD_LIBRARY_PATH into dev shell environments.
@sysvinit sysvinit requested a review from akshaymankar November 9, 2021 15:11
@CLAassistant
Copy link

CLAassistant commented Nov 9, 2021

CLA assistant check
All committers have signed the CLA.

@akshaymankar akshaymankar force-pushed the sysvinit/fix-direnv-build branch from 9d31595 to ab377c2 Compare November 9, 2021 16:20
@akshaymankar akshaymankar merged commit 08362c8 into develop Nov 9, 2021
@akshaymankar akshaymankar deleted the sysvinit/fix-direnv-build branch November 9, 2021 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants