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

View file

@ -9,13 +9,19 @@ let
escapeNixIdentifier escapeNixIdentifier
; ;
addInfo = class: moduleName: addInfo =
if class == "generic" class: moduleName:
then module: module if class == "generic" then
module: module
else else
module: 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; _class = class;
_file = "${toString moduleLocation}#modules.${escapeNixIdentifier class}.${escapeNixIdentifier moduleName}"; _file = "${toString moduleLocation}#modules.${escapeNixIdentifier class}.${escapeNixIdentifier moduleName}";
imports = [ module ]; imports = [ module ];