15 Apr 2025 |
emily | Nix doesn't know about Bash syntax | 15:50:27 |
emily | and Bash heredocs don't strip indentation | 15:50:33 |
pcarrier | I don't see how that relates to bash? | 15:50:39 |
emily | you have two spaces before the ${ , but the '' … '' string does not have any spaces after newlines | 15:50:47 |
pcarrier | I'm running into this generating YAML files too | 15:50:50 |
emily | it expands to
cat <<EOF
this:
- should be indented
EOF
| 15:51:06 |
emily | because of the two spaces on the line before ${'' | 15:51:17 |
pcarrier | why is the second line not indented? | 15:51:28 |
emily | why would it be? | 15:51:38 |
pcarrier | to preserve indentation I guess? | 15:51:47 |
emily | but the ${'' … ''} doesn't know anything about the string it's being embedded in. | 15:52:05 |
emily | it just evaluates '' … '' . | 15:52:10 |
emily | that results in "this:\n- should be indented" | 15:52:17 |
Qyriad | there are the same number of spaces before `this` as are before `-`, so the same number of spaces gets stripped | 15:52:31 |
emily | would you expect
cat <<EOF
${"this\n- should be indented"}
EOF
to modify the string you're interpolating in?
| 15:52:40 |
pcarrier | no, I would expect '' '' strings to behave differently from " strings | 15:53:19 |
pcarrier | I guess I was hoping indentation would be observed where it's not | 15:53:45 |
emily | but the expressions "this\n- should be indented\n" and
''
this
- should be indented
''
are exactly equal
| 15:54:03 |
emily | (missed the trailing newline last time) | 15:54:17 |
emily | and ${…} just evaluates and interpolates an expression | 15:54:18 |
Qyriad | I can't think of any languages where the multiline string syntax would do what you're describing | 15:54:47 |
emily | there would need to be "spooky action at a distance" where the meaning of a Nix expression depends on whether it's embedded in an interpolation in another string, and then based on the contents of that string | 15:54:53 |
emily | I suggest using a structured YAML generator like we have in Nixpkgs if you want to generate indentation-sensitive syntax, but in this case you could map over the lines and indent them | 15:55:20 |
pcarrier | interested in structured YAML generation for sure | 15:55:40 |
Qyriad | lib.generators.toYAML | 15:55:52 |
emily | or pkgs.formats.yaml and pkgs.format.yaml_1_1 for module option stuff | 15:56:38 |
emily | to put it another way, let x = …; in ''foo${x}bar'' and ''foo${…}bar'' should always be exactly equal | 15:57:48 |
pcarrier | lib.generators.toYAML
is perfect, thanks | 16:04:06 |
pcarrier | Can I access a hash of the repo my flake is in, somehow? Not looking for the commit hash but something that would change every time I save a file in a dirty checkout | 20:59:36 |
| @noskcaj:matrix.org left the room. | 21:30:34 |