nixpkgs/pkgs/test
emilylange c47f245253
patch-shebangs: fix crash with shebang without trailing newline
This fixes a bug where `patchShebangs` crashes when trying to patch
files that contain only a shebang (e.g. `#!/bin/bash`) (and nothing
else) and do not end with a newline.

Such file can be produced using `printf "#!/bin/bash" > example` or
`echo -n "#!/bin/bash" > example`.

I don't understand why one would want to create such files, as they do
literally nothing, but the chromium tarball we are using started
shipping some 🫠

Full reproducer:

```nix
with import <nixpkgs> { };

stdenv.mkDerivation {
  dontUnpack = true;
  name = "patch-shebangs-no-trailing-newline-reproducer";
  postPatch = ''
    printf "#!/bin/bash" > reproducer
    chmod +x reproducer
    patchShebangs reproducer
  '';
}
```

```
❯ nix-build reproducer.nix
this derivation will be built:
  /nix/store/vmbshdkdk4a0bayw3wi21wvxyhzpcsy2-patch-shebangs-no-trailing-newline-reproducer.drv
building '/nix/store/vmbshdkdk4a0bayw3wi21wvxyhzpcsy2-patch-shebangs-no-trailing-newline-reproducer.drv'...
patching sources
patching script interpreter paths in reproducer
/nix/store/vr6wwdxkmyy44sg0gwxi10b8fc5zhwz0-stdenv-linux/setup: line 144: pop_var_context: head of shell_variables not a function context
error: builder for '/nix/store/vmbshdkdk4a0bayw3wi21wvxyhzpcsy2-patch-shebangs-no-trailing-newline-reproducer.drv' failed with exit code 1;
       last 3 log lines:
       > patching sources
       > patching script interpreter paths in reproducer
       > /nix/store/vr6wwdxkmyy44sg0gwxi10b8fc5zhwz0-stdenv-linux/setup: line 144: pop_var_context: head of shell_variables not a function context
       For full logs, run 'nix log /nix/store/vmbshdkdk4a0bayw3wi21wvxyhzpcsy2-patch-shebangs-no-trailing-newline-reproducer.drv'.
```
2023-09-16 14:20:56 +02:00
..
cc-wrapper tests.cc-wrapper: show command output on different line 2023-09-07 22:36:16 +03:00
coq
cross tests.cross.sanity: add armv5tel and armv6l 2023-08-15 19:11:09 -07:00
cuda
cue
dhall
dotnet
haskell Merge master into haskell-updates 2023-07-26 00:13:28 +00:00
hooks
install-shell-files
ld-library-path
macos-sierra-shared
make-binary-wrapper tests.makeBinaryWrapper: fix cross test on aarch64-linux 2023-09-15 08:48:31 +03:00
make-hardcode-gsettings-patch
make-wrapper
nixos-functions
nixpkgs-check-by-name tests.nixpkgs-check-by-name: Fix with parallel tests 2023-09-12 01:07:47 +02:00
php
simple
stdenv patch-shebangs: fix crash with shebang without trailing newline 2023-09-16 14:20:56 +02:00
stdenv-inputs
texlive texlive.bin.core-big: enable upmendex 2023-08-29 16:16:15 +01:00
top-level pkgs/top-level: use lib.systems.equals for crossSystem 2023-09-13 07:22:52 +03:00
vim
config.nix
default.nix pkgs/top-level: use lib.systems.equals for crossSystem 2023-09-13 07:22:52 +03:00
kernel.nix
overriding.nix