NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.05k stars 1.47k forks source link

the empty string is only a valid regex when built with libstdc++ and not with libc++ #7208

Open symphorien opened 1 year ago

symphorien commented 1 year ago

Describe the bug

builtins.match "" "" evaluates only on linux and on darwin. This seems silly but leads to problems, see https://github.com/NixOS/nixpkgs/pull/177273#issuecomment-1287562800

Steps To Reproduce

  1. run nix repl
  2. type builtins.match "" ""
  3. returns [] on linux and error: invalid regular expression '' on darwin

Expected behavior

Same behavior. An error is probably a better idea but I wonder for backward compatibility. The issue I link suggests such an abuse in nixpkgs would have been noticed, so the worry about backward compat is only for other code bases.

nix-env --version output nix-env (Nix) 2.8.1

Additional context https://github.com/NixOS/nixpkgs/pull/197374

SharzyL commented 3 months ago

I also encountered this issue (when struggling with https://github.com/nix-community/home-manager/blob/master/modules/services/gpg-agent.nix#L51).

Consisteny between platforms should be important for Nix. Since libc++ and libstdc++ are not consistent, maybe we can

  1. Treat empty string regex specially to ensure the same result on both platforms.
  2. Or switch to something other than std::regex