feat(inventory/instances): add extendSettings as argument to perInstance, perMachine
This commit is contained in:
@@ -132,6 +132,11 @@ let
|
|||||||
in
|
in
|
||||||
makeModuleExtensible (f args);
|
makeModuleExtensible (f args);
|
||||||
|
|
||||||
|
# Extend evalModules result by a module, returns .config.
|
||||||
|
extendEval =
|
||||||
|
eval: m:
|
||||||
|
(eval.extendModules { modules = lib.toList m; } ).config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Apply the settings to the instance
|
Apply the settings to the instance
|
||||||
|
|
||||||
@@ -147,19 +152,19 @@ let
|
|||||||
# TODO: evaluate the settings against the interface
|
# TODO: evaluate the settings against the interface
|
||||||
# settings = (evalMachineSettings { inherit roleName instanceName; inherit (v) settings; }).config;
|
# settings = (evalMachineSettings { inherit roleName instanceName; inherit (v) settings; }).config;
|
||||||
settings = (
|
settings = (
|
||||||
makeExtensibleConfig evalMachineSettings {
|
evalMachineSettings {
|
||||||
inherit roleName instanceName machineName;
|
inherit roleName instanceName machineName;
|
||||||
inherit (v) settings;
|
inherit (v) settings;
|
||||||
}
|
}
|
||||||
);
|
).config;
|
||||||
}) role.machines;
|
}) role.machines;
|
||||||
# TODO: evaluate the settings against the interface
|
# TODO: evaluate the settings against the interface
|
||||||
settings = (
|
settings = (
|
||||||
makeExtensibleConfig evalMachineSettings {
|
evalMachineSettings {
|
||||||
inherit roleName instanceName;
|
inherit roleName instanceName;
|
||||||
inherit (role) settings;
|
inherit (role) settings;
|
||||||
}
|
}
|
||||||
);
|
).config;
|
||||||
}) instance.roles;
|
}) instance.roles;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
@@ -328,7 +333,14 @@ in
|
|||||||
roles = lib.attrNames (lib.filterAttrs (_n: v: v.machines ? ${machineName}) roles);
|
roles = lib.attrNames (lib.filterAttrs (_n: v: v.machines ? ${machineName}) roles);
|
||||||
};
|
};
|
||||||
settings = (
|
settings = (
|
||||||
makeExtensibleConfig evalMachineSettings {
|
evalMachineSettings {
|
||||||
|
inherit roleName instanceName machineName;
|
||||||
|
settings =
|
||||||
|
config.instances.${instanceName}.roles.${roleName}.machines.${machineName}.settings or { };
|
||||||
|
}
|
||||||
|
).config;
|
||||||
|
extendSettings = extendEval (
|
||||||
|
evalMachineSettings {
|
||||||
inherit roleName instanceName machineName;
|
inherit roleName instanceName machineName;
|
||||||
settings =
|
settings =
|
||||||
config.instances.${instanceName}.roles.${roleName}.machines.${machineName}.settings or { };
|
config.instances.${instanceName}.roles.${roleName}.machines.${machineName}.settings or { };
|
||||||
@@ -396,6 +408,7 @@ in
|
|||||||
in
|
in
|
||||||
uniqueStrings (collectRoles machineScope.instances);
|
uniqueStrings (collectRoles machineScope.instances);
|
||||||
};
|
};
|
||||||
|
# TODO: instances.<instanceName>.roles should contain all roles, even if nobody has the role
|
||||||
inherit (machineScope) instances;
|
inherit (machineScope) instances;
|
||||||
|
|
||||||
# There are no machine settings.
|
# There are no machine settings.
|
||||||
|
|||||||
@@ -23,16 +23,17 @@ let
|
|||||||
{
|
{
|
||||||
instanceName,
|
instanceName,
|
||||||
settings,
|
settings,
|
||||||
|
extendSettings,
|
||||||
machine,
|
machine,
|
||||||
roles,
|
roles,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
settings1 = settings {
|
finalSettings = extendSettings {
|
||||||
# Sometimes we want to create a default settings set depending on the machine config.
|
# Sometimes we want to create a default settings set depending on the machine config.
|
||||||
# Note: Other machines cannot depend on this settings. We must assign a new name to the settings.
|
# Note: Other machines cannot depend on this settings. We must assign a new name to the settings.
|
||||||
# And thus the new value is not accessible by other machines.
|
# And thus the new value is not accessible by other machines.
|
||||||
timeout = lib.mkOverride 10 "config.blah";
|
timeout = lib.mkOverride 10 "config.thing";
|
||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
@@ -46,12 +47,7 @@ let
|
|||||||
|
|
||||||
# We are double vendoring the settings
|
# We are double vendoring the settings
|
||||||
# To test that we can do it indefinitely
|
# To test that we can do it indefinitely
|
||||||
vendoredSettings = settings1 {
|
vendoredSettings = finalSettings;
|
||||||
# Sometimes we want to create a default settings set depending on the machine config.
|
|
||||||
# Note: Other machines cannot depend on this settings. We must assign a new name to the settings.
|
|
||||||
# And thus the new value is not accessible by other machines.
|
|
||||||
timeout = lib.mkOverride 5 "config.thing";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -92,18 +88,6 @@ let
|
|||||||
roles.peer.tags.all = { };
|
roles.peer.tags.all = { };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
filterInternals = lib.filterAttrs (n: _v: !lib.hasPrefix "_" n);
|
|
||||||
|
|
||||||
# Replace internal attributes ('_' prefix)
|
|
||||||
# So we catch their presence but don't check the value
|
|
||||||
mapInternalsRecursive = lib.mapAttrsRecursive (
|
|
||||||
path: v:
|
|
||||||
let
|
|
||||||
name = lib.last path;
|
|
||||||
in
|
|
||||||
if !lib.hasPrefix "_" name then v else name
|
|
||||||
);
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# settings should evaluate
|
# settings should evaluate
|
||||||
@@ -117,10 +101,12 @@ in
|
|||||||
# instance = instance_foo
|
# instance = instance_foo
|
||||||
# roles = peer
|
# roles = peer
|
||||||
# machines = jon
|
# machines = jon
|
||||||
settings = filterInternals res.importedModulesEvaluated.self-A.config.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.nixosModule.settings;
|
settings =
|
||||||
|
res.importedModulesEvaluated.self-A.config.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.nixosModule.settings;
|
||||||
machine =
|
machine =
|
||||||
res.importedModulesEvaluated.self-A.config.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.nixosModule.machine;
|
res.importedModulesEvaluated.self-A.config.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.nixosModule.machine;
|
||||||
roles = mapInternalsRecursive res.importedModulesEvaluated.self-A.config.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.nixosModule.roles;
|
roles =
|
||||||
|
res.importedModulesEvaluated.self-A.config.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.nixosModule.roles;
|
||||||
};
|
};
|
||||||
expected = {
|
expected = {
|
||||||
instanceName = "instance_foo";
|
instanceName = "instance_foo";
|
||||||
@@ -139,25 +125,21 @@ in
|
|||||||
machines = {
|
machines = {
|
||||||
jon = {
|
jon = {
|
||||||
settings = {
|
settings = {
|
||||||
__functor = "__functor";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
settings = {
|
settings = {
|
||||||
__functor = "__functor";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
peer = {
|
peer = {
|
||||||
machines = {
|
machines = {
|
||||||
jon = {
|
jon = {
|
||||||
settings = {
|
settings = {
|
||||||
__functor = "__functor";
|
|
||||||
timeout = "foo-peer-jon";
|
timeout = "foo-peer-jon";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
settings = {
|
settings = {
|
||||||
__functor = "__functor";
|
|
||||||
timeout = "foo-peer";
|
timeout = "foo-peer";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -167,11 +149,9 @@ in
|
|||||||
|
|
||||||
test_per_instance_settings_vendoring = {
|
test_per_instance_settings_vendoring = {
|
||||||
expr =
|
expr =
|
||||||
mapInternalsRecursive
|
|
||||||
res.importedModulesEvaluated.self-A.config.result.allRoles.peer.allInstances."instance_foo".allMachines.jon.nixosModule.vendoredSettings;
|
res.importedModulesEvaluated.self-A.config.result.allRoles.peer.allInstances."instance_foo".allMachines.jon.nixosModule.vendoredSettings;
|
||||||
expected = {
|
expected = {
|
||||||
# Returns another override
|
|
||||||
__functor = "__functor";
|
|
||||||
timeout = "config.thing";
|
timeout = "config.thing";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user