2009-07-13 18:18:52 +02:00
|
|
|
# NixOS module handling.
|
|
|
|
|
|
|
|
let lib = import ./default.nix; in
|
|
|
|
|
|
|
|
with { inherit (builtins) head tail; };
|
|
|
|
with import ./trivial.nix;
|
|
|
|
with import ./lists.nix;
|
|
|
|
with import ./misc.nix;
|
|
|
|
with import ./attrsets.nix;
|
|
|
|
with import ./properties.nix;
|
|
|
|
|
|
|
|
rec {
|
|
|
|
|
|
|
|
# Unfortunately this can also be a string.
|
|
|
|
isPath = x: !(
|
|
|
|
builtins.isFunction x
|
|
|
|
|| builtins.isAttrs x
|
|
|
|
|| builtins.isInt x
|
|
|
|
|| builtins.isBool x
|
|
|
|
|| builtins.isList x
|
|
|
|
);
|
|
|
|
|
|
|
|
importIfPath = path:
|
|
|
|
if isPath path then
|
|
|
|
import path
|
|
|
|
else
|
|
|
|
path;
|
|
|
|
|
|
|
|
applyIfFunction = f: arg:
|
|
|
|
if builtins.isFunction f then
|
|
|
|
f arg
|
|
|
|
else
|
|
|
|
f;
|
|
|
|
|
2009-09-14 15:19:00 +02:00
|
|
|
# Convert module to a set which has imports / options and config
|
|
|
|
# attributes.
|
|
|
|
unifyModuleSyntax = m:
|
2009-07-13 18:18:52 +02:00
|
|
|
let
|
|
|
|
getImports = m:
|
|
|
|
if m ? config || m ? options then
|
|
|
|
attrByPath ["imports"] [] m
|
|
|
|
else
|
|
|
|
toList (rmProperties (attrByPath ["require"] [] (delayProperties m)));
|
|
|
|
|
|
|
|
getImportedPaths = m: filter isPath (getImports m);
|
|
|
|
getImportedSets = m: filter (x: !isPath x) (getImports m);
|
|
|
|
|
2009-09-14 15:19:00 +02:00
|
|
|
getConfig = m:
|
|
|
|
removeAttrs (delayProperties m) ["require"];
|
|
|
|
in
|
|
|
|
if m ? config || m ? options then
|
|
|
|
m
|
|
|
|
else
|
|
|
|
{
|
|
|
|
imports = getImportedPaths m;
|
|
|
|
config = getConfig m;
|
|
|
|
} // (
|
|
|
|
if getImportedSets m != [] then
|
|
|
|
assert tail (getImportedSets m) == [];
|
|
|
|
{ options = head (getImportedSets m); }
|
|
|
|
else
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
|
|
|
moduleClosure = initModules: args:
|
|
|
|
let
|
2009-09-15 02:21:39 +02:00
|
|
|
moduleImport = m:
|
|
|
|
(unifyModuleSyntax (applyIfFunction (importIfPath m) args)) // {
|
2009-09-14 15:19:00 +02:00
|
|
|
# used by generic closure to avoid duplicated imports.
|
2009-09-15 02:21:39 +02:00
|
|
|
key = if isPath m then m else
|
|
|
|
/bad/developer/implies/bad/error/messages;
|
|
|
|
};
|
2009-09-14 15:19:00 +02:00
|
|
|
|
|
|
|
getImports = m: attrByPath ["imports"] [] m;
|
2009-09-15 02:21:39 +02:00
|
|
|
|
2009-07-13 18:18:52 +02:00
|
|
|
in
|
2009-09-15 02:21:39 +02:00
|
|
|
(lazyGenericClosure {
|
|
|
|
startSet = map moduleImport (filter isPath initModules);
|
2009-09-14 15:19:00 +02:00
|
|
|
operator = m: map moduleImport (getImports m);
|
2009-09-15 02:21:39 +02:00
|
|
|
}) ++ (map moduleImport (filter (m: ! isPath m) initModules));
|
2009-07-13 18:18:52 +02:00
|
|
|
|
|
|
|
selectDeclsAndDefs = modules:
|
|
|
|
lib.concatMap (m:
|
|
|
|
if m ? config || m ? options then
|
2009-07-14 18:22:42 +02:00
|
|
|
[ (attrByPath ["options"] {} m) ]
|
|
|
|
++ [ (attrByPath ["config"] {} m) ]
|
2009-07-13 18:18:52 +02:00
|
|
|
else
|
|
|
|
[ m ]
|
|
|
|
) modules;
|
|
|
|
|
2009-09-14 22:10:41 +02:00
|
|
|
}
|