maintainers/default.nix

93 lines
2.5 KiB
Nix
Raw Normal View History

2024-07-11 13:40:31 +00:00
{ pkgs, ... }:
2024-07-08 19:41:15 +00:00
let
inherit (builtins)
genericClosure
hasAttr
length
map
;
2024-07-08 19:37:49 +00:00
inherit (pkgs) runCommandLocal writeText;
2024-07-08 19:41:15 +00:00
inherit (pkgs.lib)
concatLines
concatLists
concatMap
2024-07-11 13:40:31 +00:00
concatStringsSep
2024-07-08 19:41:15 +00:00
filter
isDerivation
isList
mapAttrsToList
;
in
rec {
2024-07-08 19:37:49 +00:00
drvOutputs = drv: if hasAttr "outputs" drv then map (out: drv.${out}) drv.outputs else [ drv ];
2024-07-08 19:41:15 +00:00
drvDeps =
drv:
mapAttrsToList (
k: v:
if isDerivation v then
(drvOutputs v)
else if isList v then
concatMap drvOutputs (filter isDerivation v)
else
[ ]
2024-07-08 19:37:49 +00:00
) drv;
2024-07-08 19:41:15 +00:00
drvClosure =
let
wrap = drv: {
key = drv.outPath;
inherit drv;
};
in
drv:
map (obj: obj.drv) (genericClosure {
startSet = map wrap (drvOutputs drv);
operator = obj: map wrap (concatLists (drvDeps obj.drv.drvAttrs));
});
2024-07-11 13:40:31 +00:00
maintainable = drv: hasAttr "meta" drv && hasAttr "maintainers" drv.meta;
drvMaintainers = drv: if maintainable drv then drv.meta.maintainers else [ ];
2024-07-08 19:41:15 +00:00
nobodyMaintains =
drv: hasAttr "meta" drv && hasAttr "maintainers" drv.meta && (length drv.meta.maintainers) == 0;
2024-07-08 19:37:49 +00:00
stringJoin = objToString: objs: writeText "txt" (concatLines (map objToString objs));
2024-07-08 19:41:15 +00:00
allMaintainers =
drv:
let
closure = drvClosure drv;
maintainers = concatMap drvMaintainers closure;
mainToString = m: "${m.name} (${m.email})";
in
runCommandLocal "uniq-maintainers.txt" { } ''
<${stringJoin mainToString maintainers} sort | uniq -c > $out
'';
2024-07-08 19:37:49 +00:00
2024-07-08 19:41:15 +00:00
noMaintainers =
drv:
let
closure = drvClosure drv;
unmaintained = filter nobodyMaintains closure;
drvToString = drv: "${drv.name} ${drv.meta.position}";
in
runCommandLocal "no-maintainers.txt" { } ''
<${stringJoin drvToString unmaintained} sort -u \
| sed 's/\/nix\/store\/[^/]*/https:\/\/github.com\/NixOS\/nixpkgs\/blob\/master/' \
2024-07-08 22:59:05 +00:00
| sed 's/.nix:\(.*\)$/.nix#L\1/' \
2024-07-08 19:41:15 +00:00
| ${pkgs.unixtools.column}/bin/column -t \
> $out
'';
2024-07-11 13:40:31 +00:00
listMaintainers =
drv:
let
closure = drvClosure drv;
maintainableDrvs = filter maintainable closure;
maintainersToString =
maintainers: concatStringsSep "," (map (main: toString main.github) maintainers);
drvToString = drv: "${drv.name} ${maintainersToString (drvMaintainers drv)}";
in
runCommandLocal "maintainers.txt" { } ''
<${stringJoin drvToString maintainableDrvs} sort -u \
| ${pkgs.unixtools.column}/bin/column -t \
> $out
'';
2024-07-08 19:37:49 +00:00
}