From 1a58ce87fc6ae7deea7179d072c7473c510a8756 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 16 Oct 2024 09:56:49 -0700 Subject: [PATCH 1/3] Avoid incorrectly setting LD_LIBRARY_PATH --- pkgs/python-utils/default.nix | 10 +++++----- pkgs/python-wrapped/main.go | 27 +++++++++++++++++++++------ 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/pkgs/python-utils/default.nix b/pkgs/python-utils/default.nix index 1313ec5d..cf7c2440 100644 --- a/pkgs/python-utils/default.nix +++ b/pkgs/python-utils/default.nix @@ -32,12 +32,8 @@ 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 @@ -45,6 +41,10 @@ let 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}" "$@" ''; diff --git a/pkgs/python-wrapped/main.go b/pkgs/python-wrapped/main.go index a4526d8d..a2147f85 100644 --- a/pkgs/python-wrapped/main.go +++ b/pkgs/python-wrapped/main.go @@ -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", @@ -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) From 76102b6522f397fe9f59e51c6d4a3c3ba38a1a15 Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 16 Oct 2024 10:13:56 -0700 Subject: [PATCH 2/3] There was another --- pkgs/python-wrapped/main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkgs/python-wrapped/main.go b/pkgs/python-wrapped/main.go index a2147f85..a6399a28 100644 --- a/pkgs/python-wrapped/main.go +++ b/pkgs/python-wrapped/main.go @@ -38,13 +38,18 @@ func modern() { } } +// returns whether a Nix channel works with RTLD loader +func channelWorksWithRtldLoader(channel string) bool { + return channel != "" && channel != "legacy" && channel != "stable-21_11" +} + func main() { os.Unsetenv("PYTHONNOUSERSITE") - if val, ok := os.LookupEnv("REPLIT_NIX_CHANNEL"); !ok || val == "legacy" || val == "" { - legacy() - } else { + if val, ok := os.LookupEnv("REPLIT_NIX_CHANNEL"); ok && channelWorksWithRtldLoader(val) { modern() + } else { + legacy() } if err := syscall.Exec(PythonExePath, os.Args, os.Environ()); err != nil { From 81418d2bc67cbd30f1303d202ab497d064903dea Mon Sep 17 00:00:00 2001 From: Devon Stewart Date: Wed, 16 Oct 2024 10:41:59 -0700 Subject: [PATCH 3/3] Update pkgs/python-utils/default.nix Co-authored-by: Ryan Mulligan --- pkgs/python-utils/default.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/python-utils/default.nix b/pkgs/python-utils/default.nix index cf7c2440..876dfcbb 100644 --- a/pkgs/python-utils/default.nix +++ b/pkgs/python-utils/default.nix @@ -32,7 +32,7 @@ let ldLibraryPathConvertWrapper = pkgs.writeShellApplication { inherit name; text = '' - if test "''${REPLIT_NIX_CHANNEL:-}" = "legacy" + if test "''${REPLIT_NIX_CHANNEL:-}" = "legacy" || test "''${REPLIT_NIX_CHANNEL:-}" = "stable-21_11" then export LD_LIBRARY_PATH=${python-ld-library-path} if [ -n "''${PYTHON_LD_LIBRARY_PATH-}" ]; then