Add a couple of extra checks to exportOverlays function

This commit is contained in:
Gytis Ivaskevicius 2021-11-06 15:29:27 +02:00
parent 4d9d171acc
commit 9d743bef39
4 changed files with 41 additions and 8 deletions

View File

@ -44,27 +44,43 @@ let
attrNames
attrValues
concatMap
concatStringsSep
elem
filter
foldl'
head
isAttrs
isFunction
listToAttrs
mapAttrs
tryEval
;
# Hopefully will fix a couple of edge cases. Even tho `lib` is defined as API here - it is not. Do not use it.
fakePkgs = {
lib = flake-utils-plus.lib.internal;
callPackage = it: it;
isFakePkgs = true; # Overlay maintainers may throw an exception in case this key is set in case overlay is not compatible with this function.
};
nameValuePair = name: value: { inherit name value; };
# just pull out one arch from the system-spaced pkgs to get access to channels
# overlays can be safely evaluated on any arch
channels = head (attrValues pkgs);
pathStr = path: builtins.concatStringsSep "/" path;
pathStr = path: concatStringsSep "/" path;
channelNames = attrNames channels;
overlayNames = overlay: attrNames (overlay null null);
overlayNames = overlay:
if isOverlay overlay
then attrNames (overlay fakePkgs fakePkgs)
else [ ];
isOverlay = it: isFunction it && isFunction (it fakePkgs) && (tryEval (isAttrs (it fakePkgs fakePkgs))).success;
# get all overlays from inputs
inputOverlays = mapAttrs
(_: v: [ v.overlay or (_: _: { }) ] ++ attrValues v.overlays or { })
(_: v: (if isOverlay (v.overlay or null) then [ v.overlay ] else [ ]) ++ (filter isOverlay (attrValues (v.overlays or { }))))
(removeAttrs inputs [ "self" ]);
# use overlayNames as a way to identify overlays
flattenedInputOverlays = map overlayNames (foldl' (a: b: a ++ b) [ ] (attrValues inputOverlays));
@ -96,7 +112,7 @@ let
)
(filterOverlays channels.${channelName})
)
channelNames
(attrNames channels)
);
in

View File

@ -12,6 +12,8 @@ rec {
*/
genAttrs' = func: values: builtins.listToAttrs (map func values);
getAttrs = names: attrs: genAttrs names (name: attrs.${name});
hasFileAttr = o: builtins.hasAttr "_file" o;
# Definition in nixpkgs

View File

@ -0,0 +1,18 @@
{
inputs.utils.url = "/home/gytis/Projects/flake-utils-plus";
inputs.neovitality.url = github:vi-tality/neovitality/69aaf582bf46992ae10e6aaa44f37c9d4096cc38; # As of writing contains invalid `overlays` attribute.
inputs.nixpkgs.url = github:NixOS/nixpkgs;
outputs = inputs@{ self, neovitality, utils, ... }:
utils.lib.mkFlake {
inherit self inputs;
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" ];
overlays = utils.lib.exportOverlays { inherit (self) pkgs inputs; };
};
}

View File

@ -90,6 +90,3 @@
};
}