feat(lib/inventory): fix arguments discrepancy on perInstance and perMachine
This commit is contained in:
@@ -317,11 +317,15 @@ in
|
||||
*/
|
||||
v: instanceName: machineName:
|
||||
(lib.evalModules {
|
||||
specialArgs = {
|
||||
inherit instanceName;
|
||||
specialArgs =
|
||||
let
|
||||
roles = applySettings instanceName config.instances.${instanceName};
|
||||
in
|
||||
{
|
||||
inherit instanceName roles;
|
||||
machine = {
|
||||
name = machineName;
|
||||
roles = applySettings instanceName config.instances.${instanceName};
|
||||
roles = lib.attrNames (lib.filterAttrs (_n: v: v.machines ? ${machineName}) roles);
|
||||
};
|
||||
settings = (
|
||||
makeExtensibleConfig evalMachineSettings {
|
||||
|
||||
@@ -67,6 +67,7 @@ in
|
||||
# We might change the attribute name in the future
|
||||
expr = res.importedModulesEvaluated ? "self-simple-module";
|
||||
expected = true;
|
||||
inherit res;
|
||||
};
|
||||
|
||||
# A module can be imported multiple times
|
||||
|
||||
@@ -10,6 +10,7 @@ let
|
||||
};
|
||||
# Define two roles with unmergeable interfaces
|
||||
# Both define some 'timeout' but with completely different types.
|
||||
roles.controller = { };
|
||||
roles.peer.interface =
|
||||
{ lib, ... }:
|
||||
{
|
||||
@@ -23,6 +24,7 @@ let
|
||||
instanceName,
|
||||
settings,
|
||||
machine,
|
||||
roles,
|
||||
...
|
||||
}:
|
||||
let
|
||||
@@ -35,7 +37,12 @@ let
|
||||
in
|
||||
{
|
||||
nixosModule = {
|
||||
inherit instanceName settings machine;
|
||||
inherit
|
||||
instanceName
|
||||
settings
|
||||
machine
|
||||
roles
|
||||
;
|
||||
|
||||
# We are double vendoring the settings
|
||||
# To test that we can do it indefinitely
|
||||
@@ -64,6 +71,7 @@ let
|
||||
roles.peer = {
|
||||
settings.timeout = "foo-peer";
|
||||
};
|
||||
roles.controller.machines.jon = { };
|
||||
};
|
||||
instances."instance_bar" = {
|
||||
module = {
|
||||
@@ -73,6 +81,8 @@ let
|
||||
settings.timeout = "bar-peer-jon";
|
||||
};
|
||||
};
|
||||
# TODO: move this into a seperate test.
|
||||
# Seperate out the check that this module is never imported
|
||||
# import the module "B" (undefined)
|
||||
# All machines have this instance
|
||||
instances."instance_zaza" = {
|
||||
@@ -108,17 +118,9 @@ in
|
||||
# roles = peer
|
||||
# machines = jon
|
||||
settings = filterInternals res.importedModulesEvaluated.self-A.config.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.nixosModule.settings;
|
||||
machine = mapInternalsRecursive res.importedModulesEvaluated.self-A.config.result.allRoles.peer.allInstances.instance_foo.allMachines.jon.nixosModule.machine;
|
||||
|
||||
# hasRoleSettings =
|
||||
# res.importedModulesEvaluated.self-A.config.result.allMachines.jon.nixosModule.instance_foo.roles.peer ? settings;
|
||||
|
||||
# # settings are specific.
|
||||
# # Below we access:
|
||||
# # instance = instance_foo
|
||||
# # roles = peer
|
||||
# # machines = *
|
||||
# specificRoleSettings = filterInternals res.importedModulesEvaluated.self-A.config.result.allMachines.jon.nixosModule.instance_foo.roles.peer.settings;
|
||||
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;
|
||||
};
|
||||
expected = {
|
||||
instanceName = "instance_foo";
|
||||
@@ -127,7 +129,24 @@ in
|
||||
};
|
||||
machine = {
|
||||
name = "jon";
|
||||
roles = [
|
||||
"controller"
|
||||
"peer"
|
||||
];
|
||||
};
|
||||
roles = {
|
||||
controller = {
|
||||
machines = {
|
||||
jon = {
|
||||
settings = {
|
||||
__functor = "__functor";
|
||||
};
|
||||
};
|
||||
};
|
||||
settings = {
|
||||
__functor = "__functor";
|
||||
};
|
||||
};
|
||||
peer = {
|
||||
machines = {
|
||||
jon = {
|
||||
@@ -145,7 +164,6 @@ in
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
test_per_instance_settings_vendoring = {
|
||||
expr =
|
||||
|
||||
@@ -26,9 +26,11 @@ let
|
||||
};
|
||||
|
||||
perMachine =
|
||||
{ instances, ... }:
|
||||
{ instances, machine, ... }:
|
||||
{
|
||||
nixosModule = instances;
|
||||
nixosModule = {
|
||||
inherit instances machine;
|
||||
};
|
||||
};
|
||||
};
|
||||
machines = {
|
||||
@@ -71,9 +73,10 @@ in
|
||||
|
||||
# settings should evaluate
|
||||
test_per_machine_receives_instance_settings = {
|
||||
inherit res;
|
||||
expr = {
|
||||
hasMachineSettings =
|
||||
res.importedModulesEvaluated.self-A.config.result.allMachines.jon.nixosModule.instance_foo.roles.peer.machines.jon
|
||||
res.importedModulesEvaluated.self-A.config.result.allMachines.jon.nixosModule.instances.instance_foo.roles.peer.machines.jon
|
||||
? settings;
|
||||
|
||||
# settings are specific.
|
||||
@@ -81,10 +84,10 @@ in
|
||||
# instance = instance_foo
|
||||
# roles = peer
|
||||
# machines = jon
|
||||
specificMachineSettings = filterInternals res.importedModulesEvaluated.self-A.config.result.allMachines.jon.nixosModule.instance_foo.roles.peer.machines.jon.settings;
|
||||
specificMachineSettings = filterInternals res.importedModulesEvaluated.self-A.config.result.allMachines.jon.nixosModule.instances.instance_foo.roles.peer.machines.jon.settings;
|
||||
|
||||
hasRoleSettings =
|
||||
res.importedModulesEvaluated.self-A.config.result.allMachines.jon.nixosModule.instance_foo.roles.peer
|
||||
res.importedModulesEvaluated.self-A.config.result.allMachines.jon.nixosModule.instances.instance_foo.roles.peer
|
||||
? settings;
|
||||
|
||||
# settings are specific.
|
||||
@@ -92,7 +95,7 @@ in
|
||||
# instance = instance_foo
|
||||
# roles = peer
|
||||
# machines = *
|
||||
specificRoleSettings = filterInternals res.importedModulesEvaluated.self-A.config.result.allMachines.jon.nixosModule.instance_foo.roles.peer.settings;
|
||||
specificRoleSettings = filterInternals res.importedModulesEvaluated.self-A.config.result.allMachines.jon.nixosModule.instances.instance_foo.roles.peer.settings;
|
||||
};
|
||||
expected = {
|
||||
hasMachineSettings = true;
|
||||
|
||||
Reference in New Issue
Block a user