Last active
August 6, 2025 15:18
-
-
Save naranyala/312271a325d3c4fbd5fe33e07045cf7c to your computer and use it in GitHub Desktop.
in context nix packages outside nixos, this script will make the packages have global ".desktop", making it globally available (cli and gui executable); to make every nix packages available in terminal (bash/zsh/etc) use this script: https://gist.github.com/naranyala/2203f889a3cb89c5cfe4599788bea915
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# chmod +x make-dotdesktop-for-nixpkgs.sh | |
STORE_DIR="/nix/store" | |
DESKTOP_DIR="$HOME/.local/share/applications" | |
ICON_DIR="$HOME/.local/share/icons" | |
LOG_FILE="$HOME/nix-desktopify.log" | |
mkdir -p "$DESKTOP_DIR" "$ICON_DIR" | |
echo "# Desktop entries generated — $(date)" > "$LOG_FILE" | |
log() { echo -e "\e[1;32m[DESKTOP]\e[0m $*"; echo "[DESKTOP] $*" >> "$LOG_FILE"; } | |
for pkg in "$STORE_DIR"/*; do | |
[[ -d "$pkg/bin" ]] || continue | |
for bin in "$pkg/bin/"*; do | |
[[ -x "$bin" && ! -d "$bin" ]] || continue | |
name=$(basename "$bin") | |
exec_path="$bin" | |
desktop_file="$DESKTOP_DIR/${name}.desktop" | |
# Try to find icon (optional) | |
icon_path="" | |
for icon_candidate in "$pkg/share/icons" "$pkg/share/pixmaps" "$pkg/share/$name/icons"; do | |
[[ -d "$icon_candidate" ]] || continue | |
icon_file=$(find "$icon_candidate" -type f \( -name '*.png' -o -name '*.svg' \) | head -n1 || true) | |
if [[ -n "$icon_file" ]]; then | |
cp "$icon_file" "$ICON_DIR/${name}.png" | |
icon_path="$ICON_DIR/${name}.png" | |
break | |
fi | |
done | |
# Create .desktop entry | |
cat > "$desktop_file" <<EOF | |
[Desktop Entry] | |
Name=$name | |
Exec=$exec_path | |
Icon=${icon_path:-application-x-executable} | |
Type=Application | |
Terminal=false | |
Categories=Utility; | |
EOF | |
chmod +x "$desktop_file" | |
log "$name → $desktop_file" | |
done | |
done | |
update-desktop-database "$DESKTOP_DIR" || true | |
echo -e "\n\e[1;34m[INFO]\e[0m Desktop entries saved to: $DESKTOP_DIR" | |
echo -e "\e[1;34m[INFO]\e[0m Log saved to: $LOG_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment