Skip to content

evalModules: Imports dont work in types.submodule #377575

@hsjobeki

Description

@hsjobeki

I'd expect imports to work in types.submodule the same as in submoduleWith

Very often i use type = submodule module because it is more convenient to write than type = submoduleWith { modules = toList module; }
Since i knew that submodule is an abstraction over submoduleWith i would expect both to behave the same by default.

The weirdness is that they don't and that people wanted to decompose their submodules into multiple files which is not possible with plain types.submodule

# Doesnt evaluate
eval = evalModules {
    modules = [
      {
        options.foo = lib.mkOption {
          type = lib.types.submodule {
            options.bar = mkOption {
              type = types.str;
            };
          };
        };
        config.foo = {
          # since shorthandsOnlyDefines config is true on submodule this actually sets config.imports
          imports = [
            { bar = "bar"; }
          ];
        };
      }
    ];
  };

Possible solutions:

Idea1:

  • deprecate types.submodule (People should be warned that their modules behave differently)
  • add types.submoduleOf (or similar)

Idea2:

  • disallow imports (and probably options config and other reserved names?)
  • forward imports = config.imports

Metadata

Metadata

Labels

No fields configured for issues without a type.

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions