2021-03-14 08:10:51 +01: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);
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
safeReadDir = path: lib.optionalAttrs (builtins.pathExists path) (builtins.readDir path);
|
2021-03-14 08:10:51 +01:00
|
|
|
}
|