| 17 May 2026 |
piegames | This is the reason why ''\{ could not be deprecated | 14:34:54 |
trudwin | Another question I was also stumbling into while working on this topic. Is there an idiomatic why to keep some trailing whitespace in indented strings? Let's consider the following code:
let
markdown = ''
**Headline:**
code snippet
'';
in
...
If I remove the first line of the markdown snipped (i.e. the "headline"), the additional indent of the code snippet gets trimmed. So instead of
code snippet
the resulting string value would be:
code snippet
Is there some why to represent indented code block inside an indented string?
| 18:19:42 |
trudwin | I guess I could do the following:
let
markdown = ''
code snippet
${""}'';
in
...
This would basically use the ${""} just in front on the closing quotes to mark the indent of the string. Not sure if there is a better way to do that in the Nix language. However, I guess this case might be rarely relevant. I currently consider to just kind of ignore this edge case for now.
| 18:25:28 |
| Nuwa changed their profile picture. | 22:24:07 |
| Nuwa changed their profile picture. | 23:19:37 |
| Nuwa changed their profile picture. | 23:41:13 |
| 18 May 2026 |
piegames | In reply to @trudwin:matrix.org
I guess I could do the following:
let
markdown = ''
code snippet
${""}'';
in
...
This would basically use the ${""} just in front on the closing quotes to mark the indent of the string. Not sure if there is a better way to do that in the Nix language. However, I guess this case might be rarely relevant. I currently consider to just kind of ignore this edge case for now.
No, this is indeed the best currently available workaround | 07:30:41 |
| cesare joined the room. | 10:03:14 |
| @afarawaystar:matrix.org left the room. | 14:16:59 |
toonn | I find myself doing `// optionalAttrs (attrs ? a) { inherit (attrs) a; }` a lot. Is there a nice way to shorten that? I naively tried `attrs: attrname: optionalAttrs (attrs ? "${attrname}") { inherit (attrs) "${attrname}"; }` but dynamic attributes aren't allowed in inherit, I assume `{ ${attrname} = attrs.${attrname}; }` would work but "nice" was left behind somewhere along the road... | 15:47:25 |
piegames | Uh, is this not just a fancy filterAttrs? | 15:48:52 |
piegames | // filterAttrs (n: _: n == "attrname") attrs | 15:49:30 |
llakala | filterAttrs is heavier, requiring a whole removeAttrs | 15:53:23 |
llakala | I personally choose not to use optionalAttrs in that way, instead choosing
${if cond then "foo" else null} = value;
xovidium has said that empty merges are free on new nix versions though
| 15:54:44 |
llakala | (I've been working close to the metal on mkDerivation, which makes me performance minded) | 15:55:17 |
llakala | * | 15:57:12 |
toonn | I have the same reservation about filterAttrs. The lambda also kinda obscures what's going on, it's too powerful in a way. | 17:03:03 |
toonn | Hadn't considered a dynamic attribute with if-then-else. Useful for multiple attributes at a time but I do feel like it's more obscure. | 17:05:00 |
| Arcadia (Cady) Rose joined the room. | 17:09:05 |
| 19 May 2026 |
| Nuwa changed their profile picture. | 14:56:39 |
| todo joined the room. | 15:41:02 |
Nuwa | Redacted or Malformed Event | 20:24:00 |
| amadaluzia changed their profile picture. | 20:58:44 |
| 20 May 2026 |
| nahsi joined the room. | 09:09:48 |
| nahsi left the room. | 09:41:01 |
| nahsi joined the room. | 09:48:48 |
| Nuwa changed their profile picture. | 21:00:54 |
| Nuwa changed their display name from Hazel to Aspen. | 22:37:52 |
| 21 May 2026 |
| rajudev joined the room. | 00:00:20 |
| @moatx:matrix.org removed their profile picture. | 15:47:26 |