1
1
forked from extern/flakelight

Fix packages depending on pkg with same name

If a package depends on a package with same name, this causes an
infinite recursion as it tries to depend on itself. This is not likely
what was intended, and breaks ability to re-export packages, so instead
if a package depends on the same name, that now refers to the previous
version.
This commit is contained in:
Archit Gupta 2024-01-16 10:48:48 -08:00
parent 26a8a4454a
commit e143290511
2 changed files with 30 additions and 9 deletions

View File

@ -4,15 +4,27 @@
{ config, lib, inputs, flakelight, genSystems, moduleArgs, ... }:
let
inherit (builtins) parseDrvName tryEval;
inherit (lib) filterAttrs findFirst mapAttrs mapAttrs' mkIf mkMerge mkOption
nameValuePair optionalAttrs;
inherit (builtins) hasAttr parseDrvName tryEval;
inherit (lib) filterAttrs findFirst functionArgs mapAttrs' mapAttrs mkIf
mkMerge mkOption nameValuePair optionalAttrs;
inherit (lib.types) lazyAttrsOf nullOr str uniq;
inherit (flakelight) supportedSystem;
inherit (flakelight.types) optCallWith overlay packageDef;
genPkg = pkgs: pkg: pkgs.callPackage pkg { };
genPkgs = pkgs: mapAttrs (_: genPkg pkgs) config.packages;
genPkg = final: prev: name: pkg:
let
dependsOnSelf = hasAttr name (functionArgs pkg);
dependsOnPkgs = (functionArgs pkg) ? pkgs;
selfOverride = {
${name} = prev.${name} or
(throw "${name} depends on ${name}, but no existing ${name}.");
};
overrides = optionalAttrs dependsOnSelf selfOverride
// optionalAttrs dependsOnPkgs { pkgs = final.pkgs // selfOverride; };
in
final.callPackage pkg overrides;
genPkgs = final: prev: pkgs:
mapAttrs (name: genPkg final prev name) pkgs;
in
{
options = {
@ -61,13 +73,16 @@ in
(getName (import inputs.nixpkgs {
inherit (prev.stdenv.hostPlatform) system;
inherit (config.nixpkgs) config;
overlays = config.withOverlays ++ [ (final: _: genPkgs final) ];
overlays = config.withOverlays ++
[ (final: prev: genPkgs final prev config.packages) ];
}).default)
];
in
(optionalAttrs (config.packages ? default) {
${defaultPkgName} = genPkg final config.packages.default;
}) // genPkgs final;
(optionalAttrs (config.packages ? default) rec {
default = genPkg final prev defaultPkgName
config.packages.default;
${defaultPkgName} = default;
}) // genPkgs final prev (removeAttrs config.packages [ "default" ]);
overlay = final: prev: removeAttrs
(config.packageOverlay (final.appendOverlays config.withOverlays) prev)

View File

@ -170,6 +170,12 @@ in
})
(f: import f.packages.x86_64-linux.default);
package-prevent-recursion = test
(flakelight ./empty {
package = { hello }: hello;
})
(f: f.packages.aarch64-linux.default.pname == "hello");
package = test
(flakelight ./empty {
package = { stdenv }: