tazjin / nix-1p

A (more or less) one page introduction to Nix, the language.
https://code.tvl.fyi/about/nix/nix-1p
896 stars 24 forks source link

Adding examples (or additional explanation) for the merge operator . #16

Closed miker closed 11 months ago

miker commented 11 months ago

Lines 129 - 132 the merge operator.

| `left // right`      | Merge `left` & `right` attribute sets, with the right set taking precedence |

Make sure to understand the `//`-operator, as it is used quite a lot and is
probably the least familiar one.

The note says to focus on the merge operator and to make sure to understand it but no real examples are provided nor is merge discussed in the rest of the document.

Is there a way we could add a solid example or two, or perhaps an additional section explaining how/why to use merge.

I think I understand it but feel explaining the operator more would be very helpful. Especially after making a point of adding the note stating to make sure to understand it. Also searching for // is a pain.

The nix docs don't really explain merge either.

{ x = 1; y = 2; } // { z = 3; }

Merge two sets (attributes in the right-hand set taking precedence)

Thanks!

tazjin commented 11 months ago

Hey! Yes, good point, I think I'll add a little section about it (also mentioning that it doesn't do recursive merges etc.).

miker commented 11 months ago

Wow, thanks for the quick response! That would be awesome.

I read the doc and it is a great quick intro to nix. Thanks for putting it together 🙂

tazjin commented 11 months ago

Thanks, glad to hear it :)

New section is pending review here: https://cl.tvl.fyi/c/depot/+/9599/

miker commented 11 months ago

New section and examples look great. The examples are succinct and easy to understand.

Thanks for the insane turnaround time on adding this 🙂

tazjin commented 11 months ago

Thanks for the insane turnaround time on adding this

When you work for a big company it's nice to keep some personal projects around which let you move fast ;)