nixos-configuration/pkgs/overlays/unstable-from-source.nix
Wroclaw 955083407e 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
2025-06-01 18:48:45 +02:00

73 lines
2.6 KiB
Nix

{
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 [
"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 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 self
# if callPackage is not false
else if builtins.isBool callPackage && !callPackage then callPackagesUnstablePkgs
else unstablePkgs;
}