2021-04-18 04:35:05 +03:00
|
|
|
{ lib, ... }:
|
2021-03-14 10:10:51 +03:00
|
|
|
|
|
|
|
let mkProfileAttrs =
|
|
|
|
/**
|
|
|
|
Synopsis: mkProfileAttrs _path_
|
|
|
|
|
|
|
|
Recursively collect the subdirs of _path_ containing a default.nix into attrs.
|
|
|
|
This sets a contract, eliminating ambiguity for _default.nix_ living under the
|
|
|
|
profile directory.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
let profiles = mkProfileAttrs ./profiles; in
|
|
|
|
assert profiles ? core.default; 0
|
|
|
|
**/
|
|
|
|
dir:
|
|
|
|
let
|
|
|
|
imports =
|
|
|
|
let
|
2021-04-18 04:35:05 +03:00
|
|
|
files = lib.safeReadDir dir;
|
2021-03-14 10:10:51 +03:00
|
|
|
|
|
|
|
p = n: v:
|
|
|
|
v == "directory"
|
|
|
|
&& n != "profiles";
|
|
|
|
in
|
|
|
|
lib.filterAttrs p files;
|
|
|
|
|
|
|
|
f = n: _:
|
|
|
|
lib.optionalAttrs
|
|
|
|
(lib.pathExists "${dir}/${n}/default.nix")
|
2021-03-23 22:05:30 +03:00
|
|
|
{ default = "${dir}/${n}"; }
|
2021-03-14 10:10:51 +03:00
|
|
|
// mkProfileAttrs "${dir}/${n}";
|
|
|
|
in
|
|
|
|
lib.mapAttrs f imports;
|
|
|
|
in mkProfileAttrs
|
|
|
|
|