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

Escape sequences not handled properly #189

Open
thefossguy opened this issue Apr 7, 2024 · 5 comments
Open

Escape sequences not handled properly #189

thefossguy opened this issue Apr 7, 2024 · 5 comments
Assignees
Labels
bug Something isn't working correctness Output parses differently after formatting

Comments

@thefossguy
Copy link
Member

Description

It appears that nixfmt does not preserve backslashes. I have the following two lines in my darwin.nix:

https://github.com/thefossguy/prathams-nixos/blob/6acda3f9c27516b81a29d718ea1cb3b1025f86b6/nixos-configuration/home-manager/darwin.nix#L56-L57

And this got mangled like so:

-      "^\Uf702" = "moveWordLeft:"; # Ctrl-<Left>
-      "^\Uf703" = "moveWordRight:"; # Ctrl-<Right>
+      "^Uf702" = "moveWordLeft:"; # Ctrl-<Left>
+      "^Uf703" = "moveWordRight:"; # Ctrl-<Right>
@piegamesde piegamesde self-assigned this Apr 9, 2024
@piegamesde piegamesde added bug Something isn't working correctness Output parses differently after formatting labels Apr 9, 2024
@piegamesde
Copy link
Member

piegamesde commented Apr 14, 2024

These strings are semantically equivalent in Nix:

nix-repl> "^\Uf702"
"^Uf702"
nix-repl> "^\Uf702" == "^Uf702"
true

Not sure if nixfmt should preserve the input regardless or not. On the one hand I want it to treat strings as opaque and never change them, on the other hand normalizing this here has the potential of uncovering very subtle bugs.

@thefossguy
Copy link
Member Author

I don't even remember why I have that key specific string in the key binding but it looks like Nix is actually writing the "incorrect" string to the target file.

https://github.com/nix-community/home-manager/blob/e84811035d7c8ec79ed6c687a97e19e2a22123c1/modules/targets/darwin/keybindings.nix#L41-L42

Contents of ~/Library/KeyBindings/DefaultKeyBinding.dict:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>^Uf702</key>
	<string>moveWordLeft:</string>
	<key>^Uf703</key>
	<string>moveWordRight:</string>
</dict>
</plist>

And it works. So not an issue at all. Sorry for the trouble :)

@infinisil
Copy link
Member

Not sure if nixfmt should preserve the input regardless or not. On the one hand I want it to treat strings as opaque and never change them, on the other hand normalizing this here has the potential of uncovering very subtle bugs.

I think we should preserve the input regardless, because it's not nixfmt's job to fix these kind of problems. Instead it should be Nix itself that does that.

And we do have that in the standard:

The non-interpolated string parts must be preserved from the input.

And by preserving this we can also simplify the code because we don't need to think as much about how Nix parses strings.

If you don't mind, let's leave this open for now :)

@infinisil infinisil reopened this Apr 15, 2024
@infinisil
Copy link
Member

We very briefly discussed this in todays team meeting:

  • Not entirely sure how this ends up happening at all
  • Must be somewhere in the parser
  • @infinisil: The strings shouldn't be touched at all, would be good to figure this out

@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/formatting-team-meeting-2024-04-16/43533/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctness Output parses differently after formatting
Projects
Status: Todo
Development

No branches or pull requests

4 participants