Skip to content

Commit

Permalink
Avoid incorrectly setting LD_LIBRARY_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Oct 16, 2024
1 parent 458dcf0 commit 1a58ce8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
10 changes: 5 additions & 5 deletions pkgs/python-utils/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ let
ldLibraryPathConvertWrapper = pkgs.writeShellApplication {
inherit name;
text = ''
if test "''${REPLIT_RTLD_LOADER:-}" = "1" && test "''${REPLIT_NIX_CHANNEL:-}" != "legacy"
if test "''${REPLIT_NIX_CHANNEL:-}" = "legacy"
then
# activate RTLD loader!
export LD_AUDIT="${pkgs.replit-rtld-loader}/rtld_loader.so"
export REPLIT_LD_LIBRARY_PATH=${python-ld-library-path}:''${REPLIT_LD_LIBRARY_PATH:-}
else
export LD_LIBRARY_PATH=${python-ld-library-path}
if [ -n "''${PYTHON_LD_LIBRARY_PATH-}" ]; then
export LD_LIBRARY_PATH=''${PYTHON_LD_LIBRARY_PATH}:$LD_LIBRARY_PATH
fi
if [ -n "''${REPLIT_LD_LIBRARY_PATH-}" ]; then
export LD_LIBRARY_PATH=''${REPLIT_LD_LIBRARY_PATH}:$LD_LIBRARY_PATH
fi
else
# activate RTLD loader!
export LD_AUDIT="${pkgs.replit-rtld-loader}/rtld_loader.so"
export REPLIT_LD_LIBRARY_PATH=${python-ld-library-path}:''${REPLIT_LD_LIBRARY_PATH:-}
fi
exec "${bin}" "$@"
'';
Expand Down
27 changes: 21 additions & 6 deletions pkgs/python-wrapped/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ import (
var PythonExePath string
var ReplitPythonLdLibraryPath string

func main() {
if ldAudit := os.Getenv("REPLIT_LD_AUDIT"); ldAudit != "" {
os.Setenv("LD_AUDIT", ldAudit)
}
os.Unsetenv("PYTHONNOUSERSITE")

// Set up environment for legacy nixpkgs
func legacy() {
ldLibraryPath := []string{}
for _, key := range []string{
"REPLIT_LD_LIBRARY_PATH",
Expand All @@ -30,7 +26,26 @@ func main() {
if len(ldLibraryPath) > 0 {
os.Setenv("LD_LIBRARY_PATH", strings.Join(ldLibraryPath, ":"))
}
}

// Set up environment for non-legacy nixpkgs
func modern() {
if ldAudit := os.Getenv("REPLIT_LD_AUDIT"); ldAudit != "" {
os.Setenv("LD_AUDIT", ldAudit)
}
if val, ok := os.LookupEnv("REPLIT_LD_LIBRARY_PATH"); ok && val != "" {
os.Setenv("REPLIT_LD_LIBRARY_PATH", strings.Join([]string{ReplitPythonLdLibraryPath, val}, ":"))
}
}

func main() {
os.Unsetenv("PYTHONNOUSERSITE")

if val, ok := os.LookupEnv("REPLIT_NIX_CHANNEL"); !ok || val == "legacy" || val == "" {
legacy()
} else {
modern()
}

if err := syscall.Exec(PythonExePath, os.Args, os.Environ()); err != nil {
panic(err)
Expand Down

0 comments on commit 1a58ce8

Please sign in to comment.