2021-04-18 04:29:45 +02:00
|
|
|
{ lib }:
|
2021-03-14 08:10:51 +01:00
|
|
|
rec {
|
|
|
|
# mapFilterAttrs ::
|
|
|
|
# (name -> value -> bool )
|
|
|
|
# (name -> value -> { name = any; value = any; })
|
|
|
|
# attrs
|
|
|
|
mapFilterAttrs = seive: f: attrs:
|
|
|
|
lib.filterAttrs
|
|
|
|
seive
|
|
|
|
(lib.mapAttrs' f attrs);
|
|
|
|
|
|
|
|
# Generate an attribute set by mapping a function over a list of values.
|
|
|
|
genAttrs' = values: f: lib.listToAttrs (map f values);
|
|
|
|
|
2021-03-28 08:18:27 +02:00
|
|
|
# Convert a list of file paths to attribute set where
|
|
|
|
# the key is the folder or filename stripped of nix
|
|
|
|
# extension and imported content of the file as value.
|
2021-03-14 08:10:51 +01:00
|
|
|
#
|
|
|
|
pathsToImportedAttrs = paths:
|
|
|
|
let
|
2021-03-28 08:18:27 +02:00
|
|
|
paths' = lib.filter
|
|
|
|
(path: lib.hasSuffix ".nix" path
|
|
|
|
|| lib.pathExists "${path}/default.nix")
|
|
|
|
paths;
|
2021-03-14 08:10:51 +01:00
|
|
|
in
|
|
|
|
genAttrs' paths' (path: {
|
2021-03-26 04:42:47 +01:00
|
|
|
name = lib.removeSuffix ".nix"
|
|
|
|
# Safe as long this is just used as a name
|
|
|
|
(builtins.unsafeDiscardStringContext (baseNameOf path));
|
2021-03-14 08:10:51 +01:00
|
|
|
value = import path;
|
|
|
|
});
|
|
|
|
|
2021-04-27 19:26:45 +02:00
|
|
|
importHosts = dir:
|
|
|
|
lib.os.recImport {
|
|
|
|
inherit dir;
|
|
|
|
_import = base: {
|
|
|
|
modules = import "${toString dir}/${base}.nix";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-03-14 08:10:51 +01:00
|
|
|
concatAttrs = lib.fold (attr: sum: lib.recursiveUpdate sum attr) { };
|
2021-03-26 22:41:10 +01:00
|
|
|
|
|
|
|
# Filter out packages that support given system and follow flake check requirements
|
|
|
|
filterPackages = system: packages:
|
|
|
|
let
|
|
|
|
# Everything that nix flake check requires for the packages output
|
|
|
|
filter = (n: v: with v; let platforms = meta.hydraPlatforms or meta.platforms or [ ]; in
|
2021-04-10 03:22:08 +02:00
|
|
|
lib.isDerivation v && !meta.broken && builtins.elem system platforms);
|
2021-03-26 22:41:10 +01:00
|
|
|
in
|
2021-04-10 03:22:08 +02:00
|
|
|
lib.filterAttrs filter packages;
|
2021-03-30 21:47:54 +02:00
|
|
|
|
2021-04-27 18:30:28 +02:00
|
|
|
safeReadDir = path:
|
|
|
|
lib.optionalAttrs (builtins.pathExists (toString path)) (builtins.readDir (toString path));
|
2021-03-14 08:10:51 +01:00
|
|
|
}
|