diff --git a/docs/site/getting-started/configure.md b/docs/site/getting-started/configure.md index 6eca52854..34ad33b84 100644 --- a/docs/site/getting-started/configure.md +++ b/docs/site/getting-started/configure.md @@ -199,21 +199,6 @@ If you only want to setup a single machine at this point, you can delete `sara` git rm ./machines/sara ``` -### Step 5: Check Configuration - -Validate your configuration by running: - -```bash -nix flake check -``` - -This command helps ensure that your system configuration is correct and free from errors. - -!!! Tip - - You can integrate this step into your [Continuous Integration](https://en.wikipedia.org/wiki/Continuous_integration) workflow to ensure that only valid Nix configurations are merged into your codebase. - - --- ## Whats next? diff --git a/docs/site/getting-started/secrets.md b/docs/site/getting-started/secrets.md index 350fde04e..9efca892e 100644 --- a/docs/site/getting-started/secrets.md +++ b/docs/site/getting-started/secrets.md @@ -55,7 +55,35 @@ sops/ ``` If you followed the quickstart tutorial all necessary secrets are initialized at this point. ---- + + +### Generate Facts and Vars + +Typically, this step is handled automatically when a machine is deployed. However, to enable the use of `nix flake check` with your configuration, it must be completed manually beforehand. + +Currently, generating all the necessary facts requires two separate commands. This is due to the coexistence of two parallel secret management solutions: the older, stable version (`clan secrets` and `clan facts`) and the newer, experimental version (`clan vars`). + +To generate both facts and vars, execute the following commands: + +```sh +clan facts generate && clan vars generate +``` + + +### Check Configuration + +Validate your configuration by running: + +```bash +nix flake check +``` + +This command helps ensure that your system configuration is correct and free from errors. + +!!! Tip + + You can integrate this step into your [Continuous Integration](https://en.wikipedia.org/wiki/Continuous_integration) workflow to ensure that only valid Nix configurations are merged into your codebase. + ## Whats next? diff --git a/pkgs/clan-cli/clan_cli/facts/generate.py b/pkgs/clan-cli/clan_cli/facts/generate.py index 89b59afb3..a1a279b04 100644 --- a/pkgs/clan-cli/clan_cli/facts/generate.py +++ b/pkgs/clan-cli/clan_cli/facts/generate.py @@ -189,8 +189,8 @@ def _generate_facts_for_machine( def generate_facts( machines: list[Machine], - service: str | None, - regenerate: bool, + service: str | None = None, + regenerate: bool = False, prompt: Callable[[str, str], str] = prompt_func, ) -> bool: was_regenerated = False @@ -212,7 +212,7 @@ def generate_facts( ) raise ClanError(msg) - if not was_regenerated: + if not was_regenerated and len(machines) > 0: machine.info("All secrets and facts are already up to date") return was_regenerated diff --git a/pkgs/clan-cli/clan_cli/flash/flash.py b/pkgs/clan-cli/clan_cli/flash/flash.py index 8fd36c153..9d3955770 100644 --- a/pkgs/clan-cli/clan_cli/flash/flash.py +++ b/pkgs/clan-cli/clan_cli/flash/flash.py @@ -63,7 +63,7 @@ def flash_machine( generate_vars_for_machine( machine, generator_name=None, regenerate=False, fix=False ) - generate_facts([machine], service=None, regenerate=False) + generate_facts([machine]) if system_config.wifi_settings: wifi_settings: dict[str, dict[str, str]] = {} diff --git a/pkgs/clan-cli/clan_cli/machines/install.py b/pkgs/clan-cli/clan_cli/machines/install.py index 98d7edf70..37f588e4e 100644 --- a/pkgs/clan-cli/clan_cli/machines/install.py +++ b/pkgs/clan-cli/clan_cli/machines/install.py @@ -55,8 +55,8 @@ def install_machine(opts: InstallOptions) -> None: target_host = f"{h.user or 'root'}@{h.host}" log.info(f"target host: {target_host}") - generate_facts([machine], None, False) - generate_vars([machine], None, False) + generate_facts([machine]) + generate_vars([machine]) with TemporaryDirectory(prefix="nixos-install-") as tmpdir_: tmpdir = Path(tmpdir_) diff --git a/pkgs/clan-cli/clan_cli/machines/update.py b/pkgs/clan-cli/clan_cli/machines/update.py index 52e34002f..5d62adeaa 100644 --- a/pkgs/clan-cli/clan_cli/machines/update.py +++ b/pkgs/clan-cli/clan_cli/machines/update.py @@ -114,8 +114,8 @@ def deploy_machine(machines: MachineGroup) -> None: def deploy(machine: Machine) -> None: host = machine.build_host - generate_facts([machine], None, False) - generate_vars([machine], None, False) + generate_facts([machine]) + generate_vars([machine]) upload_secrets(machine) upload_secret_vars(machine) diff --git a/pkgs/clan-cli/clan_cli/vars/generate.py b/pkgs/clan-cli/clan_cli/vars/generate.py index c2fc016d3..c431c97e6 100644 --- a/pkgs/clan-cli/clan_cli/vars/generate.py +++ b/pkgs/clan-cli/clan_cli/vars/generate.py @@ -405,8 +405,8 @@ def generate_vars_for_machine( def generate_vars( machines: list[Machine], - generator_name: str | None, - regenerate: bool, + generator_name: str | None = None, + regenerate: bool = False, fix: bool = False, ) -> bool: was_regenerated = False @@ -424,7 +424,7 @@ def generate_vars( msg = f"Failed to generate facts for {len(errors)} hosts. Check the logs above" raise ClanError(msg) from errors[0] - if not was_regenerated: + if not was_regenerated and len(machines) > 0: machine.info("All vars are already up to date") return was_regenerated diff --git a/pkgs/clan-cli/clan_cli/vms/run.py b/pkgs/clan-cli/clan_cli/vms/run.py index 1d8fe8629..852b27232 100644 --- a/pkgs/clan-cli/clan_cli/vms/run.py +++ b/pkgs/clan-cli/clan_cli/vms/run.py @@ -84,7 +84,7 @@ def get_secrets( secret_facts_module = importlib.import_module(machine.secret_facts_module) secret_facts_store = secret_facts_module.SecretStore(machine=machine) - generate_facts([machine], None, False) + generate_facts([machine]) secret_facts_store.upload(secrets_dir) return secrets_dir