ocaml / opam

opam is a source-based package manager. It supports multiple simultaneous compiler installations, flexible package constraints, and a Git-friendly development workflow.
https://opam.ocaml.org
Other
1.21k stars 348 forks source link

TODO: port Nixpkgs' patch_shebangs.sh #6070

Open kit-ty-kate opened 1 week ago

kit-ty-kate commented 1 week ago

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?

RyanGibb commented 1 week ago

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.