toraritte.github.io

with considered harmful in Nix expressions

Expanding slightly on the Nix anti-patterns sub-section, with attrset; ... expression at nix.dev. It points to the NixOS/nix issue #490 with a more detailed discussion.

Workarounds

Both the post and the issue lists the detrimental effects using with but there is only one suggestion:

let lib = something.very.long; in { lib.foo /*etc..*/ }

What about using with to simplify input lists? (Such as buildInputs in nix-shell expressions)

That is:

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {

  buildInputs = with pkgs; [
    # ...
  ];

  # ...
}

easy-purescript-nix provides alternatives by using builtins.attrValues:

{ pkgs ? import <nixpkgs> {} }:

let
  default = import ./default.nix {};

  buildInputs = builtins.attrValues {
    inherit (pkgs) gnumake which;

    inherit (default) purs pulp purp psc-package dhall-simple spago pscid spago2nix purty zephyr;
  };

in
pkgs.mkShell {
  buildInputs = buildInputs;
  # or
  # inherit buildInputs;
}