vars: implement migration

Migrating generated files from the facts subsystem to the vars subsystem is now possible.

HowTo:
1. declare `clan.core.vars.generators.<generator>.migrateFact = my_service` where `my_service` refers to a service from `clan.core.facts.services`
2. run `clan vers generate your_machine` or `clan machines update your_machine`

Vars will only be migrated for a generator if:
1. The facts service specified via `migrateFact` does exist
2. None of the vars to generate exist yet
3. All public var names exist in the public facts store
4. All secret var names exist in the secret fact store

If the migration is deemed possible, the generator script will not be executed. Instead the files from the public or secret facts store are read and stored into the corresponding vars store
This commit is contained in:
DavHau
2024-09-19 17:55:17 +02:00
parent 733c44b7b6
commit 0a8b7f38a8
7 changed files with 194 additions and 11 deletions

View File

@@ -42,6 +42,7 @@ in
inherit (generator)
dependencies
finalScript
migrateFact
prompts
share
;

View File

@@ -12,6 +12,7 @@ let
either
enum
listOf
nullOr
package
path
str
@@ -49,6 +50,16 @@ in
type = listOf str;
default = [ ];
};
migrateFact = {
description = ''
The fact service name to import the files from.
Use this to migrate legacy facts to the new vars system.
'';
type = nullOr str;
example = "my_service";
default = null;
};
files = {
description = ''
A set of files to generate.