2021-03-14 07:10:51 +00:00
|
|
|
{ lib, ... }:
|
|
|
|
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);
|
|
|
|
|
|
|
|
# Convert a list of file paths to attribute set
|
|
|
|
# that has the filenames stripped of nix extension as keys
|
|
|
|
# and imported content of the file as value.
|
|
|
|
#
|
|
|
|
pathsToImportedAttrs = paths:
|
|
|
|
let
|
|
|
|
paths' = lib.filter (lib.hasSuffix ".nix") paths;
|
|
|
|
in
|
|
|
|
genAttrs' paths' (path: {
|
2021-03-26 03:42:47 +00:00
|
|
|
name = lib.removeSuffix ".nix"
|
|
|
|
# Safe as long this is just used as a name
|
|
|
|
(builtins.unsafeDiscardStringContext (baseNameOf path));
|
2021-03-14 07:10:51 +00:00
|
|
|
value = import path;
|
|
|
|
});
|
|
|
|
|
|
|
|
concatAttrs = lib.fold (attr: sum: lib.recursiveUpdate sum attr) { };
|
|
|
|
}
|