Fix import and make pkgFilter recurse into dependencies.
This commit is contained in:
parent
1476ff6acb
commit
af66caf14a
2 changed files with 32 additions and 15 deletions
|
@ -4,19 +4,20 @@ with builtins;
|
||||||
with lib;
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
fn = import ./fn.nix { inherit lib; };
|
fn = import (toString ./fn.nix) { inherit lib; };
|
||||||
# Cannot use <hostName> here as those evaluations only work with existing paths >.<
|
# Cannot use <hostName> here as those evaluations only work with existing paths >.<
|
||||||
# hostName and secretPtah can be set with -I hostName=$HOSTNAME and -I secretPath=$SECRETPATH respectively
|
# hostName and secretPtah can be set with -I hostName=$HOSTNAME and -I secretPath=$SECRETPATH respectively
|
||||||
# , defaults to the contents of /secret/hostName
|
# , defaults to the contents of /secret/hostName
|
||||||
secretPath = fn.ifelse ((tryEval <secretPath>).value != false)
|
secretPath = fn.ifelse ((tryEval (toString <secretPath>)).value != false)
|
||||||
<secretPath>
|
(toString <secretPath>)
|
||||||
/secret;
|
(toString /secret);
|
||||||
hostName = (findFirst
|
hostName = (
|
||||||
(elem: elem.prefix == "hostName")
|
findFirst
|
||||||
{ path = (fileContents "${secretPath}/hostName"); }
|
(elem: elem.prefix == "hostName")
|
||||||
nixPath
|
{ path = (fileContents "${secretPath}/hostName"); }
|
||||||
|
nixPath
|
||||||
).path;
|
).path;
|
||||||
machinePath = (builtins.toPath ( ./machines + ("/" + hostName)));
|
machinePath = (builtins.toPath (./machines + ("/" + hostName)));
|
||||||
machineFiles = fn.lst { p = machinePath; b = true; };
|
machineFiles = fn.lst { p = machinePath; b = true; };
|
||||||
configFiles = fn.lst { p = (toString ./config); b = true; };
|
configFiles = fn.lst { p = (toString ./config); b = true; };
|
||||||
pkgsFiles = fn.lst { p = (toString ./pkgs); b = true; };
|
pkgsFiles = fn.lst { p = (toString ./pkgs); b = true; };
|
||||||
|
|
28
fn.nix
28
fn.nix
|
@ -9,6 +9,8 @@ rec {
|
||||||
(pathIsRegularFile a)
|
(pathIsRegularFile a)
|
||||||
a b);
|
a b);
|
||||||
cwd = toString ./.;
|
cwd = toString ./.;
|
||||||
|
|
||||||
|
# lst (string PATH) (string FILETYPE) (bool RETURNFULLPATH)
|
||||||
lst = { p ? cwd, t ? "regular", b ? false }: (lists.forEach
|
lst = { p ? cwd, t ? "regular", b ? false }: (lists.forEach
|
||||||
(attrNames
|
(attrNames
|
||||||
(filterAttrs (n: v: v == t)
|
(filterAttrs (n: v: v == t)
|
||||||
|
@ -23,11 +25,25 @@ rec {
|
||||||
(hasAttrByPath a d)
|
(hasAttrByPath a d)
|
||||||
(hasAttr a d)))
|
(hasAttr a d)))
|
||||||
aList);
|
aList);
|
||||||
pkgFilter = l: (filter
|
deps = p: ifelse (isAttrs p) (filter (p: isAttrs p)
|
||||||
|
(p.buildInputs ++ p.nativeBuildInputs ++ p.propagatedBuildInputs ++ p.propagatedNativeBuildInputs)
|
||||||
|
) [];
|
||||||
|
importFilter = l: p: filter (n: elem (nameFromURL (toString n) ".") l) p;
|
||||||
|
depsRec = ld: ifelse (ld == []) [] ((toList ld) ++ (depsRec (lists.unique (lists.flatten (map (d: deps d) (toList ld))))));
|
||||||
|
isBroken = p: ifelse ((elem true (hasAttrs [["meta" "broken"]] p)) && (p.meta.broken == true))
|
||||||
|
(warn "Package ${p.name} is marked as broken." true)
|
||||||
|
false;
|
||||||
|
depsBroken = p: lists.any (p: (isBroken p)) (deps p);
|
||||||
|
# Those two lines are quite magical 🧙
|
||||||
|
depsBrokenRec = p: (b: b == true) (ifelse (depsBroken p) true
|
||||||
|
(map (p: depsBrokenRec p) (deps p)));
|
||||||
|
pkgFilter = ld: (filter
|
||||||
(p: (
|
(p: (
|
||||||
ifelse (elem true (hasAttrs [["meta" "broken"]] p))
|
ifelse (isBroken p)
|
||||||
(warn "Package ${p.name} is marked as broken." false)
|
false
|
||||||
true)
|
(ifelse (depsBrokenRec p)
|
||||||
)
|
(warn "Dependency of ${p.name} is marked as broken." false)
|
||||||
l);
|
true)
|
||||||
|
))
|
||||||
|
ld);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue