From 955083407ec7cefecb263c1e6b2d1915a42cb7d1 Mon Sep 17 00:00:00 2001 From: Wroclaw Date: Sun, 1 Jun 2025 18:48:45 +0200 Subject: [PATCH] pkgs/overlays/unstable-from-source: allow to provide callPackage that means that you can build package from unstable, while using dependencies for a given unstable package from stable needs more testing with nested packages and package sets, but I don't see why it wouldn't work --- pkgs/overlays/unstable-from-source.nix | 35 +++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/pkgs/overlays/unstable-from-source.nix b/pkgs/overlays/unstable-from-source.nix index dbd0728..7ff3cae 100644 --- a/pkgs/overlays/unstable-from-source.nix +++ b/pkgs/overlays/unstable-from-source.nix @@ -1,10 +1,21 @@ { unstableSource, attributeName ? "unstable", + # callPackage :: function | boolean + callPackage ? false, }: self: super: +assert self.lib.assertMsg ( + self.lib.isFunction callPackage + || self.lib.isBool callPackage +) '' + callPackage argument should be a function or a boolean. + If you want to use the callPackage from self, set it to true. + If you want to use a custom callPackage, set it to a function (pkgs.callPackage). +''; + let useUnstable = self.config.useUnstable or true; sanitizePlatform = platformConfig: self.lib.removeAttrs platformConfig [ @@ -34,7 +45,29 @@ let # when crossSystem is passed. crossSystem = sanitizePlatform self.stdenv.hostPlatform; }; + + callPackage' = if builtins.isFunction callPackage then callPackage + else if builtins.isBool callPackage && callPackage then self.callPackage + else if builtins.isBool callPackage && !callPackage then throw "this should never be evaluated" + else throw "callPackage should be a function (callPackage) or a boolean"; + + callPackagesUnstablePkgs = self.lib.mapAttrsRecursiveCond ( + attrset: !(self.lib.hasAttr "override" attrset) && attrset.recurseForDerivations or false + ) ( + _: unstablePackage: callPackage' { + # For some reason, override functor of the package has its argument set as required, + # which is totally false! the override functor can take all of those arguemnts optionally. + __functionArgs = self.lib.mapAttrs (_: _: true) (self.lib.functionArgs unstablePackage.override); + __functor = + if builtins.isFunction unstablePackage.override then unstablePackage.override + else unstablePackage.override.__functor; + } {} + ) unstablePkgs; + in { - "${attributeName}" = if useUnstable then unstablePkgs else self; + "${attributeName}" = if !useUnstable then self + # if callPackage is not false + else if builtins.isBool callPackage && !callPackage then callPackagesUnstablePkgs + else unstablePkgs; }