rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

[RFC 0120] Discourage nested `with` expressions

Open fogti opened this issue 3 years ago • 7 comments

Rendered

This has come up while trying to implement alternative interpreters/evaluators for the Nix language, and similar tools which need to perform static analysis on Nix expressions.

This idea is a compromise. The original idea was to forbid with expressions completely, which proved to be undesirable and impratical. A related idea was the introduction of a with-only expression, but it (1) wouldn't completely solve the problem and (2) introduce another keyword with no apparent immediate benefit.

This issue was discussed quite a few times on various channels, and this is an attempt to move closer to a solution.

cc @sternenseemann

fogti avatar Jan 12 '22 19:01 fogti

Related: #110

L-as avatar Jan 12 '22 22:01 L-as

For the record let me explain what @L-as means by noting inherit-as-list RFC. Assuming this RFC gets implemented - there is no need for with-only expressions due to syntaxes as such:

# Basic usecase:
meta = {
  inherit homepage; # inherit in attribute set
  license = with licenses; [ inherit (lib.licenses) mit  ]; # inherit in list
}

# Not so obvious syntax
let inherit (lib) mapAttrs filterAttrs; in {
  a = mapAttrs (a: b: xyz) abc;
  b = filterAttrs (it: xyz) abc;
}

gytis-ivaskevicius avatar Jan 14 '22 14:01 gytis-ivaskevicius

This RFC is now again open for nominations :)

lheckemann avatar Apr 20 '22 13:04 lheckemann

This RFC has not gotten any nominations which appears to show lack of interest from the community. In order to drive this RFC forward I recommend trying to help find shepherds by reaching out to people you know and posting in discourse or Matrix.

If no shepherds can be found we will convert this RFC to draft to be on hold until we can find enough interested participants.

kevincox avatar May 04 '22 13:05 kevincox

To re-iterate the previous comment, this RFC will require some shepherds in the next two weeks otherwise will be turned into a draft awaiting further interest.

tomberek avatar Jun 01 '22 13:06 tomberek

A simpler alternative to this would be to "just" forbid mutual imports combined with with-expressions, because these prevent the import structure from forming a DAG, and have no unambiguous translation to explicit fixed points (lib in nixpkgs is an unambiguous and explicit fix point); which is the case which triggered the problem in the first place, because "no unambiguous translation" means that interpreting nix files separately or on a one-by-one basis is hard, because the scope is temporarily ambiguous...

fogti avatar Jun 01 '22 22:06 fogti

Related: https://github.com/NixOS/nixpkgs/pull/294383 https://github.com/NixOS/nixpkgs/issues/292468#issuecomment-2016454242 https://github.com/NixOS/nixpkgs/pull/298316/files

AndersonTorres avatar Mar 25 '24 03:03 AndersonTorres