From af479c182ff0391aefd070f5219e79d15d655c75 Mon Sep 17 00:00:00 2001 From: Will Fancher Date: Tue, 11 Jul 2017 22:27:05 -0400 Subject: [PATCH] Added `callPackageWithSelfWith` and `callPackageWithSelf` --- lib/customisation.nix | 9 +++++++++ pkgs/top-level/splice.nix | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/lib/customisation.nix b/lib/customisation.nix index 124e8596f49..66260c8a486 100644 --- a/lib/customisation.nix +++ b/lib/customisation.nix @@ -183,6 +183,15 @@ rec { auto = builtins.intersectAttrs (builtins.functionArgs f) autoArgs; in makeOverridable f (auto // args); + # Like `callPackageWith`, but provides the function with the `self` + # argument. `fn` is called with the new `self` whenever an override + # or extension is added. + callPackageWithSelfWith = autoArgs: fn: args: + let + f = if builtins.isFunction fn then fn else import fn; + auto = builtins.intersectAttrs (builtins.functionArgs f) autoArgs; + in makeOverridableWithSelf f (auto // args); + /* Like callPackage, but for a function that returns an attribute set of derivations. The override function is added to the diff --git a/pkgs/top-level/splice.nix b/pkgs/top-level/splice.nix index 43951100de3..329a83e5a31 100644 --- a/pkgs/top-level/splice.nix +++ b/pkgs/top-level/splice.nix @@ -79,7 +79,11 @@ in # `newScope' for sets of packages in `pkgs' (see e.g. `gnome' below). callPackage = pkgs.newScope {}; + callPackageWithSelf = pkgs.newScopeWithSelf {}; + callPackages = lib.callPackagesWith splicedPackages; newScope = extra: lib.callPackageWith (splicedPackages // extra); + + newScopeWithSelf = extra: lib.callPackageWithSelfWith (splicedPackages // extra); }