How can I use nix-shell and uv together to create a self-contained script?

The -i argument will be run as the interpreter, so this seems to work:

#! /usr/bin/env nix-shell
#! nix-shell -i "uv run --script --quiet" -p uv
# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "rich",
# ]
# ///

import time
from rich.progress import track

for i in track(range(20), description="For example:"):
    time.sleep(0.05)
1 Like