Commit 30809cce authored by Yueh-Shun Li's avatar Yueh-Shun Li
Browse files

stdenv.mkDerivation: simplify overrideAttrs with extends and toOverlay

parent 11c20cd3
Loading
Loading
Loading
Loading
+2 −20
Original line number Diff line number Diff line
@@ -67,26 +67,8 @@ let
      #              ^^^^

      overrideAttrs = f0:
        let
          f = self: super:
            # Convert f0 to an overlay. Legacy is:
            #   overrideAttrs (super: {})
            # We want to introduce self. We follow the convention of overlays:
            #   overrideAttrs (self: super: {})
            # Which means the first parameter can be either self or super.
            # This is surprising, but far better than the confusion that would
            # arise from flipping an overlay's parameters in some cases.
            let x = f0 super;
            in
              if builtins.isFunction x
              then
                # Can't reuse `x`, because `self` comes first.
                # Looks inefficient, but `f0 super` was a cheap thunk.
                f0 self super
              else x;
        in
        makeDerivationExtensible
            (self: let super = rattrs self; in super // (if builtins.isFunction f0 || f0?__functor then f self super else f0));
          (lib.extends (lib.toExtension f0) rattrs);

      finalPackage =
        mkDerivationSimple overrideAttrs args;