Created
December 30, 2019 16:31
-
-
Save zimbatm/a639ece627d6bc86cb0675c16eec4cf7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs }@orig: | |
{ pkgs ? orig.pkgs, rootDir }: | |
with builtins; | |
let | |
mapAttrsMerge = pred: set: | |
let | |
mapF = name: | |
let | |
v = pred name set.${name}; | |
in | |
if v == null then [] | |
else [ { name = name; value = v; } ]; | |
in | |
listToAttrs (concatMap mapF (attrNames set)); | |
importers = { | |
"bake.nix" = (file: callPackage file {}); | |
}; | |
traverse = dir: | |
let | |
contents = builtins.readDir dir; | |
# TODO: ignore based on the top-level | |
eachEntry = name: type: | |
if name == ".git" || name == "build" then | |
null # ignore | |
else if type == "directory" then | |
traverse "${dir}/${name}" | |
else null # ignore | |
; | |
eachImporter = name: fn: | |
if contents ? "${name}" then | |
fn "${dir}/${name}" | |
else | |
{}; | |
entries = mapAttrsMerge eachEntry contents; | |
imported = mapAttrs eachImporter importers; | |
merged = | |
foldl' | |
(a: b: a // b) | |
{} | |
([ entries ] ++ (attrValues imported)); | |
in | |
merged; | |
callPackage = pkgs.newScope ( | |
pkgs // { | |
root = root; | |
#callPackage = callPackage; | |
} | |
); | |
collectAll = val: | |
if pkgs.lib.isDerivation val then [ val ] | |
else if isAttrs val then | |
concatMap collectAll (attrValues val) | |
else [] | |
; | |
root = traverse rootDir; | |
in | |
root // { | |
# contains all derivations of the tree | |
all = collectAll root; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment