3
0
Fork 0
forked from mirrors/nixpkgs

lib: make extensible

This allows the lib fixed point to be extended with

  myLib = lib.extend (self: super: {
    foo = "foo";
  })

With this it's possible to have the new modified lib attrset available to all
modules when using evalModules

  myLib.evalModules {
    modules = [ ({ lib, ... }: {
      options.bar = lib.mkOption {
	default = lib.foo;
      };
    }) ];
  }

  => { config = { bar = "foo"; ... }; options = ...; }
This commit is contained in:
Silvan Mosberger 2018-04-06 18:51:10 +02:00 committed by John Ericson
parent 95ece9efe5
commit e1dee4efcb
2 changed files with 6 additions and 4 deletions

View file

@ -5,9 +5,11 @@
*/
let
callLibs = file: import file { inherit lib; };
inherit (import ./fixed-points.nix {}) makeExtensible;
lib = rec {
lib = makeExtensible (self: let
callLibs = file: import file { lib = self; };
in with self; {
# often used, or depending on very little
trivial = callLibs ./trivial.nix;
@ -128,5 +130,5 @@ let
mergeAttrsNoOverride mergeAttrByFunc mergeAttrsByFuncDefaults
mergeAttrsByFuncDefaultsClean mergeAttrBy
prepareDerivationArgs nixType imap overridableDelayableArgs;
};
});
in lib

View file

@ -59,7 +59,7 @@ rec {
};
};
closed = closeModules (modules ++ [ internalModule ]) ({ inherit config options; lib = import ./.; } // specialArgs);
closed = closeModules (modules ++ [ internalModule ]) ({ inherit config options lib; } // specialArgs);
options = mergeModules prefix (reverseList (filterModules (specialArgs.modulesPath or "") closed));