mix imports can be attrs or fns
This commit is contained in:
parent
bbea746e8d
commit
3fe748f174
1 changed files with 39 additions and 11 deletions
|
|
@ -2,10 +2,17 @@
|
||||||
inherit
|
inherit
|
||||||
(builtins)
|
(builtins)
|
||||||
attrNames
|
attrNames
|
||||||
attrValues
|
|
||||||
hasAttr
|
hasAttr
|
||||||
|
isAttrs
|
||||||
|
isFunction
|
||||||
listToAttrs
|
listToAttrs
|
||||||
removeAttrs
|
removeAttrs
|
||||||
|
typeOf
|
||||||
|
;
|
||||||
|
|
||||||
|
inherit
|
||||||
|
(this)
|
||||||
|
enfIsPrimitive
|
||||||
;
|
;
|
||||||
|
|
||||||
inherit
|
inherit
|
||||||
|
|
@ -38,14 +45,36 @@
|
||||||
in rec {
|
in rec {
|
||||||
# by default the imported module is given the basename of its path
|
# by default the imported module is given the basename of its path
|
||||||
# but you can set it manually by using the `mix.mod` function.
|
# but you can set it manually by using the `mix.mod` function.
|
||||||
importMods = list: inputs:
|
|
||||||
|
importMod = path: inputs:
|
||||||
|
assert enfIsPrimitive "path" path "importMod"; let
|
||||||
|
mod = import path;
|
||||||
|
in
|
||||||
|
if isAttrs mod
|
||||||
|
then mod
|
||||||
|
else let
|
||||||
|
modResult = mod inputs;
|
||||||
|
in
|
||||||
|
# TODO: create a better version of toString that can handle sets, lists, and null
|
||||||
|
assert isFunction mod
|
||||||
|
|| throw ''
|
||||||
|
Mix modules expect primitive type "set" or "lambda" (returning "set").
|
||||||
|
Got primitive type "${typeOf mod}" instead.
|
||||||
|
'';
|
||||||
|
assert isAttrs modResult
|
||||||
|
|| throw ''
|
||||||
|
Mix module provided as primitive type "lambda" must return primitive type "set"!
|
||||||
|
Got primitive return type "${typeOf modResult} instead."
|
||||||
|
''; modResult;
|
||||||
|
|
||||||
|
mkSubMods = list: inputs:
|
||||||
list
|
list
|
||||||
|> map (path: nameValuePair (modNameFromPath path) (import path inputs))
|
|> map (path: nameValuePair (modNameFromPath path) (importMod path inputs))
|
||||||
|> listToAttrs;
|
|> listToAttrs;
|
||||||
|
|
||||||
importMergeMods = list: inputs:
|
mkIncludes = list: inputs:
|
||||||
list
|
list
|
||||||
|> map (path: (import path inputs))
|
|> map (path: (importMod path inputs))
|
||||||
|> mergeAttrsList;
|
|> mergeAttrsList;
|
||||||
|
|
||||||
# create a new and empty mixture
|
# create a new and empty mixture
|
||||||
|
|
@ -74,8 +103,8 @@ in rec {
|
||||||
# mixture components are ordered based on shadowing
|
# mixture components are ordered based on shadowing
|
||||||
mixture =
|
mixture =
|
||||||
inputs'
|
inputs'
|
||||||
// importMods meta.submods.public inputsWithThis
|
// mkSubMods meta.submods.public inputsWithThis
|
||||||
// importMergeMods meta.includes.public inputsWithThis
|
// mkIncludes meta.includes.public inputsWithThis
|
||||||
// content;
|
// content;
|
||||||
|
|
||||||
# this = {
|
# this = {
|
||||||
|
|
@ -139,11 +168,10 @@ in rec {
|
||||||
# privateMixture = add [private] protectedMixture;
|
# privateMixture = add [private] protectedMixture;
|
||||||
|
|
||||||
mkInterface = name: mixture: base:
|
mkInterface = name: mixture: base:
|
||||||
mergeAttrsList
|
mergeAttrsList [
|
||||||
(attrValues <| importMods meta.includes.${name} mixture)
|
|
||||||
++ [
|
|
||||||
base
|
base
|
||||||
(importMods meta.submods.${name} mixture)
|
(mkIncludes meta.includes.${name} mixture)
|
||||||
|
(mkSubMods meta.submods.${name} mixture)
|
||||||
];
|
];
|
||||||
# XXX: TODO
|
# XXX: TODO
|
||||||
# NOTE: public submodules are still DESCENDENTS
|
# NOTE: public submodules are still DESCENDENTS
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue