←back to thread

Fun with uv and PEP 723

(www.cottongeeks.com)
619 points deepakjois | 2 comments | | HN request time: 0.424s | source
Show context
ACAVJW4H ◴[] No.44370555[source]
finally feels like Python scripts can Just Work™ without a virtualenv scavenger hunt.

Now if only someone could do the same for shell scripts. Packaging, dependency management, and reproducibility in shell land are still stuck in the Stone Ages. Right now it’s still curl | bash and hope for the best, or a README with 12 manual steps and three missing dependencies.

Sure, there’s Nix... if you’ve already transcended time, space, and the Nix manual. Docker? Great, if downloading a Linux distro to run sed sounds reasonable.

There’s got to be a middle ground simple, declarative, and built for humans.

replies(16): >>44370574 #>>44370603 #>>44370609 #>>44370667 #>>44370757 #>>44370943 #>>44371081 #>>44371402 #>>44372258 #>>44372278 #>>44372472 #>>44372942 #>>44373775 #>>44374090 #>>44374399 #>>44376192 #
traverseda ◴[] No.44371081[source]
I don't think nix is that hard for this particular use case. Installing nix on other distros is pretty easy, and once it's installed you just do something like this

    #! /usr/bin/env nix-shell
    #! nix-shell -i bash -p imagemagick cowsay

    # scale image by 50%
    convert "$1" -scale 50% "$1.s50.jpg" &&
    cowsay "done $1.q50.jpg"
Sure all of nixos and packaging for nix is a challenge, but just using it for a shell script is not too bad
replies(2): >>44375926 #>>44376976 #
1. caspar ◴[] No.44375926[source]
Last time I checked,[0] this works great - as long as you don't particularly care which specific versions of imagemagick or cowsay you want.

If you do care, then welcome to learning about niv, flakes, etc.

[0]: admittedly 3 years ago or so.

replies(1): >>44380944 #
2. loremm ◴[] No.44380944[source]
This is a hack but I still found it helpful. If you do want to force a certain version, without worrying about flakes [1] this can be your bash shebang, with similar for nix configuration.nix or nix-shell interactive. It just tells nix to use a specific git hash for it's base instead of whatever your normal channel is.

For my use case, most things I don't mind tracking mainline, but some things I want to fix (chromium is very large, python changes a lot, or some version broke things)

``` #! nix-shell -i bash -p "cowsay" '(import (fetchTarball { url="https://github.com/NixOS/nixpkgs/archive/eb090f7b923b1226e8b... sha256 = "15iglsr7h3s435a04313xddah8vds815i9lajcc923s4yl54aj4j";}) {}).python3' ```

[1] flakes really aren't bad either, especially if you think about it as just doing above, but automatically