kissgyorgy 3 days ago

We do the same with Nix, the shebang line looks like this:

    #! nix-shell -i python3 -p "python312.withPackages (pkgs: [ pkgs.boto3 pkgs.click ])"
With this, the only requirement is Nix on the system, you don't even need Python to be installed!

5
skowalak 3 days ago

While that is true, there are still lots of PyPI packages not yet packaged with nixpkgs, so this is not as universal an approach as uv.

falcor84 3 days ago

> you don't even need Python to be installed!

Note that this is exactly the case in TFA - uv takes care of installing Python ad-hoc.

skavi 3 days ago

Yup, and you can apply the same technique to any language. The obvious example is bash with all the dependencies specified, but I’ve also hacked up quick single file rust scripts using nix shebangs.

https://nixos.wiki/wiki/Nix-shell_shebang

Tractor8626 3 days ago

Having Nih installed is much stronger requirement than having uv

aerzen 3 days ago

im not sure this is true

maleldil 3 days ago

Nix requires a bunch of stuff to setup and to understand. uv is just a binary in PATH.

execat 3 days ago

How to do the same thing with `nix shell` (The flake based command) instead of `nix-shell`?

skeledrew 3 days ago

Maybe `#! /usr/bin/env -S nix shell `?