!tDnwWRNkmmYtMXfaZl:nixos.org

Nix Language

1667 Members
Nix programming language301 Servers

Load older messages


SenderMessageTime
15 Apr 2025
@emilazy:matrix.orgemilyNix doesn't know about Bash syntax15:50:27
@emilazy:matrix.orgemilyand Bash heredocs don't strip indentation15:50:33
@pc:rrier.frpcarrierI don't see how that relates to bash?15:50:39
@emilazy:matrix.orgemily you have two spaces before the ${, but the '' … '' string does not have any spaces after newlines 15:50:47
@pc:rrier.frpcarrierI'm running into this generating YAML files too15:50:50
@emilazy:matrix.orgemily

it expands to

cat <<EOF
  this:
- should be indented
EOF
15:51:06
@emilazy:matrix.orgemily because of the two spaces on the line before ${'' 15:51:17
@pc:rrier.frpcarrierwhy is the second line not indented?15:51:28
@emilazy:matrix.orgemilywhy would it be?15:51:38
@pc:rrier.frpcarrierto preserve indentation I guess?15:51:47
@emilazy:matrix.orgemily but the ${'' … ''} doesn't know anything about the string it's being embedded in. 15:52:05
@emilazy:matrix.orgemily it just evaluates '' … ''. 15:52:10
@emilazy:matrix.orgemily that results in "this:\n- should be indented" 15:52:17
@qyriad:katesiria.orgQyriad there are the same number of spaces before `this` as are before `-`, so the same number of spaces gets stripped 15:52:31
@emilazy:matrix.orgemily

would you expect

            cat <<EOF
              ${"this\n- should be indented"}
            EOF

to modify the string you're interpolating in?

15:52:40
@pc:rrier.frpcarrier no, I would expect '' '' strings to behave differently from " strings 15:53:19
@pc:rrier.frpcarrierI guess I was hoping indentation would be observed where it's not15:53:45
@emilazy:matrix.orgemily

but the expressions "this\n- should be indented\n" and

''
  this
  - should be indented
''

are exactly equal

15:54:03
@emilazy:matrix.orgemily(missed the trailing newline last time)15:54:17
@emilazy:matrix.orgemily and ${…} just evaluates and interpolates an expression 15:54:18
@qyriad:katesiria.orgQyriad I can't think of any languages where the multiline string syntax would do what you're describing 15:54:47
@emilazy:matrix.orgemilythere 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 string15:54:53
@emilazy:matrix.orgemilyI 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 them15:55:20
@pc:rrier.frpcarrierinterested in structured YAML generation for sure15:55:40
@qyriad:katesiria.orgQyriad lib.generators.toYAML 15:55:52
@emilazy:matrix.orgemily or pkgs.formats.yaml and pkgs.format.yaml_1_1 for module option stuff 15:56:38
@emilazy:matrix.orgemily to put it another way, let x = …; in ''foo${x}bar'' and ''foo${…}bar'' should always be exactly equal 15:57:48
@pc:rrier.frpcarrierlib.generators.toYAML is perfect, thanks16:04:06
@pc:rrier.frpcarrierCan 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 checkout20:59:36
@noskcaj:matrix.org@noskcaj:matrix.org left the room.21:30:34

Show newer messages


Back to Room ListRoom Version: 6