Make mkFlake extensible with additional modules

This is intended to allow flakes implementing a flakelight module to
export a mkFlake that automatically includes its module.
This commit is contained in:
Archit Gupta 2023-09-13 22:39:20 -07:00
parent 62083df539
commit 53f35dc91c

View File

@ -6,7 +6,7 @@ nixpkgs:
let
inherit (builtins) isAttrs isPath readDir;
inherit (nixpkgs.lib) attrNames composeManyExtensions
filter findFirst genAttrs getValues hasSuffix isFunction isList
filter findFirst fix genAttrs getValues hasSuffix isFunction isList
mapAttrsToList pathExists pipe removePrefix removeSuffix evalModules
mkDefault mkOptionType singleton;
inherit (nixpkgs.lib.types) coercedTo functionTo listOf;
@ -14,15 +14,24 @@ let
builtinModules = mapAttrsToList (k: _: ./builtinModules + ("/" + k))
(readDir ./builtinModules);
mkFlake = src: root: (evalModules {
mkFlake = {
__functor = self: src: root: (evalModules {
specialArgs.modulesPath = ./builtinModules;
modules = builtinModules ++ [
modules = builtinModules ++ self.extraModules ++ [
{ inputs.nixpkgs = mkDefault nixpkgs; }
{ _module.args = { inherit src flakelight; }; }
root
];
}).config.outputs;
# Attributes to allow module flakes to extend mkFlake
extraModules = [ ];
extend = (fix (extend': mkFlake': modules: fix (self: mkFlake' // {
extraModules = mkFlake'.extraModules ++ modules;
extend = extend' self;
}))) mkFlake;
};
flakelight = {
inherit mkFlake supportedSystem autoImport autoImportArgs;