[Nix-dev] [***SPAM***] Use Function Application To Escape Override Hell

William Casarin bill at casarin.me
Fri Oct 16 09:08:01 CEST 2015


Hey Peter,

On Wed, Oct 14, 2015 at 7:46 AM, Peter Simons <simons at cryp.to> wrote:
> [..] The expression "callPackage f args" translates to "stdenv.lib.callPackageWith
> self f args". "callPackageWith" [2] then uses reflection to determine the names
> of all arguments expected by "f". It finds those names that don't exist in
> "args" in "self" and adds them to "args" to complete the function call. In
> other words, parameters of "f" that are not specified in "args" are
> automatically filled in from "self" --- the Haskell package set. This is why
> system packages are passed explicitly ("self" doesn't contain them), but
> Haskell dependencies are not ("self" does contain them).

Thanks for explaining this! I've always wondered how this magic works,
it makes a lot of sense now.

> Possible Improvements
> [..]
> So maybe it would be best to batch all those variant options in an attribute set
> of their own? [..]
> This approach allows us to call "hslua { config.doCheck = false; }", which
> seems nice enough.

I like this approach. It's simple and less magical.

How would this look from the user side of things? Let's say I wanted to use a
custom version of hslua in my project. Currently I do something like this:

    haskellPackages = baseHaskellPackages.override {
      hslua = overrideCabal super.hslua (attrs: {
        version = "2.0.8";
        src = pkgs.fetchFromGitHub {
          owner = "jb55";
          repo = "hslua";
          rev = "632f0eaafa3b898937798e649be72b85410ff0d6";
          sha256 = "0j3a88cd49g3xx1xhlpxz5n5ps4ppj66cmllf8mcdd3jpc7v1az5";
        };
      });
    }

I'm having a hard time visualizing what this would now look like in the proposed
approaches.

> An entirely different approach is to take advantage of lazy evaluation to
> define all possible build variants at once

This approach seems super janky to me, wouldn't there be a combinatorial
explosion of variants?

Cheers,
William


More information about the nix-dev mailing list