vars: use correct paths for value accesses

Use correct paths for value accesses of vars under:

- `per-machine`
- `shared`
This commit is contained in:
a-kenji
2024-09-11 17:36:07 +02:00
parent 8d27e0412d
commit 4d2ad709ad
4 changed files with 61 additions and 11 deletions

View File

@@ -74,6 +74,17 @@ in
readOnly = true;
default = generator.config._module.args.name;
};
share = {
type = lib.types.bool;
description = ''
Whether the generated vars should be shared between machines.
Shared vars are only generated once, when the first machine using it is deployed.
Subsequent machines will re-use the already generated values.
'';
readOnly = true;
internal = true;
default = generator.config.share;
};
deploy = {
description = ''
Whether the file should be deployed to the target machine.
@@ -97,15 +108,18 @@ in
'';
type = str;
};
value = {
description = ''
The content of the generated value.
Only available if the file is not secret.
'';
type = str;
default = throw "Cannot access value of secret file";
defaultText = "Throws error because the value of a secret file is not accessible";
};
value =
{
description = ''
The content of the generated value.
Only available if the file is not secret.
'';
type = str;
defaultText = "Throws error because the value of a secret file is not accessible";
}
// lib.optionalAttrs file.config.secret {
default = throw "Cannot access value of secret file";
};
};
})
);

View File

@@ -6,8 +6,15 @@
publicModule = "clan_cli.vars.public_modules.in_repo";
fileModule = file: {
path = lib.mkIf (file.config.secret == false) (
config.clan.core.clanDir + "/machines/${config.clan.core.machineName}/vars/${file.config.name}"
if file.config.share then
(config.clan.core.clanDir + "/vars/shared/${file.config.generatorName}/${file.config.name}/value")
else
(
config.clan.core.clanDir
+ "/vars/per-machine/${config.clan.core.machineName}/${file.config.generatorName}/${file.config.name}/value"
)
);
value = lib.mkIf (file.config.secret == false) (lib.readFile file.config.path);
};
};
}