maintainers/lib.nix

81 lines
2.1 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
2024-07-29 03:09:17 +00:00
head
2024-07-08 19:41:15 +00:00
length
map
2024-07-29 03:09:17 +00:00
match
tail
2024-07-08 19:41:15 +00:00
;
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
;
2024-07-29 03:36:42 +00:00
inherit (import ./closure.nix { inherit pkgs; }) drvClosure;
2024-07-08 19:41:15 +00:00
in
rec {
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-29 03:09:17 +00:00
# Construct a link to a derivation's source in github:NixOS/nixpkgs
2024-07-29 03:42:05 +00:00
drvSource =
drv:
let
parts = match "/nix/store/[^/]+/(.*):([0-9]*)" drv.meta.position;
in
if hasAttr "meta" drv && hasAttr "position" drv.meta then
"https://github.com/NixOS/nixpkgs/blob/master/${head parts}#L${head (tail parts)}"
else
"";
2024-07-29 03:09:17 +00:00
mainInfo = drv: {
name = drv.name;
maintainers = map (main: toString main.github) (drvMaintainers drv);
source = drvSource drv;
};
2024-07-08 19:37:49 +00:00
stringJoin = objToString: objs: writeText "txt" (concatLines (map objToString objs));
2024-07-29 03:09:17 +00:00
closureInfo = drv: map mainInfo (filter maintainable (drvClosure drv));
2024-07-08 19:41:15 +00:00
allMaintainers =
drv:
let
2024-07-29 03:09:17 +00:00
info = closureInfo drv;
infoToString = info: "${info.name} ${concatStringsSep "," info.maintainers}";
2024-07-08 19:41:15 +00:00
in
2024-07-29 03:09:17 +00:00
runCommandLocal "all-maintainers.txt" { } ''
<${stringJoin infoToString info} sort -u | ${pkgs.unixtools.column}/bin/column -t > $out
2024-07-08 19:41:15 +00:00
'';
2024-07-08 19:37:49 +00:00
2024-07-08 19:41:15 +00:00
noMaintainers =
drv:
let
2024-07-29 03:09:17 +00:00
info = closureInfo drv;
unmaintained = filter (info: (length info.maintainers) == 0) info;
infoToString = info: "${info.name} ${info.source}";
2024-07-08 19:41:15 +00:00
in
2024-07-29 03:09:17 +00:00
runCommandLocal "unmaintained.txt" { } ''
<${stringJoin infoToString unmaintained} sort -u | ${pkgs.unixtools.column}/bin/column -t > $out
2024-07-08 19:41:15 +00:00
'';
2024-07-11 13:40:31 +00:00
2024-07-29 03:09:17 +00:00
expandInput =
input:
if (input.class or null == "nixos") && (input._type or null == "configuration") then
[
input.config.system.build.toplevel
input.config.environment.systemPackages
]
else
input;
2024-07-08 19:37:49 +00:00
}