diff options
author | Nicolas Pierron <nicolas.b.pierron@gmail.com> | 2009-07-13 16:18:52 +0000 |
---|---|---|
committer | Nicolas Pierron <nicolas.b.pierron@gmail.com> | 2009-07-13 16:18:52 +0000 |
commit | b09382fcd1baa62df37253594a65cef6dfb4fa48 (patch) | |
tree | 72f24ceeff20dd0f28f6c8c0d2586a2b03c76dcf /pkgs/lib/modules.nix | |
parent | 9cd30e68e314f1aab8676cdb07182e913e784284 (diff) | |
download | nixpkgs-b09382fcd1baa62df37253594a65cef6dfb4fa48.tar nixpkgs-b09382fcd1baa62df37253594a65cef6dfb4fa48.tar.gz nixpkgs-b09382fcd1baa62df37253594a65cef6dfb4fa48.tar.bz2 nixpkgs-b09382fcd1baa62df37253594a65cef6dfb4fa48.tar.lz nixpkgs-b09382fcd1baa62df37253594a65cef6dfb4fa48.tar.xz nixpkgs-b09382fcd1baa62df37253594a65cef6dfb4fa48.tar.zst nixpkgs-b09382fcd1baa62df37253594a65cef6dfb4fa48.zip |
Extract properties.nix and modules.nix from options.nix.
svn path=/nixpkgs/trunk/; revision=16339
Diffstat (limited to 'pkgs/lib/modules.nix')
-rw-r--r-- | pkgs/lib/modules.nix | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/pkgs/lib/modules.nix b/pkgs/lib/modules.nix new file mode 100644 index 00000000000..0b92462ee3e --- /dev/null +++ b/pkgs/lib/modules.nix @@ -0,0 +1,71 @@ +# 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; + + moduleClosure = initModules: args: + let + moduleImport = m: + (applyIfFunction (importIfPath m) args) // { + # used by generic closure to avoid duplicated imports. + key = m; + }; + + removeKeys = list: map (m: removeAttrs m ["key"]) list; + + 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); + + inlineImportedSets = list: + lib.concatMap (m:[m] ++ map moduleImport (getImportedSets m)) list; + in + removeKeys (inlineImportedSets (lazyGenericClosure { + startSet = map moduleImport initModules; + operator = m: map moduleImport (getImportedPaths m); + })); + + selectDeclsAndDefs = modules: + lib.concatMap (m: + if m ? config || m ? options then + attrByPath ["options"] [] m + ++ attrByPath ["config"] [] m + else + [ m ] + ) modules; + +} \ No newline at end of file |