opam icon indicating copy to clipboard operation
opam copied to clipboard

TODO: port Nixpkgs' patch_shebangs.sh

Open kit-ty-kate opened this issue 1 year ago • 1 comments

Source available at https://github.com/NixOS/nixpkgs/blob/66f2bf71eb459ec22892fb981fdf1b00f0a148dc/pkgs/development/tools/ocaml/opam/opam-shebangs.patch

The script seems pretty complex and relatively scary but maybe it would be nice for nix users to have more packages work out of the box for them.

From what i understand this script live-patches the shebangs of the scripts used when running a script directly with ./script (e.g. build: ["./configure"]) to rename it to use #!/nix/.../bin... instead of #!/bin...

cc resident nix expert @RyanGibb what do you think of this script?

kit-ty-kate avatar Jul 04 '24 13:07 kit-ty-kate

cc resident nix expert @RyanGibb what do you think of this script?

It looks like opam-shebangs.patch was adapted from https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/setup-hooks/patch-shebangs.sh (almost verbatim https://github.com/NixOS/nixpkgs/blob/4b1b6ee6d1a12501e9383748fa07423a0dc1718f/pkgs/build-support/setup-hooks/patch-shebangs.sh), which is a standard hook in Nixpkgs https://nixos.org/manual/nixpkgs/stable/#patch-shebangs.sh (and is indeed used separately in the Opam Nix derivation to patch src/state/shellscripts)

From what i understand this script live-patches the shebangs of the scripts used when running a script directly with ./script (e.g. build: ["./configure"]) to rename it to use #!/nix/.../bin... instead of #!/bin...

That makes sense, since that won't work in Nix as there is no /bin/bash (only /bash/sh for bootstrapping). I write my shell scripts with the portable #!/usr/bin/env bash. I've been running the trunk brunch of Opam without this branch on NixOS and haven't run into any issues, however. I wonder if Opam is doing something to the environment to make /bin/bash work? Or if all the ./configure scripts of packages I'm using are written portably? I would need to look into this.

RyanGibb avatar Jul 05 '24 08:07 RyanGibb