/ .nixos-patch-electron.sh
.nixos-patch-electron.sh
 1  #!/usr/bin/env bash
 2  # Script to patch Electron for NixOS
 3  
 4  set -e
 5  
 6  if [ ! -d "node_modules/electron/dist" ]; then
 7    echo "Electron not installed yet. Run 'npm install' first."
 8    exit 1
 9  fi
10  
11  echo "Patching Electron binaries for NixOS..."
12  
13  cd node_modules/electron/dist
14  
15  # Patch main electron binary
16  if [ -f electron ]; then
17    patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" electron
18    patchelf --set-rpath "${LD_LIBRARY_PATH}" electron
19    echo "✓ Patched electron"
20  fi
21  
22  # Patch chrome-sandbox
23  if [ -f chrome-sandbox ]; then
24    chmod u+w chrome-sandbox
25    patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" chrome-sandbox || true
26    patchelf --set-rpath "${LD_LIBRARY_PATH}" chrome-sandbox || true
27    echo "✓ Patched chrome-sandbox"
28  fi
29  
30  # Copy libffmpeg from the system
31  if [ ! -f libffmpeg.so ]; then
32    # Try to find libffmpeg in the system
33    for ffmpeg_lib in /nix/store/*-electron-*/lib/libffmpeg.so; do
34      if [ -f "$ffmpeg_lib" ]; then
35        cp "$ffmpeg_lib" .
36        chmod +w libffmpeg.so
37        echo "✓ Copied libffmpeg.so"
38        break
39      fi
40    done
41  fi
42  
43  echo "Electron patching complete!"