News for hackers. Stuff that matters.
Re:Self-contained Python scripts with uv by kissgyorgy on Sunday March 30, 2025 @02:50AM (#43521949)
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!
Re:Self-contained Python scripts with uv by skavi on Sunday March 30, 2025 @04:27AM (#43522428)
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

Re:Self-contained Python scripts with uv by execat on Sunday March 30, 2025 @07:19AM (#43523263)
How to do the same thing with `nix shell` (The flake based command) instead of `nix-shell`?
Re:Self-contained Python scripts with uv by skeledrew on Sunday March 30, 2025 @09:59AM (#43524260)
Maybe `#! /usr/bin/env -S nix shell `?
Re:Self-contained Python scripts with uv by skavi on Monday March 31, 2025 @03:48AM (#43532297)
Re:Self-contained Python scripts with uv by skowalak on Sunday March 30, 2025 @07:24AM (#43523283)
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.
Re:Self-contained Python scripts with uv by falcor84 on Sunday March 30, 2025 @08:21AM (#43523566)
> 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.

Re:Self-contained Python scripts with uv by Tractor8626 on Sunday March 30, 2025 @08:53AM (#43523782)
Having Nih installed is much stronger requirement than having uv
Re:Self-contained Python scripts with uv by aerzen on Sunday March 30, 2025 @10:43AM (#43524592)
im not sure this is true
Re:Self-contained Python scripts with uv by maleldil on Sunday March 30, 2025 @03:35PM (#43526873)
Nix requires a bunch of stuff to setup and to understand. uv is just a binary in PATH.