2024-11-20 20:32:38 +01:00
|
|
|
{ lib }:
|
2019-11-11 18:38:42 +01:00
|
|
|
with builtins;
|
2024-11-20 20:32:38 +01:00
|
|
|
with lib;
|
|
|
|
rec {
|
|
|
|
ifelse =
|
|
|
|
a: b: c:
|
|
|
|
if a then b else c;
|
|
|
|
fileContentsOr = a: b: (ifelse (pathIsRegularFile a) a b);
|
2020-06-01 02:24:25 +02:00
|
|
|
cwd = builtins.getEnv "PWD";
|
2020-05-10 17:16:08 +02:00
|
|
|
|
|
|
|
# lst (string PATH) (string FILETYPE) (bool RETURNFULLPATH)
|
2024-11-20 20:32:38 +01:00
|
|
|
lst =
|
|
|
|
{
|
|
|
|
p ? cwd,
|
|
|
|
t ? "regular",
|
|
|
|
b ? false,
|
|
|
|
}:
|
|
|
|
(lists.forEach (attrNames (filterAttrs (n: v: v == t) (readDir p))) (
|
|
|
|
v: ((optionalString b "${p}/") + v)
|
|
|
|
));
|
|
|
|
lsf = p: (lst { inherit p; });
|
|
|
|
lsd =
|
|
|
|
p:
|
|
|
|
(lst {
|
|
|
|
inherit p;
|
|
|
|
t = "directory";
|
|
|
|
b = true;
|
|
|
|
});
|
|
|
|
lsfRec =
|
|
|
|
p: b:
|
|
|
|
flatten (
|
|
|
|
(map (np: lsfRec np b) (lsd p))
|
2023-09-11 20:23:04 +02:00
|
|
|
++ (lst {
|
2023-09-11 21:20:14 +02:00
|
|
|
inherit p;
|
|
|
|
inherit b;
|
2024-11-20 20:32:38 +01:00
|
|
|
})
|
|
|
|
);
|
|
|
|
hasAttrs = aList: d: (map (a: (ifelse (isList a) (hasAttrByPath a d) (hasAttr a d))) aList);
|
2020-06-01 02:24:25 +02:00
|
|
|
|
|
|
|
# Not sure how list operations are implemented in Nix
|
|
|
|
# This might be a tad bit inefficient.
|
|
|
|
# TODO: look for better implementation (map is a builtin function so checking that probably won't help)
|
|
|
|
# Sequentially checks elements of list (l) for condition (cond) and executes do on first match.
|
2024-11-20 20:32:38 +01:00
|
|
|
meetsConDo =
|
|
|
|
cond: do: l:
|
|
|
|
ifelse (l == [ ]) false (
|
|
|
|
let
|
|
|
|
h = head l;
|
|
|
|
t = tail l;
|
|
|
|
in
|
|
|
|
ifelse (cond h) (do h) (meetsConDo cond do t)
|
|
|
|
);
|
|
|
|
deps =
|
|
|
|
p:
|
|
|
|
ifelse (isAttrs p) (filter isAttrs (
|
|
|
|
p.buildInputs ++ p.nativeBuildInputs ++ p.propagatedBuildInputs ++ p.propagatedNativeBuildInputs
|
|
|
|
)) [ ];
|
2023-09-11 21:20:14 +02:00
|
|
|
importFilter = l: filter (n: elem (nameFromURL (toString n) ".") l);
|
2024-11-20 20:32:38 +01:00
|
|
|
depsRec =
|
|
|
|
ld:
|
|
|
|
ifelse (ld == [ ]) [ ] (
|
|
|
|
(toList ld) ++ (depsRec (lists.unique (lists.flatten (map deps (toList ld)))))
|
|
|
|
);
|
|
|
|
isBroken =
|
|
|
|
p:
|
|
|
|
meetsConDo (s: ((hasAttrByPath s.path p) && (s.check (getAttrFromPath s.path p)))) (s: s.msg) [
|
2023-09-11 20:23:04 +02:00
|
|
|
{
|
2024-11-20 20:32:38 +01:00
|
|
|
path = [
|
|
|
|
"meta"
|
|
|
|
"broken"
|
|
|
|
];
|
2023-09-11 20:23:04 +02:00
|
|
|
msg = warn "Package ${p.name} is marked as broken." true;
|
|
|
|
check = m: m;
|
|
|
|
}
|
|
|
|
{
|
2024-11-20 20:32:38 +01:00
|
|
|
path = [
|
|
|
|
"meta"
|
|
|
|
"knownVulnerabilities"
|
|
|
|
];
|
2023-09-11 20:23:04 +02:00
|
|
|
msg = warn "Package ${p.name} has known Vulnerabilities.." true;
|
2024-11-20 20:32:38 +01:00
|
|
|
check = m: m != [ ];
|
2023-09-11 20:23:04 +02:00
|
|
|
}
|
|
|
|
{
|
2024-11-20 20:32:38 +01:00
|
|
|
path = [ "name" ];
|
2023-09-11 20:23:04 +02:00
|
|
|
msg = warn "${p.name}: python2 is depricated." false;
|
|
|
|
check = m: (strings.hasInfix "python2" m) || (strings.hasInfix "python-2" m);
|
|
|
|
}
|
|
|
|
# not sure if the following test creates false positives (AFAIK every derivation/package needs to have an outPath)
|
|
|
|
# , definitely should catch all corner cases/everything that fails to evaluate.
|
|
|
|
{
|
2024-11-20 20:32:38 +01:00
|
|
|
path = [ "outPath" ];
|
2023-09-11 20:23:04 +02:00
|
|
|
msg = warn "Package ${p.name} has no outPath" true;
|
|
|
|
check = m: !(tryEval m).success;
|
|
|
|
}
|
|
|
|
];
|
2020-05-10 17:16:08 +02:00
|
|
|
depsBroken = p: lists.any (p: (isBroken p)) (deps p);
|
2020-06-01 02:24:25 +02:00
|
|
|
# No more magic 🧙 here 😢
|
|
|
|
# But at least it now (hopefully) checks ONLY dependencies (and all of them at that).
|
2024-11-20 20:32:38 +01:00
|
|
|
depsBrokenRec =
|
|
|
|
p: (meetsConDo (p: ifelse (depsBroken p) true (depsBrokenRec (deps p))) (p: true) (deps p));
|
|
|
|
sopsHelper =
|
|
|
|
template: names: options:
|
|
|
|
let
|
|
|
|
optionsIsFunction = (typeOf options) == "lambda";
|
|
|
|
in
|
|
|
|
listToAttrs (
|
|
|
|
map (name: {
|
2023-09-11 20:23:04 +02:00
|
|
|
name = template name;
|
|
|
|
value = ifelse optionsIsFunction (options name) options;
|
2024-11-20 20:32:38 +01:00
|
|
|
}) names
|
|
|
|
);
|
|
|
|
pkgFilter =
|
|
|
|
ld:
|
|
|
|
(filter (
|
|
|
|
p:
|
|
|
|
(ifelse (isBroken p) false (
|
|
|
|
ifelse (depsBrokenRec p) (warn "Dependency of ${p.name} is marked as broken." false) true
|
|
|
|
))
|
|
|
|
) ld);
|
|
|
|
makeOptionTypeList =
|
|
|
|
path:
|
|
|
|
(lists.forEach
|
|
|
|
# get a list of all files ending in .nix in path
|
|
|
|
(filter (hasSuffix ".nix") (lsfRec path true))
|
|
|
|
# remove leading path and trailing ".nix", replace every slash with "::"
|
|
|
|
(
|
|
|
|
replaceStrings
|
|
|
|
[
|
|
|
|
"${path}/"
|
|
|
|
"/"
|
|
|
|
".nix"
|
|
|
|
]
|
|
|
|
[
|
|
|
|
""
|
|
|
|
"::"
|
|
|
|
""
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
2019-11-11 18:38:42 +01:00
|
|
|
}
|