Skip to content

Instantly share code, notes, and snippets.

@kalbasit
Created February 28, 2019 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalbasit/45efe8d3464736c2f3980a260e824b4e to your computer and use it in GitHub Desktop.
Save kalbasit/45efe8d3464736c2f3980a260e824b4e to your computer and use it in GitHub Desktop.
if ! nix-shell -p hello --run 'hello' &>/dev/null; then
# The following condition addresses https://github.com/NixOS/nix/issues/2523
if [[ "$(uname -s)" == "Darwin" ]] && [[ "$( grep -E 'nix-daemon.*fork()' /var/log/system.log | wc -l )" -gt 0 ]]; then
>&2 echo ">>> I ran into a Mac-specific bug (https://github.com/NixOS/nix/issues/2523) and I'm applying the workaround automatically for it."
sudo launchctl remove org.nixos.nix-daemon
sed \
-e "s:<key>Program</key>:<key>EnvironmentVariables</key><dict><key>OBJC_DISABLE_INITIALIZE_FORK_SAFETY</key><string>YES</string></dict>&:g" \
/Library/LaunchDaemons/org.nixos.nix-daemon.plist > /tmp/org.nixos.nix-daemon.plist
sudo mv /tmp/org.nixos.nix-daemon.plist /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo chown root: /Library/LaunchDaemons/org.nixos.nix-daemon.plist
sudo launchctl load /Library/LaunchDaemons/org.nixos.nix-daemon.plist
nix-shell -p hello --run 'hello'
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment