mirror of
https://github.com/nix-community/flakelight.git
synced 2024-09-11 08:55:39 +03:00
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:
parent
26a8a4454a
commit
e143290511
@ -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)
|
||||
|
@ -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 }:
|
||||
|
Loading…
Reference in New Issue
Block a user