nixos-configuration/pkgs/overlays/unstable-from-source.nix
Wroclaw 2d88df163a pkgs/overlays/unstable-from-source: fix infinite recursion in assert
also fix checking of callPackage argument, it was opposite
2025-06-01 19:45:20 +02:00

68 lines
2.5 KiB
Nix

{
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"
];
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 -> partial of pkgs.overlays
overlays = self.overlays;
# crossOverlays -> partial of pkgs.overlays
# crossOverlays are merged to overlays, not sure what issues that might raise.
# ignoring.
} // 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;
}