flakeModules: Support disabledModules

Requires Nixpkgs > 2023-03-09
This commit is contained in:
Robert Hensing 2023-01-26 20:40:11 +01:00
parent dc531e3a9c
commit f5b6209441
6 changed files with 46 additions and 11 deletions

46
extras/flakeModules.nix Normal file
View file

@ -0,0 +1,46 @@
{ config, self, lib, flake-parts-lib, ... }:
let
inherit (lib)
filterAttrs
mapAttrs
mkOption
optionalAttrs
types
;
inherit (flake-parts-lib)
mkAliasOptionModule
;
flakeModulesOption = mkOption {
type = types.lazyAttrsOf types.deferredModule;
default = { };
apply = mapAttrs (k: v: {
_file = "${toString self.outPath}/flake.nix#flakeModules.${k}";
key = "${toString self.outPath}/flake.nix#flakeModules.${k}";
imports = [ v ];
});
description = ''
flake-parts modules for use by other flakes.
If the flake defines only one module, it should be flakeModules.default.
You can not use this option in defining the flake's own `imports`. Instead, you can
put the module in question into its own file and reference it both in `imports` and
export it with this option.
'';
};
in
{
options = {
flake = mkOption {
type = types.submoduleWith {
modules = [
(mkAliasOptionModule [ "flakeModule" ] [ "flakeModules" "default" ])
{
options.flakeModules = flakeModulesOption;
}
];
};
};
};
}