lib.modules: Make option injection work when shorthandOnlyDefinesConfig

This commit is contained in:
Robert Hensing 2022-02-28 22:57:03 +01:00
parent 11537c9c02
commit 8baea8b82c
6 changed files with 17 additions and 3 deletions

View File

@ -496,6 +496,7 @@ rec {
options = mkOption { options = mkOption {
type = types.submoduleWith { type = types.submoduleWith {
modules = [ { options = decl.options; } ]; modules = [ { options = decl.options; } ];
shorthandOnlyDefinesConfig = null;
}; };
}; };
}; };

View File

@ -66,6 +66,7 @@ checkConfigOutput '^1$' config.bare-submodule.nested ./declare-bare-submodule.ni
checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix
checkConfigOutput '^42$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix checkConfigOutput '^42$' config.bare-submodule.nested ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix
checkConfigOutput '^420$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix checkConfigOutput '^420$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-nested-option.nix ./declare-bare-submodule-deep-option.nix ./define-bare-submodule-values.nix
checkConfigOutput '^2$' config.bare-submodule.deep ./declare-bare-submodule.nix ./declare-bare-submodule-deep-option.nix ./define-shorthandOnlyDefinesConfig-true.nix
# Check integer types. # Check integer types.
# unsigned # unsigned

View File

@ -1,10 +1,11 @@
{ lib, ... }: { config, lib, ... }:
let let
inherit (lib) mkOption types; inherit (lib) mkOption types;
in in
{ {
options.bare-submodule = mkOption { options.bare-submodule = mkOption {
type = types.submoduleWith { type = types.submoduleWith {
shorthandOnlyDefinesConfig = config.shorthandOnlyDefinesConfig;
modules = [ modules = [
{ {
options.nested = mkOption { options.nested = mkOption {

View File

@ -1,4 +1,4 @@
{ lib, ... }: { config, lib, ... }:
let let
inherit (lib) mkOption types; inherit (lib) mkOption types;
in in
@ -6,7 +6,13 @@ in
options.bare-submodule = mkOption { options.bare-submodule = mkOption {
type = types.submoduleWith { type = types.submoduleWith {
modules = [ ]; modules = [ ];
shorthandOnlyDefinesConfig = config.shorthandOnlyDefinesConfig;
}; };
default = {}; default = {};
}; };
# config-dependent options: won't recommend, but useful for making this test parameterized
options.shorthandOnlyDefinesConfig = mkOption {
default = false;
};
} }

View File

@ -0,0 +1 @@
{ shorthandOnlyDefinesConfig = true; }

View File

@ -637,7 +637,11 @@ rec {
then lhs.specialArgs // rhs.specialArgs then lhs.specialArgs // rhs.specialArgs
else throw "A submoduleWith option is declared multiple times with the same specialArgs \"${toString (attrNames intersecting)}\""; else throw "A submoduleWith option is declared multiple times with the same specialArgs \"${toString (attrNames intersecting)}\"";
shorthandOnlyDefinesConfig = shorthandOnlyDefinesConfig =
if lhs.shorthandOnlyDefinesConfig == rhs.shorthandOnlyDefinesConfig if lhs.shorthandOnlyDefinesConfig == null
then rhs.shorthandOnlyDefinesConfig
else if rhs.shorthandOnlyDefinesConfig == null
then lhs.shorthandOnlyDefinesConfig
else if lhs.shorthandOnlyDefinesConfig == rhs.shorthandOnlyDefinesConfig
then lhs.shorthandOnlyDefinesConfig then lhs.shorthandOnlyDefinesConfig
else throw "A submoduleWith option is declared multiple times with conflicting shorthandOnlyDefinesConfig values"; else throw "A submoduleWith option is declared multiple times with conflicting shorthandOnlyDefinesConfig values";
}; };