Title | Author | Discussions-To | Status | Type | Topic | Created |
---|---|---|---|---|---|---|
Refine usage of mkPolyPkg |
jonringer |
Draft |
Standards Track |
Packaging |
2024-09-22 |
Argument passing in multiple-package-versions-proposal was awkward, this creates a mkAutoCalledPolyPkgDir function which creates an overlay in which the directories in a specified directory will be automatically called with mkPolyPkg, and that partially applied function then passed to callPackage.
This separates the creation of a package which contains multiple variants and the callPackage call which should only be passing arguments needed to conduct a build.
Example PR: ekala-project/corepkgs#6
let
mkAutoCalledPolyPackageDir = baseDirectory:
let
namesForShard = lib.packageSets.mkNamesForDirectory baseDirectory;
# This is defined up here in order to allow reuse of the value (it's kind of expensive to compute)
# if the overlay has to be applied multiple times
packageFiles = mergeAttrsList (mapAttrsToList namesForShard (builtins.readDir baseDirectory));
in
# TODO: Consider optimising this using `builtins.deepSeq packageFiles`,
# which could free up the above thunks and reduce GC times.
# Currently this would be hard to measure until we have more packages
# and ideally https://github.com/NixOS/nix/pull/8895
self: _:
{
_internalCallPolyFile = file: self.callPackage (import file { inherit (self) mkPolyPkg; }) { };
}
// builtins.mapAttrs
(name: value: self._internalCallPolyFile value)
packageFiles;
polyPkgOverlay = mkAutoCalledPolyPackageDir ./polyPkgs;
in
import stdenvRepo {
overlays = [
polyPkgOverlay
...
];
}
Previously, arguments for mkPolyPkg needed to be passed along with the arguments for the underlying package, this now separates the two concerns.
# before changes
{ callPackage
, mkPolyPkg
, ...
}@args:
callPackage (mkPolyPkg {
versions = ./versions.nix;
aliases = ./aliases.nix;
defaultSelector = (p: p.v3_3);
genericBuilder = ./generic.nix;
}) args
# post changes
{ mkPolyPkg }:
mkPolyPkg {
versions = ./versions.nix;
aliases = ./aliases.nix;
defaultSelector = (p: p.v3_3);
genericBuilder = ./generic.nix;
}