Skip to content

Commit

Permalink
chore(dev): Add Flox for local environment setup (#26805)
Browse files Browse the repository at this point in the history
  • Loading branch information
Twixes authored Dec 18, 2024
1 parent 8f49a0d commit a99faee
Show file tree
Hide file tree
Showing 11 changed files with 2,071 additions and 39 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if [ -z "${FLOX_VERSION}" ]; then # Don't activate if already activated
flox activate
fi
4 changes: 4 additions & 0 deletions .flox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
run/
cache/
lib/
log/
4 changes: 4 additions & 0 deletions .flox/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "posthog",
"version": 1
}
70 changes: 70 additions & 0 deletions .flox/env/direnv-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

if ! command -v direnv &> /dev/null; then
# Install direnv based on platform
if command -v brew &> /dev/null; then
echo "🔄 Installing direnv using 'brew install direnv'..."
HOMEBREW_NO_ENV_HINTS=1 brew install -q direnv
elif command -v apt &> /dev/null; then
echo "🔄 Installing direnv using 'apt install direnv'..."
sudo apt update && sudo apt install -yq direnv
elif command -v dnf &> /dev/null; then
echo "🔄 Installing direnv using 'dnf install direnv'..."
sudo dnf install -yq direnv
else
echo "🔄 Installing direnv using 'curl -sfL https://direnv.net/install.sh | bash'"
curl -sfL https://direnv.net/install.sh | bash
fi
echo "✅ Installed direnv"
else
echo "⏩ direnv already installed"
fi

# Determine shell and config file
shell_name=$(basename "$SHELL")
case "$shell_name" in
"bash")
config_file="$HOME/.bashrc"
hook_command='eval "$(direnv hook bash)"'
;;
"zsh")
config_file="$HOME/.zshrc"
hook_command='eval "$(direnv hook zsh)"'
;;
"fish")
config_file="$HOME/.config/fish/config.fish"
hook_command='direnv hook fish | source'
mkdir -p "$(dirname "$config_file")"
;;
"tcsh")
config_file="$HOME/.cshrc"
hook_command='eval `direnv hook tcsh`'
;;
*)
echo "Unsupported shell: $shell_name"
return 1
;;
esac

echo "🐚 Configuring your default shell, $SHELL, for direnv"

# Add hook to shell config if not already present
if ! grep -q "direnv hook" "$config_file" 2>/dev/null; then
echo -e "\n# Initialize direnv - added by PostHog's Flox activation hook (../posthog/.flox/env/manifest.toml)\n$hook_command" >> "$config_file"
echo "✅ Injected direnv hook into $config_file"
else
echo "⏩ direnv hook already present in $config_file"
fi

# Add hook to shell config if not already present
if ! grep -q "warn_timeout" "$HOME/.config/direnv/direnv.toml" 2>/dev/null; then
echo "[global]\nwarn_timeout = 0 # Ignore timeout from this issue: https://github.com/direnv/direnv/issues/1065 - added by PostHog's Flox activation hook (../posthog/.flox/env/manifest.toml)" >> "$HOME/.config/direnv/direnv.toml"
echo "✅ Configured ~/.config/direnv/direnv.toml"
else
echo "⏩ ~/.config/direnv/direnv.toml already configured"
fi

echo "💫 direnv is now active"

# Allow this directory's .envrc to be loaded
direnv allow
Loading

0 comments on commit a99faee

Please sign in to comment.