{ unstableSource, attributeName ? "unstable", # callPackage :: function | boolean callPackage ? false, }: self: super: let useUnstable = self.config.useUnstable or true; sanitizePlatform = platformConfig: self.lib.removeAttrs platformConfig [ "emulator" "emulatorAvailable" "darwinSdkVersion" "darwinMinVersion" "parsed" ]; # if overlay is found in previous layer, then it was provided in "overlays" argument # otherwise, it is provided in "crossOverlays" argument. overlays = self.lib.groupBy (overlay: if self.lib.elem overlay self.buildPackages.overlays then "allLayers" else "finalLayer" ) self.overlays; unstablePkgs = import unstableSource { # localSystem -> pkgs.stdenv.buildPlatform localSystem = sanitizePlatform self.stdenv.buildPlatform; # crossSystem -> pkgs.stdenv.hostPlatform or pkgs.stdenv.targetPlatform ?? # passing below # config -> pkgs.config config = self.config; # overlays -> pkgs.buildPackages.overlays overlays = overlays.allLayers; # crossOverlays -> pkgs.overlays without pkgs.buildPackages.overlays crossOverlays = overlays.finalLayer; } // self.lib.optionalAttrs ( self.lib.systems.equals self.stdenv.buildPlatform self.stdenv.hostPlatform ) { # workaround for some odd structured packages that changes behaviour # 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 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). ''; 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 self # if callPackage is not false else if !(builtins.isBool callPackage && !callPackage) then callPackagesUnstablePkgs else unstablePkgs; }