maintainers/flake.nix

58 lines
2.2 KiB
Nix
Raw Normal View History

2024-07-08 06:00:24 +00:00
{
outputs = { self, nixpkgs, ... }: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
inherit (builtins) genericClosure hasAttr length map;
inherit (pkgs) runCommandLocal writeText;
inherit (pkgs.lib) concatLines concatLists concatMap filter isDerivation isList mapAttrsToList;
in {
lib = rec {
drvOutputs = drv:
if hasAttr "outputs" drv
then map (output: drv.${output}) drv.outputs
else [ drv ];
drvDeps = attrs:
mapAttrsToList (k: v:
if isDerivation v then (drvOutputs v)
else if isList v then concatMap drvOutputs (filter isDerivation v)
else []
) attrs;
wrap = drv: { key = drv.outPath; inherit drv; };
buildtimeDerivations = drv0: map (obj: obj.drv) (genericClosure {
2024-07-08 06:00:24 +00:00
startSet = map wrap (drvOutputs drv0);
operator = obj: map wrap (concatLists (drvDeps obj.drv.drvAttrs));
});
2024-07-08 06:00:24 +00:00
drvMaintainers = drv:
if ! hasAttr "meta" drv then []
else if ! hasAttr "maintainers" drv.meta then []
else drv.meta.maintainers;
nobodyMaintains = drv:
2024-07-08 16:39:03 +00:00
hasAttr "meta" drv &&
hasAttr "maintainers" drv.meta &&
(length drv.meta.maintainers) == 0;
stringJoin = objToString: objs: writeText "txt" (concatLines (map objToString objs));
2024-07-08 06:00:24 +00:00
maintainerToString = m: "${m.name} (${m.email})";
drvToString = drv: "${drv.name}";
};
2024-07-08 06:03:23 +00:00
bundlers."x86_64-linux" = with self.lib; rec {
default = adopt;
2024-07-08 06:00:24 +00:00
maintainers = drv: let
drvs = buildtimeDerivations drv;
2024-07-08 06:00:24 +00:00
maintainers = concatMap drvMaintainers drvs;
maintainerNamesList = stringJoin (m: "${m.name} (${m.email})") maintainers;
2024-07-08 06:00:24 +00:00
uniqNames = runCommandLocal "uniq-maintainers.txt" {} ''
<${maintainerNamesList} sort | uniq -c > $out
'';
in uniqNames;
adopt = drv: let
drvs = buildtimeDerivations drv;
2024-07-08 06:00:24 +00:00
drvsNoMain = filter nobodyMaintains drvs;
drvNamesList = stringJoin (drv: "${drv.name} ${drv.meta.position}") drvsNoMain;
2024-07-08 06:00:24 +00:00
uniqNames = runCommandLocal "no-maintainers.txt" {} ''
2024-07-08 16:39:03 +00:00
<${drvNamesList} sort -u > $out
2024-07-08 06:00:24 +00:00
'';
in uniqNames;
};
};
}