Exports POC
This commit is contained in:
@@ -504,7 +504,7 @@ in
|
||||
staticModules = [
|
||||
({
|
||||
options.exports = mkOption {
|
||||
type = types.deferredModule;
|
||||
type = types.lazyAttrsOf types.deferredModule;
|
||||
default = { };
|
||||
description = ''
|
||||
!!! Danger "Experimental Feature"
|
||||
@@ -634,8 +634,16 @@ in
|
||||
type = types.deferredModuleWith {
|
||||
staticModules = [
|
||||
({
|
||||
# exports."///".generator.name = { _file ... import = []; _type = }
|
||||
# exports."///".networking = { _file ... import = []; }
|
||||
|
||||
# generators."///".name = { name, ...}: { _file ... import = [];}
|
||||
# networks."///" = { _file ... import = []; }
|
||||
|
||||
# { _file ... import = []; }
|
||||
# { _file ... import = []; }
|
||||
options.exports = mkOption {
|
||||
type = types.deferredModule;
|
||||
type = types.lazyAttrsOf types.deferredModule;
|
||||
default = { };
|
||||
description = ''
|
||||
!!! Danger "Experimental Feature"
|
||||
@@ -767,79 +775,38 @@ in
|
||||
```
|
||||
'';
|
||||
default = { };
|
||||
type = types.submoduleWith {
|
||||
# Static modules
|
||||
modules = [
|
||||
{
|
||||
options.instances = mkOption {
|
||||
type = types.attrsOf types.deferredModule;
|
||||
description = ''
|
||||
export modules defined in 'perInstance'
|
||||
mapped to their instance name
|
||||
|
||||
Example
|
||||
|
||||
with instances:
|
||||
|
||||
```nix
|
||||
instances.A = { ... };
|
||||
instances.B= { ... };
|
||||
|
||||
roles.peer.perInstance = { instanceName, machine, ... }:
|
||||
{
|
||||
exports.foo = 1;
|
||||
}
|
||||
|
||||
This yields all other services can access these exports
|
||||
=>
|
||||
exports.instances.A.foo = 1;
|
||||
exports.instances.B.foo = 1;
|
||||
```
|
||||
'';
|
||||
};
|
||||
options.machines = mkOption {
|
||||
type = types.attrsOf types.deferredModule;
|
||||
description = ''
|
||||
export modules defined in 'perMachine'
|
||||
mapped to their machine name
|
||||
|
||||
Example
|
||||
|
||||
with machines:
|
||||
|
||||
```nix
|
||||
instances.A = { roles.peer.machines.jon = ... };
|
||||
instances.B = { roles.peer.machines.jon = ... };
|
||||
|
||||
perMachine = { machine, ... }:
|
||||
{
|
||||
exports.foo = 1;
|
||||
}
|
||||
|
||||
This yields all other services can access these exports
|
||||
=>
|
||||
exports.machines.jon.foo = 1;
|
||||
exports.machines.sara.foo = 1;
|
||||
```
|
||||
'';
|
||||
};
|
||||
# Lazy default via imports
|
||||
# should probably be moved to deferredModuleWith { staticModules = [ ]; }
|
||||
imports =
|
||||
if config._docs_rendering then
|
||||
[ ]
|
||||
else
|
||||
lib.mapAttrsToList (_roleName: role: {
|
||||
instances = lib.mapAttrs (_instanceName: instance: {
|
||||
imports = lib.mapAttrsToList (_machineName: v: v.exports) instance.allMachines;
|
||||
}) role.allInstances;
|
||||
}) config.result.allRoles
|
||||
++ lib.mapAttrsToList (machineName: machine: {
|
||||
machines.${machineName} = machine.exports;
|
||||
}) config.result.allMachines;
|
||||
}
|
||||
];
|
||||
};
|
||||
type = types.lazyAttrsOf (
|
||||
types.deferredModuleWith {
|
||||
# staticModules = [];
|
||||
# lib.concatLists (
|
||||
# lib.concatLists (
|
||||
# lib.mapAttrsToList (
|
||||
# _roleName: role:
|
||||
# lib.mapAttrsToList (
|
||||
# _instanceName: instance: lib.mapAttrsToList (_machineName: v: v.exports) instance.allMachines
|
||||
# ) role.allInstances
|
||||
# ) config.result.allRoles
|
||||
# )
|
||||
# )
|
||||
# ++
|
||||
}
|
||||
);
|
||||
# # Lazy default via imports
|
||||
# # should probably be moved to deferredModuleWith { staticModules = [ ]; }
|
||||
# imports =
|
||||
# if config._docs_rendering then
|
||||
# [ ]
|
||||
# else
|
||||
# lib.mapAttrsToList (_roleName: role: {
|
||||
# instances = lib.mapAttrs (_instanceName: instance: {
|
||||
# imports = lib.mapAttrsToList (_machineName: v: v.exports) instance.allMachines;
|
||||
# }) role.allInstances;
|
||||
# }) config.result.allRoles
|
||||
# ++ lib.mapAttrsToList (machineName: machine: {
|
||||
# machines.${machineName} = machine.exports;
|
||||
# }) config.result.allMachines;
|
||||
# }
|
||||
# ];
|
||||
};
|
||||
# ---
|
||||
# Place the result in _module.result to mark them as "internal" and discourage usage/overrides
|
||||
@@ -1024,5 +991,39 @@ in
|
||||
}
|
||||
) config.result.allMachines;
|
||||
};
|
||||
|
||||
debug = mkOption {
|
||||
default = lib.zipAttrsWith (_name: values: { imports = values; }) (
|
||||
lib.mapAttrsToList (_machineName: machine: machine.exports) config.result.allMachines
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
imports = [
|
||||
{
|
||||
# collect exports from all machines
|
||||
# zipAttrs is needed until we use the record type.
|
||||
exports = lib.zipAttrsWith (_name: values: { imports = values; }) (
|
||||
lib.mapAttrsToList (_machineName: machine: machine.exports) config.result.allMachines
|
||||
);
|
||||
|
||||
}
|
||||
{
|
||||
# collect exports from all instances, roles and machines
|
||||
# zipAttrs is needed until we use the record type.
|
||||
exports = lib.zipAttrsWith (_name: values: { imports = values; }) (
|
||||
lib.concatLists (
|
||||
lib.concatLists (
|
||||
lib.mapAttrsToList (
|
||||
_roleName: role:
|
||||
lib.mapAttrsToList (
|
||||
_instanceName: instance: lib.mapAttrsToList (_machineName: v: v.exports) instance.allMachines
|
||||
) role.allInstances
|
||||
) config.result.allRoles
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user