Exports POC
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
{
|
||||
# TODO: consume directly from clan.config
|
||||
directory,
|
||||
exports,
|
||||
}:
|
||||
{
|
||||
lib,
|
||||
@@ -17,10 +18,10 @@ in
|
||||
{
|
||||
# TODO: merge these options into clan options
|
||||
options = {
|
||||
exportsModule = mkOption {
|
||||
type = types.deferredModule;
|
||||
readOnly = true;
|
||||
};
|
||||
# exportsModule = mkOption {
|
||||
# type = types.deferredModule;
|
||||
# readOnly = true;
|
||||
# };
|
||||
mappedServices = mkOption {
|
||||
visible = false;
|
||||
type = attrsWith {
|
||||
@@ -28,9 +29,11 @@ in
|
||||
elemType = submoduleWith {
|
||||
class = "clan.service";
|
||||
specialArgs = {
|
||||
directory = directory;
|
||||
clanLib = specialArgs.clanLib;
|
||||
exports = config.exports;
|
||||
inherit
|
||||
exports
|
||||
directory
|
||||
;
|
||||
};
|
||||
modules = [
|
||||
(
|
||||
@@ -51,34 +54,13 @@ in
|
||||
default = { };
|
||||
};
|
||||
exports = mkOption {
|
||||
type = submoduleWith {
|
||||
modules = [
|
||||
{
|
||||
options = {
|
||||
instances = lib.mkOption {
|
||||
default = { };
|
||||
# instances.<instanceName>...
|
||||
type = types.attrsOf (submoduleWith {
|
||||
modules = [
|
||||
config.exportsModule
|
||||
];
|
||||
});
|
||||
};
|
||||
# instances.<machineName>...
|
||||
machines = lib.mkOption {
|
||||
default = { };
|
||||
type = types.attrsOf (submoduleWith {
|
||||
modules = [
|
||||
config.exportsModule
|
||||
];
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
]
|
||||
++ lib.mapAttrsToList (_: service: service.exports) config.mappedServices;
|
||||
};
|
||||
default = { };
|
||||
type = types.lazyAttrsOf types.deferredModule;
|
||||
|
||||
# collect exports from all services
|
||||
# zipAttrs is needed until we use the record type.
|
||||
default = lib.zipAttrsWith (_name: values: { imports = values; }) (
|
||||
lib.mapAttrsToList (_name: service: service.exports) config.mappedServices
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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