Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid regular expression breaks kresd NixOS module #156861

Closed
puppe opened this issue Jan 26, 2022 · 6 comments · Fixed by #156867
Closed

Invalid regular expression breaks kresd NixOS module #156861

puppe opened this issue Jan 26, 2022 · 6 comments · Fixed by #156867
Assignees

Comments

@puppe
Copy link
Contributor

puppe commented Jan 26, 2022

Describe the bug

There is an error in the kresd NixOS module. The changed regular expression introduced in #153610 is invalid.

error: invalid regular expression '([0-9.]+):([0-9]+)()'

       at /nix/store/ldq0kzflyiy4ip2l1fpdqbhsgcrpal3x-source/nixos/modules/services/networking/kresd.nix:12:13:

           11|   mkListen = kind: addr: let
           12|     al_v4 = builtins.match "([0-9.]+):([0-9]+)()" addr;
             |             ^
           13|     al_v6 = builtins.match "\\[(.+)]:([0-9]+)(%.*|$)" addr;

Steps To Reproduce

Steps to reproduce the behavior:

  1. Add the following to a NIxOS configuration: services.kresd.enable = true;
  2. Evaluate the configuration.

Expected behavior

I guess, the regular expression should not be invalid and thereby should not cause an error during evaluation.

Additional context

This can also be reproduced in nix repl:

nix-repl> builtins.match "([0-9.]+):([0-9]+)()" "127.0.0.1:53"
error: invalid regular expression '([0-9.]+):([0-9]+)()'

       at «string»:1:1:

            1| builtins.match "([0-9.]+):([0-9]+)()" "127.0.0.1:53"
             | ^
            2|


Notify maintainers

@vcunat

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"aarch64-darwin"`
 - host os: `Darwin 21.2.0, macOS 12.1`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.5.1`
 - channels(root): `"nixpkgs-22.05pre345162.81f05d871fa"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`
@puppe
Copy link
Contributor Author

puppe commented Jan 26, 2022

Maybe there are differences in builtins.match between Nix 2.3 and Nix 2.5. I have just tested this on another host:

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"                                                                                                                                                                                                                                                                     
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.91, NixOS, 21.11 (Porcupine)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.3.16`
 - channels(root): `"nixos-21.11.335288.3ddd960a3b5"`
 - channels(martin): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`

[user@system:~]$ nix repl                                                                                                                                                                                                                                                                                                      
Welcome to Nix version 2.3.16. Type :? for help.

nix-repl> builtins.match "([0-9.]+):([0-9]+)()" "127.0.0.1:53"
[ "127.0.0.1" "53" "" ]

Edit: There are differences in builtins.match between Darwin and Linux.

@puppe
Copy link
Contributor Author

puppe commented Jan 26, 2022

NixOS/nix#1537 might be related.

puppe added a commit to puppe/nixpkgs that referenced this issue Jan 26, 2022
Empty parantheses are not supported in regular expressions on
Darwin/macOS. The old regular expression produces an error during
evaluation. This commit fixes that.

Nix‘s `builtins.match` works with extend POSIX regular expressions. The
specification for these regular expression states[^1] that the result
for a left paranthesis immediately followed by a right paranthesis
outside of a bracket expression is undefined.

[^1]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04_03
@vcunat vcunat self-assigned this Jan 26, 2022
@puppe
Copy link
Contributor Author

puppe commented Jan 26, 2022

I submitted a pull request that should fix this. See #156867.

@vcunat
Copy link
Member

vcunat commented Jan 26, 2022

This is the obnoxious thing that Nix takes the regexp engine from the C++ library, but the standard does not define such details, so different people platforms get different things. On my NixOS the regexp is accepted.

@vcunat
Copy link
Member

vcunat commented Jan 26, 2022

Just my curiosity: you don't use the code to run kresd on a darwin, right? (just to evaluate a NixOS system)

@vcunat vcunat linked a pull request Jan 26, 2022 that will close this issue
13 tasks
@puppe
Copy link
Contributor Author

puppe commented Jan 26, 2022

Just my curiosity: you don't use the code to run kresd on a darwin, right? (just to evaluate a NixOS system)

The Nix expressions are evaluated on my Macbook (aarch64-darwin), and then the derivations are built on a NixOS host (x86_64-linux). See https://nixos.org/manual/nix/stable/advanced-topics/distributed-builds.html and https://nixos.wiki/wiki/Distributed_build for details.

Edit: Yes, I evaluate the kresd module for a NixOS system.

github-actions bot pushed a commit that referenced this issue Jan 26, 2022
Empty parantheses are not supported in regular expressions on
Darwin/macOS. The old regular expression produces an error during
evaluation. This commit fixes that.

Nix‘s `builtins.match` works with extend POSIX regular expressions. The
specification for these regular expression states[^1] that the result
for a left paranthesis immediately followed by a right paranthesis
outside of a bracket expression is undefined.

[^1]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap09.html#tag_09_04_03

(cherry picked from commit 6a96992)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants