diff --git a/.aliases/dev-root b/.aliases/dev-root index 61cdcf4..626a30f 100755 --- a/.aliases/dev-root +++ b/.aliases/dev-root @@ -5,4 +5,5 @@ set -eo pipefail SCRIPTDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) cd "$SCRIPTDIR/.." -nix build .#gcroots -o .gcroots +nix build .#packages.aarch64-darwin.gcroots -o .gcroots-aarch64-darwin +nix build .#packages.x86_64-darwin.gcroots -o .gcroots-x86_64-darwin diff --git a/.gitignore b/.gitignore index 6782576..b201745 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ result dist-newstyle .direnv -.gcroots +.gcroots* diff --git a/flake.nix b/flake.nix index 9dfc6e5..cb20207 100644 --- a/flake.nix +++ b/flake.nix @@ -40,9 +40,17 @@ baseModules = { packages.haskell-notebook-language-server.components.exes.haskell-notebook-language-server.dontStrip = false; - # packages.haskell-notebook-language-server.components.exes.haskell-notebook-language-server.postFixup = '' - # echo AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA - # ''; + } // pkgs.lib.optionalAttrs pkgs.stdenv.isDarwin { + packages.haskell-notebook-language-server.components.exes.haskell-notebook-language-server.postInstall = '' + ${builtins.readFile ./nix/fix-dylib.sh} + + fix_dylib "$out/bin/haskell-notebook-language-server" libiconv.2.dylib libiconv.dylib + fix_dylib "$out/bin/haskell-notebook-language-server" libffi.8.dylib libffi.dylib + check_no_nix_refs "$out/bin/haskell-notebook-language-server" + ''; + packages.haskell-notebook-language-server.components.exes.haskell-notebook-language-server.configureFlags = [ + ''--ghc-options="-optl-Wl,-dead_strip -optl-Wl,-dead_strip_dylibs -optl-Wl,-force_load,${pkgs.pkgsStatic.libffi}/lib/libffi.a"'' + ]; }; flake = compiler-nix-name: src: (pkgs.hixProject compiler-nix-name src [baseModules]).flake {}; diff --git a/nix/fix-dylib.sh b/nix/fix-dylib.sh new file mode 100644 index 0000000..668d317 --- /dev/null +++ b/nix/fix-dylib.sh @@ -0,0 +1,32 @@ + +# Example usage: +# fix_dylib "./myapp" "libffi.8.dylib" "libffi.dylib" +fix_dylib() { + local executable="$1" + local dylib_name="$2" + local target_name="$3" + + if otool -L "$executable" | grep -q "/nix/store/.*/$dylib_name"; then + echo "Fixing $dylib_name reference in $executable" + local old_path=$(otool -L "$executable" | grep "/nix/store/.*/$dylib_name" | awk '{print $1}') + install_name_tool -change "$old_path" "/usr/lib/$target_name" "$executable" + if otool -L "$executable" | grep -q "/usr/lib/$target_name"; then + echo "Successfully fixed $dylib_name in $executable (now points to $target_name)" + else + echo "Failed to fix $dylib_name in $executable (attempted to point to $target_name)" + return 1 + fi + fi +} + +# Example usage: +# check_no_nix_refs "./myapp" +check_no_nix_refs() { + local executable="$1" + + if otool -L "$executable" | tail -n +2 | grep -q "/nix/store/"; then + echo "ERROR: $executable still contains Nix store references:" + otool -L "$executable" | tail -n +2 | grep "/nix/store/" + return 1 + fi +}