Merge pull request #176380 from hercules-ci/simplify-mkDerivation

Simplify `mkDerivation`
This commit is contained in:
John Ericson 2022-06-05 12:26:34 -04:00 committed by GitHub
commit a4af21c0d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,14 +10,8 @@ let
inherit (stdenv) hostPlatform;
};
makeOverlayable = mkDerivationSimple:
fnOrAttrs:
if builtins.isFunction fnOrAttrs
then makeDerivationExtensible mkDerivationSimple fnOrAttrs
else makeDerivationExtensibleConst mkDerivationSimple fnOrAttrs;
# Based off lib.makeExtensible, with modifications:
makeDerivationExtensible = mkDerivationSimple: rattrs:
makeDerivationExtensible = rattrs:
let
# NOTE: The following is a hint that will be printed by the Nix cli when
# encountering an infinite recursion. It must not be formatted into
@ -48,14 +42,14 @@ let
f0 self super
else x;
in
makeDerivationExtensible mkDerivationSimple
makeDerivationExtensible
(self: let super = rattrs self; in super // f self super))
args;
in finalPackage;
# makeDerivationExtensibleConst == makeDerivationExtensible (_: attrs),
# but pre-evaluated for a slight improvement in performance.
makeDerivationExtensibleConst = mkDerivationSimple: attrs:
makeDerivationExtensibleConst = attrs:
mkDerivationSimple
(f0:
let
@ -67,12 +61,10 @@ let
f0 self super
else x;
in
makeDerivationExtensible mkDerivationSimple (self: attrs // f self attrs))
makeDerivationExtensible (self: attrs // f self attrs))
attrs;
in
makeOverlayable (overrideAttrs:
mkDerivationSimple = overrideAttrs:
# `mkDerivation` wraps the builtin `derivation` function to
@ -485,6 +477,10 @@ lib.extendDerivation
# should be made available to Nix expressions using the
# derivation (e.g., in assertions).
passthru)
(derivation derivationArg)
(derivation derivationArg);
)
in
fnOrAttrs:
if builtins.isFunction fnOrAttrs
then makeDerivationExtensible fnOrAttrs
else makeDerivationExtensibleConst fnOrAttrs