flakeModules.modules: Make values valid definitions for plain submodule

This commit is contained in:
Robert Hensing 2025-12-08 01:23:36 +01:00
parent 2cccadc735
commit b696a983bc
2 changed files with 46 additions and 18 deletions

View file

@ -95,23 +95,42 @@ rec {
};
};
modulesFlake = mkFlake
{
inputs.self = { };
moduleLocation = "modulesFlake";
}
{
imports = [ flake-parts.flakeModules.modules ];
systems = [ ];
flake = {
modules.generic.example = { lib, ... }: {
options.generic.example = lib.mkOption { default = "works in any module system application"; };
modulesFlake =
mkFlake
{
inputs.self = { };
moduleLocation = "modulesFlake";
}
{
imports = [ flake-parts.flakeModules.modules ];
options = {
# Test option that uses plain types.submodule
flake.fooConfiguration = lib.mkOption {
type = lib.types.submoduleWith {
# Just Like types.submodule;
shorthandOnlyDefinesConfig = true;
class = "foo";
modules = [ ];
};
};
};
modules.foo.example = { lib, ... }: {
options.foo.example = lib.mkOption { default = "works in foo application"; };
config = {
systems = [ ];
flake = {
modules.generic.example =
{ lib, ... }:
{
options.generic.example = lib.mkOption { default = "works in any module system application"; };
};
modules.foo.example =
{ lib, ... }:
{
options.foo.example = lib.mkOption { default = "works in foo application"; };
};
fooConfiguration = modulesFlake.modules.foo.example;
};
};
};
};
flakeModulesDeclare = mkFlake
{ inputs.self = { outPath = ./.; }; }
@ -315,6 +334,9 @@ rec {
];
}).config.foo.example == "works in foo application";
# Test that modules can be loaded into plain submodules with shorthandOnlyDefinesConfig = true
assert modulesFlake.fooConfiguration.foo.example == "works in foo application";
assert specialArgFlake.foo;
assert builtins.isAttrs partitionWithoutExtraInputsFlake.devShells.x86_64-linux;

View file

@ -9,13 +9,19 @@ let
escapeNixIdentifier
;
addInfo = class: moduleName:
if class == "generic"
then module: module
addInfo =
class: moduleName:
if class == "generic" then
module: module
else
module:
# TODO: set key?
# By returning a function, it will be accepted as a full-on module despite
# a submodule having shorthandOnlyDefinesConfig = true, which is the
# `types.submodule` default.
# https://github.com/hercules-ci/flake-parts/issues/326
{ ... }:
{
# TODO: set key?
_class = class;
_file = "${toString moduleLocation}#modules.${escapeNixIdentifier class}.${escapeNixIdentifier moduleName}";
imports = [ module ];