!tDnwWRNkmmYtMXfaZl:nixos.org

Nix Language

1350 Members
Nix programming language237 Servers

Load older messages


SenderMessageTime
23 Apr 2024
@qyriad:katesiria.orgQyriad // isn't something like @ or ... which changes the semantics of something. // is just flat out an operator, like addition and subtraction. but rather than operating on integers (like + and -), // operates on attribute sets.

leftHandSide // rightHandSide
both side ("operands") must be attribute sets. the result of leftHandSide // rightHandSide is another attribute set, which has all the attributes in leftHandSide and all the attributes in rightHandSide, where overlapping values take precedence from rightHandSide

It's a dictionary merge, basically
20:41:55
@qyriad:katesiria.orgQyriad .override is a different story 😅 20:42:10
@grimmauld:grimmauld.deGrimmauld
In reply to @qyriad:katesiria.org
// isn't something like @ or ... which changes the semantics of something. // is just flat out an operator, like addition and subtraction. but rather than operating on integers (like + and -), // operates on attribute sets.

leftHandSide // rightHandSide
both side ("operands") must be attribute sets. the result of leftHandSide // rightHandSide is another attribute set, which has all the attributes in leftHandSide and all the attributes in rightHandSide, where overlapping values take precedence from rightHandSide

It's a dictionary merge, basically
ah so its mkMerge that doesn't complain if stuff overlaps? Interesting
20:42:50
@grimmauld:grimmauld.deGrimmauldi will use it then20:42:56
@qyriad:katesiria.orgQyriadgonna have to lookup mkMerge one sec…20:43:20
@qyriad:katesiria.orgQyriad oh dear okay, so. mkMerge is conceptually similar, but operates at a different level. mkMerge merges NixOS modules. // merges any arbitrary attrsets 20:44:09
@qyriad:katesiria.orgQyriad It's like the difference between lib.mkIf and lib.optionalAttrs, if you're familiar with those two 20:44:27
@grimmauld:grimmauld.deGrimmauld
In reply to @qyriad:katesiria.org
It's like the difference between lib.mkIf and lib.optionalAttrs, if you're familiar with those two
wait what, whats the actual diff?
20:45:39
@grimmauld:grimmauld.deGrimmauldi know both but how are they different?20:45:54
@grimmauld:grimmauld.deGrimmauldimage.png
Download image.png
20:47:18
@grimmauld:grimmauld.deGrimmauldand this is a valid replacement, so i don't quite follow how mkMerge and // is differnt if mkMerge didn'texplode before20:47:41
@grimmauld:grimmauld.deGrimmauldit does the same thing, i checked20:47:48
@grimmauld:grimmauld.deGrimmauld(gotta say i should have learnt // earlier)20:48:14
@grimmauld:grimmauld.deGrimmauldthere is some places where i use mkMerge in conjunction with mapAttrsToList, // obviously wouldn't work for that assuming no fold magic. // is a binary operator, but to me it really looks like mkMerge just is the full accumulator function to the operator // like sum is the accumulator to the operator +20:50:12
@qyriad:katesiria.orgQyriad
In reply to@grimmauld:grimmauld.de
wait what, whats the actual diff?
mkIf is probably easiet to demonstrate like this:
nix-repl> lib.mkIf true { foo = "bar"; }
{
  _type = "if";
  condition = true;
  content = { foo = "bar"; };
}
nix-repl> lib.mkIf false { foo = "bar"; }
{
  _type = "if";
  condition = false;
  content = { foo = "bar"; };
}
Compare optionalAttrs:
nix-repl> lib.optionalAttrs true { foo = "bar"; }
{ foo = "bar": }
nix-repl> lib.optionalAttrs false { foo = "bar"; }
{ }
20:54:24
@grimmauld:grimmauld.deGrimmauldaaahhh interesting! That makes sense, ty!20:55:00
@qyriad:katesiria.orgQyriad I actually haven't used mkMerge myself so I'm not actually sure what cases its used in, but I did just look at the implementation, which is this:
mkMerge = contents:
{
  _type = "merge";
  inherit contents;
};
which is definitely not the same as //. to figure out exactly what mkMerge does (since it doesn't seem to be documented…) I'd have to see what NixOS' module system does when it sees a module of _type = "merge";
20:56:30
@qyriad:katesiria.orgQyriad but in general, it's the NixOS module system that does anything with mkMerge at all. it only makes sense on NixOS module attrsets 20:57:27
@grimmauld:grimmauld.deGrimmauldit does work for all attrsets though, at least from my testing XD20:58:02
@grimmauld:grimmauld.deGrimmauldbut yeah that makes sense, guess i'll have to go through my stuff and decide whether or not it makes sense then20:58:29
@qyriad:katesiria.orgQyriad
In reply to@grimmauld:grimmauld.de
it does work for all attrsets though, at least from my testing XD
I mean definitely works in the sense that it does something, for attrsets, but try it on a derivation and you might run into some trouble =P
20:59:42
@grimmauld:grimmauld.deGrimmauldFair fair XD21:01:03
@grimmauld:grimmauld.deGrimmauldThank you for the explanations, really helped 21:04:32
@qyriad:katesiria.orgQyriadno problem! glad to help!21:05:02
24 Apr 2024
@d.tomov33:matrix.orgDaniel Tomov joined the room.06:40:22
@stablejoy:matrix.orgstablejoy changed their profile picture.08:59:09
@infinisil:matrix.orginfinisil Qyriad Grimmauld Btw there's a newish room specifically for the module system: https://matrix.to/#/%23modules:nixos.org 14:38:01
@finer2750:matrix.orgYuri joined the room.18:47:47
@zirpu:matrix.org@zirpu:matrix.org left the room.23:50:09
25 Apr 2024
@dpjyoo:matrix.orgdpjyoo joined the room.17:17:34

Show newer messages


Back to Room ListRoom Version: 6