!tDnwWRNkmmYtMXfaZl:nixos.org

Nix Language

1914 Members
Nix programming language355 Servers

Load older messages


SenderMessageTime
17 May 2026
@piegames:flausch.socialpiegames This is the reason why ''\{ could not be deprecated 14:34:54
@trudwin:matrix.orgtrudwin

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:matrix.orgtrudwin

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
@lumi:the-apothecary.clubNuwa changed their profile picture.22:24:07
@lumi:the-apothecary.clubNuwa changed their profile picture.23:19:37
@lumi:the-apothecary.clubNuwa changed their profile picture.23:41:13
18 May 2026
@piegames:flausch.socialpiegames
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:matrix.uao.mecesare joined the room.10:03:14
@afarawaystar:matrix.org@afarawaystar:matrix.org left the room.14:16:59
@toonn:matrix.orgtoonn 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:flausch.socialpiegames Uh, is this not just a fancy filterAttrs? 15:48:52
@piegames:flausch.socialpiegames // filterAttrs (n: _: n == "attrname") attrs 15:49:30
@llakala:matrix.orgllakalafilterAttrs is heavier, requiring a whole removeAttrs15:53:23
@llakala:matrix.orgllakala

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:matrix.orgllakala(I've been working close to the metal on mkDerivation, which makes me performance minded)15:55:17
@llakala:matrix.orgllakala * 15:57:12
@toonn:matrix.orgtoonn 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:matrix.orgtoonn 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
@chaotic.smol:matrix.orgArcadia (Cady) Rose joined the room.17:09:05
19 May 2026
@lumi:the-apothecary.clubNuwa changed their profile picture.14:56:39
@todoqki:matrix.orgtodo joined the room.15:41:02
@lumi:the-apothecary.clubNuwaRedacted or Malformed Event20:24:00
@amadaluzia:4d2.orgamadaluzia changed their profile picture.20:58:44
20 May 2026
@me:nahsi.devnahsi joined the room.09:09:48
@me:nahsi.devnahsi left the room.09:41:01
@me:nahsi.devnahsi joined the room.09:48:48
@lumi:the-apothecary.clubNuwa changed their profile picture.21:00:54
@lumi:the-apothecary.clubNuwa changed their display name from Hazel to Aspen.22:37:52
21 May 2026
@libregeekingkid:matrix.orgrajudev joined the room.00:00:20
@moatx:matrix.org@moatx:matrix.org removed their profile picture.15:47:26

Show newer messages


Back to Room ListRoom Version: 6