-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Indented strings do not work with tabs #3759
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
Comments
We can't change this because it would be incompatible (it could cause the result of evaluating a derivation to change). |
If anyone else except me still wants to use tabs in their Nix files – this may help you: stripTabs = text: let
# Whether all lines start with a tab (or is empty)
shouldStripTab = lines: builtins.all (line: (line == "") || (pkgs.lib.strings.hasPrefix " " line)) lines;
# Strip a leading tab from all lines
stripTab = lines: builtins.map (line: pkgs.lib.strings.removePrefix " " line) lines;
# Strip tabs recursively until there are none
stripTabs = lines: if (shouldStripTab lines) then (stripTabs (stripTab lines)) else lines;
in
# Split into lines. Strip leading tabs. Concat back to string.
builtins.concatStringsSep "\n" (stripTabs (pkgs.lib.strings.splitString "\n" text)); Usage: myConfigExtraString = (stripTabs ''
Some
multiline
text
''); |
Other line terminators (i.e. CRLF) also prevent the removal of leading whitespace. |
I think that warrants a reopen. |
Not really. For once I'll have to agree with @edolstra, this behavior cannot really be adjusted, as long as nix does not have any kind of language versioning or other process for breaking changes, because as he said "it could cause the result of evaluating a derivation to change". |
@ajkovar Yes and no. Just because of this doesn't mean the issue cannot be resolved at all. Some possible alternative solutions off the hat:
|
Actually, this has another, more severe implication: Some tools like git automatically adjust line endings to the preferred flavor of the host platform. With this behavior, this may silently change derivations. |
I think adding new syntax or built-in functions just for this issue is over the top. However, I would like to see a warning in such cases, since such issues with whitespace are very subtle. It took a lot of time until I discovered that the line terminators were causing the problem. |
Is your feature request related to a problem? Please describe.
The manual says about indented strings:
This is exclusive to spaces and won't work on files indented using tabs.
Describe the solution you'd like
I'd like to have it work with tabs as well.
Describe alternatives you've considered
Additional context
I use tabs for indentation. Programming languages should not force me to use spaces for some features to work.
The text was updated successfully, but these errors were encountered: