Skip to content

Instantly share code, notes, and snippets.

@marcelarie
Created July 5, 2025 20:12
Show Gist options
  • Save marcelarie/d1ad106663ce49ed5888aef1a99df047 to your computer and use it in GitHub Desktop.
Save marcelarie/d1ad106663ce49ed5888aef1a99df047 to your computer and use it in GitHub Desktop.
Start nix dev shells without local flake.nix
#!/usr/bin/env bash
set -euo pipefail
REPO="${DEV_TEMPLATES:-$HOME/clones/own/dev-templates}"
edit=false
remote=""
lang=""
while [[ $# -gt 0 ]]; do
case "$1" in
-e | --edit)
edit=true
shift
;;
-r | --remote)
remote="$2"
shift 2
;;
*)
lang="$1"
shift
;;
esac
done
if [[ -n "$remote" ]]; then
if [[ -z "$lang" ]]; then
if [[ $remote =~ ^github: ]]; then
gh="${remote#github:}"
owner="${gh%%/*}"
repo="${gh#*/}"
api="https://api.github.com/repos/${owner}/${repo}/contents"
lang=$(curl -fsSL "$api" | jq -r '.[] | select(.type=="dir") | .name' | grep -v '^\.github$' | fzf)
else
echo "fzf selection only supported for github: remotes" >&2
exit 1
fi
fi
[[ -z "$lang" ]] && exit 0
$edit && echo "--edit ignored with --remote" >&2
exec nix develop "${remote}?dir=${lang}"
fi
if [[ -z "$lang" ]]; then
lang=$(git -C "$REPO" ls-tree -d --name-only HEAD | grep -v '^\.github$' | fzf)
fi
[[ -z "$lang" ]] && exit 0
flake="$REPO/$lang/flake.nix"
if $edit; then
"${EDITOR:-vi}" "$flake"
fi
exec nix develop "$REPO/$lang"
@marcelarie
Copy link
Author

marcelarie commented Jul 5, 2025

Available commands

Open fzf to select a language from the local repository (first we need to specify the path on the script):

tempshell

Open a specific language from the local repo:

tempshell python

Open a specific language from the local repo but edit it before running the dev shell:

tempshell -e rust
tempshell --edit rust

Open fzf to select a language from a remote repository:

tempshell -r github:the-nix-way/dev-templates

Open a specific language from a remote repository:

tempshell -r github:the-nix-way/dev-templates node

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment