Skip to content

Remove `with` and `rec`

Rebecca Turner requested to merge rebeccat/ghc.nix:remove-with-rec into main

with and rec are considered anti-patterns:

  • with makes it unclear where variables are assigned and what variables refer to.

    Instead of with pkgs; [ foo ], write [ pkgs.foo ] directly.

  • rec also makes it unclear what variables refer to and makes it easy to introduce subtle bugs.

    Instead of rec { a = 1; b = a; }, use a let binding:

    let a = 1; b = a; in { inherit a b; }

See: https://nix.dev/guides/best-practices

Merge request reports

Loading