Merge pull request #67809 from Infinisil/propagate-override-args

lib.makeOverridable: Propagate function arguments
This commit is contained in:
Silvan Mosberger 2019-10-22 14:37:40 +02:00 committed by GitHub
commit 1230fc8674
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 15 deletions

View file

@ -66,22 +66,31 @@ rec {
*/ */
makeOverridable = f: origArgs: makeOverridable = f: origArgs:
let let
ff = f origArgs; result = f origArgs;
# Creates a functor with the same arguments as f
copyArgs = g: lib.setFunctionArgs g (lib.functionArgs f);
# Changes the original arguments with (potentially a function that returns) a set of new attributes
overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs); overrideWith = newArgs: origArgs // (if lib.isFunction newArgs then newArgs origArgs else newArgs);
# Re-call the function but with different arguments
overrideArgs = copyArgs (newArgs: makeOverridable f (overrideWith newArgs));
# Change the result of the function call by applying g to it
overrideResult = g: makeOverridable (copyArgs (args: g (f args))) origArgs;
in in
if builtins.isAttrs ff then (ff // { if builtins.isAttrs result then
override = newArgs: makeOverridable f (overrideWith newArgs); result // {
overrideDerivation = fdrv: override = overrideArgs;
makeOverridable (args: overrideDerivation (f args) fdrv) origArgs; overrideDerivation = fdrv: overrideResult (x: overrideDerivation x fdrv);
${if ff ? overrideAttrs then "overrideAttrs" else null} = fdrv: ${if result ? overrideAttrs then "overrideAttrs" else null} = fdrv:
makeOverridable (args: (f args).overrideAttrs fdrv) origArgs; overrideResult (x: x.overrideAttrs fdrv);
}) }
else if lib.isFunction ff then { else if lib.isFunction result then
override = newArgs: makeOverridable f (overrideWith newArgs); # Transform the result into a functor while propagating its arguments
__functor = self: ff; lib.setFunctionArgs result (lib.functionArgs result) // {
overrideDerivation = throw "overrideDerivation not yet supported for functors"; override = overrideArgs;
} }
else ff; else result;
/* Call the package function in the file `fn' with the required /* Call the package function in the file `fn' with the required

View file

@ -1,7 +1,7 @@
{ stdenv, lib, symlinkJoin, gimp, makeWrapper, gimpPlugins, gnome3, plugins ? null}: { stdenv, lib, symlinkJoin, gimp, makeWrapper, gimpPlugins, gnome3, plugins ? null}:
let let
allPlugins = lib.filter (pkg: builtins.isAttrs pkg && pkg.type == "derivation" && !pkg.meta.broken or false) (lib.attrValues gimpPlugins); allPlugins = lib.filter (pkg: lib.isDerivation pkg && !pkg.meta.broken or false) (lib.attrValues gimpPlugins);
selectedPlugins = if plugins == null then allPlugins else plugins; selectedPlugins = if plugins == null then allPlugins else plugins;
extraArgs = map (x: x.wrapArgs or "") selectedPlugins; extraArgs = map (x: x.wrapArgs or "") selectedPlugins;
versionBranch = stdenv.lib.versions.majorMinor gimp.version; versionBranch = stdenv.lib.versions.majorMinor gimp.version;