Move logic to default.nix
This commit is contained in:
parent
185a541c59
commit
6efb6110a6
|
@ -0,0 +1,48 @@
|
||||||
|
{ pkgs ? import <nixpkgs> {}, ... }: let
|
||||||
|
inherit (builtins) genericClosure hasAttr length map;
|
||||||
|
inherit (pkgs) runCommandLocal writeText;
|
||||||
|
inherit (pkgs.lib) concatLines concatLists concatMap filter isDerivation isList mapAttrsToList;
|
||||||
|
in rec {
|
||||||
|
drvOutputs = drv: if hasAttr "outputs" drv then map (out: drv.${out}) drv.outputs else [ drv ];
|
||||||
|
drvDeps = drv:
|
||||||
|
mapAttrsToList (k: v:
|
||||||
|
if isDerivation v then (drvOutputs v)
|
||||||
|
else if isList v then concatMap drvOutputs (filter isDerivation v)
|
||||||
|
else []
|
||||||
|
) drv;
|
||||||
|
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));
|
||||||
|
});
|
||||||
|
drvMaintainers = drv:
|
||||||
|
if ! hasAttr "meta" drv then []
|
||||||
|
else if ! hasAttr "maintainers" drv.meta then []
|
||||||
|
else drv.meta.maintainers;
|
||||||
|
nobodyMaintains = drv:
|
||||||
|
hasAttr "meta" drv &&
|
||||||
|
hasAttr "maintainers" drv.meta &&
|
||||||
|
(length drv.meta.maintainers) == 0;
|
||||||
|
stringJoin = objToString: objs: writeText "txt" (concatLines (map objToString objs));
|
||||||
|
|
||||||
|
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
|
||||||
|
'';
|
||||||
|
|
||||||
|
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/' \
|
||||||
|
| sed 's/.nix:\(.*\)$/#L\1/' \
|
||||||
|
| ${pkgs.unixtools.column}/bin/column -t \
|
||||||
|
> $out
|
||||||
|
'';
|
||||||
|
}
|
56
flake.nix
56
flake.nix
|
@ -2,60 +2,12 @@
|
||||||
outputs = { self, nixpkgs, ... }: let
|
outputs = { self, nixpkgs, ... }: let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
inherit (builtins) genericClosure hasAttr length map;
|
lib = import ./default.nix { inherit pkgs; };
|
||||||
inherit (pkgs) runCommandLocal writeText;
|
|
||||||
inherit (pkgs.lib) concatLines concatLists concatMap filter isDerivation isList mapAttrsToList;
|
|
||||||
in {
|
in {
|
||||||
lib = rec {
|
bundlers."x86_64-linux" = 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 {
|
|
||||||
startSet = map wrap (drvOutputs drv0);
|
|
||||||
operator = obj: map wrap (concatLists (drvDeps obj.drv.drvAttrs));
|
|
||||||
});
|
|
||||||
drvMaintainers = drv:
|
|
||||||
if ! hasAttr "meta" drv then []
|
|
||||||
else if ! hasAttr "maintainers" drv.meta then []
|
|
||||||
else drv.meta.maintainers;
|
|
||||||
nobodyMaintains = drv:
|
|
||||||
hasAttr "meta" drv &&
|
|
||||||
hasAttr "maintainers" drv.meta &&
|
|
||||||
(length drv.meta.maintainers) == 0;
|
|
||||||
stringJoin = objToString: objs: writeText "txt" (concatLines (map objToString objs));
|
|
||||||
maintainerToString = m: "${m.name} (${m.email})";
|
|
||||||
drvToString = drv: "${drv.name}";
|
|
||||||
};
|
|
||||||
bundlers."x86_64-linux" = with self.lib; rec {
|
|
||||||
default = adopt;
|
default = adopt;
|
||||||
maintainers = drv: let
|
maintainers = lib.allMaintainers;
|
||||||
drvs = buildtimeDerivations drv;
|
adopt = lib.noMaintainers;
|
||||||
maintainers = concatMap drvMaintainers drvs;
|
|
||||||
maintainerNamesList = stringJoin (m: "${m.name} (${m.email})") maintainers;
|
|
||||||
uniqNames = runCommandLocal "uniq-maintainers.txt" {} ''
|
|
||||||
<${maintainerNamesList} sort | uniq -c > $out
|
|
||||||
'';
|
|
||||||
in uniqNames;
|
|
||||||
adopt = drv: let
|
|
||||||
drvs = buildtimeDerivations drv;
|
|
||||||
drvsNoMain = filter nobodyMaintains drvs;
|
|
||||||
drvNamesList = stringJoin (drv: "${drv.name} ${drv.meta.position}") drvsNoMain;
|
|
||||||
uniqNames = runCommandLocal "no-maintainers.txt" {} ''
|
|
||||||
<${drvNamesList} sort -u \
|
|
||||||
| sed 's/\/nix\/store\/[^/]*/https:\/\/github.com\/NixOS\/nixpkgs\/blob\/master/' \
|
|
||||||
| sed 's/.nix:\(.*\)$/#L\1/' \
|
|
||||||
| ${pkgs.unixtools.column}/bin/column -t \
|
|
||||||
> $out
|
|
||||||
'';
|
|
||||||
in uniqNames;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue