mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 16:10:05 +01:00
feat(submodules): add support for submodule exports
This commit is contained in:
parent
accd2dec1b
commit
9ca9c44c92
4 changed files with 52 additions and 2 deletions
|
|
@ -29,10 +29,16 @@ with lib;
|
||||||
default = [];
|
default = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports = mkOption {
|
||||||
|
description = "Attribute set of functions to export";
|
||||||
|
type = types.attrs;
|
||||||
|
default = {};
|
||||||
|
};
|
||||||
|
|
||||||
passthru = mkOption {
|
passthru = mkOption {
|
||||||
description = "Attribute set to passthru";
|
description = "Attribute set to passthru";
|
||||||
default = {};
|
|
||||||
type = types.attrs;
|
type = types.attrs;
|
||||||
|
default = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
args._empty = mkOption {};
|
args._empty = mkOption {};
|
||||||
|
|
|
||||||
|
|
@ -144,11 +144,17 @@ in {
|
||||||
description = "Submodule definition";
|
description = "Submodule definition";
|
||||||
type = types.attrs;
|
type = types.attrs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exportAs = mkOption {
|
||||||
|
description = "Name under which to register exports";
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
definition = {
|
definition = {
|
||||||
inherit (evaledSubmodule.config.submodule) name description version tags;
|
inherit (evaledSubmodule.config.submodule) name description version tags exports;
|
||||||
};
|
};
|
||||||
|
|
||||||
features = evaledSubmodule.config._module.features;
|
features = evaledSubmodule.config._module.features;
|
||||||
|
|
@ -230,6 +236,11 @@ in {
|
||||||
|
|
||||||
config = mkMerge ([
|
config = mkMerge ([
|
||||||
{
|
{
|
||||||
|
# register exported functions as args
|
||||||
|
_module.args = mkMerge (map (submodule: {
|
||||||
|
${submodule.exportAs} = submodule.definition.exports;
|
||||||
|
}) (filter (submodule: submodule.exportAs != null) cfg.imports));
|
||||||
|
|
||||||
_module.features = ["submodules"];
|
_module.features = ["submodules"];
|
||||||
|
|
||||||
submodules.specialArgs.kubenix = kubenix;
|
submodules.specialArgs.kubenix = kubenix;
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ let
|
||||||
./submodules/simple.nix
|
./submodules/simple.nix
|
||||||
./submodules/defaults.nix
|
./submodules/defaults.nix
|
||||||
./submodules/versioning.nix
|
./submodules/versioning.nix
|
||||||
|
./submodules/exports.nix
|
||||||
];
|
];
|
||||||
testing.args = {
|
testing.args = {
|
||||||
inherit images k8sVersion;
|
inherit images k8sVersion;
|
||||||
|
|
|
||||||
32
tests/submodules/exports.nix
Normal file
32
tests/submodules/exports.nix
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
{ name, config, lib, kubenix, subm-lib, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
submodule = {
|
||||||
|
imports = [ kubenix.modules.submodule ];
|
||||||
|
|
||||||
|
config.submodule = {
|
||||||
|
name = "subm";
|
||||||
|
exports = {
|
||||||
|
inherit id;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
imports = with kubenix.modules; [ test submodules ];
|
||||||
|
|
||||||
|
test = {
|
||||||
|
name = "submodules-exports";
|
||||||
|
description = "Submodules exports test";
|
||||||
|
assertions = [{
|
||||||
|
message = "should have library exported";
|
||||||
|
assertion = subm-lib.id 1 == 1;
|
||||||
|
}];
|
||||||
|
};
|
||||||
|
|
||||||
|
submodules.imports = [{
|
||||||
|
modules = [submodule];
|
||||||
|
exportAs = "subm-lib";
|
||||||
|
}];
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue