Format with nixfmt-rfc-style

This commit is contained in:
Tim Van Baak 2024-07-08 12:41:15 -07:00
parent 6efb6110a6
commit 82b543859f
2 changed files with 93 additions and 51 deletions

View File

@ -1,48 +1,85 @@
{ pkgs ? import <nixpkgs> {}, ... }: let {
inherit (builtins) genericClosure hasAttr length map; pkgs ? import <nixpkgs> { },
...
}:
let
inherit (builtins)
genericClosure
hasAttr
length
map
;
inherit (pkgs) runCommandLocal writeText; inherit (pkgs) runCommandLocal writeText;
inherit (pkgs.lib) concatLines concatLists concatMap filter isDerivation isList mapAttrsToList; inherit (pkgs.lib)
in rec { concatLines
concatLists
concatMap
filter
isDerivation
isList
mapAttrsToList
;
in
rec {
drvOutputs = drv: if hasAttr "outputs" drv then map (out: drv.${out}) drv.outputs else [ drv ]; drvOutputs = drv: if hasAttr "outputs" drv then map (out: drv.${out}) drv.outputs else [ drv ];
drvDeps = drv: drvDeps =
mapAttrsToList (k: v: drv:
if isDerivation v then (drvOutputs v) mapAttrsToList (
else if isList v then concatMap drvOutputs (filter isDerivation v) k: v:
else [] if isDerivation v then
(drvOutputs v)
else if isList v then
concatMap drvOutputs (filter isDerivation v)
else
[ ]
) drv; ) drv;
drvClosure = let drvClosure =
wrap = drv: { key = drv.outPath; inherit drv; }; let
in drv: map (obj: obj.drv) (genericClosure { wrap = drv: {
startSet = map wrap (drvOutputs drv); key = drv.outPath;
operator = obj: map wrap (concatLists (drvDeps obj.drv.drvAttrs)); inherit drv;
}); };
drvMaintainers = drv: in
if ! hasAttr "meta" drv then [] drv:
else if ! hasAttr "maintainers" drv.meta then [] map (obj: obj.drv) (genericClosure {
else drv.meta.maintainers; startSet = map wrap (drvOutputs drv);
nobodyMaintains = drv: operator = obj: map wrap (concatLists (drvDeps obj.drv.drvAttrs));
hasAttr "meta" drv && });
hasAttr "maintainers" drv.meta && drvMaintainers =
(length drv.meta.maintainers) == 0; 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)); stringJoin = objToString: objs: writeText "txt" (concatLines (map objToString objs));
allMaintainers = drv: let allMaintainers =
closure = drvClosure drv; drv:
maintainers = concatMap drvMaintainers closure; let
mainToString = m: "${m.name} (${m.email})"; closure = drvClosure drv;
in runCommandLocal "uniq-maintainers.txt" {} '' maintainers = concatMap drvMaintainers closure;
<${stringJoin mainToString maintainers} sort | uniq -c > $out mainToString = m: "${m.name} (${m.email})";
''; in
runCommandLocal "uniq-maintainers.txt" { } ''
<${stringJoin mainToString maintainers} sort | uniq -c > $out
'';
noMaintainers = drv: let noMaintainers =
closure = drvClosure drv; drv:
unmaintained = filter nobodyMaintains closure; let
drvToString = drv: "${drv.name} ${drv.meta.position}"; closure = drvClosure drv;
in runCommandLocal "no-maintainers.txt" {} '' unmaintained = filter nobodyMaintains closure;
<${stringJoin drvToString unmaintained} sort -u \ drvToString = drv: "${drv.name} ${drv.meta.position}";
| sed 's/\/nix\/store\/[^/]*/https:\/\/github.com\/NixOS\/nixpkgs\/blob\/master/' \ in
| sed 's/.nix:\(.*\)$/#L\1/' \ runCommandLocal "no-maintainers.txt" { } ''
| ${pkgs.unixtools.column}/bin/column -t \ <${stringJoin drvToString unmaintained} sort -u \
> $out | sed 's/\/nix\/store\/[^/]*/https:\/\/github.com\/NixOS\/nixpkgs\/blob\/master/' \
''; | sed 's/.nix:\(.*\)$/#L\1/' \
| ${pkgs.unixtools.column}/bin/column -t \
> $out
'';
} }

View File

@ -1,13 +1,18 @@
{ {
outputs = { self, nixpkgs, ... }: let outputs =
system = "x86_64-linux"; { self, nixpkgs, ... }:
pkgs = nixpkgs.legacyPackages.${system}; let
lib = import ./default.nix { inherit pkgs; }; system = "x86_64-linux";
in { pkgs = nixpkgs.legacyPackages.${system};
bundlers."x86_64-linux" = rec { lib = import ./default.nix { inherit pkgs; };
default = adopt; in
maintainers = lib.allMaintainers; {
adopt = lib.noMaintainers; bundlers."x86_64-linux" = rec {
default = adopt;
maintainers = lib.allMaintainers;
adopt = lib.noMaintainers;
};
formatter."x86_64-linux" = pkgs.nixfmt-rfc-style;
}; };
};
} }