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