machine/host: degrade into info and add docs
This commit is contained in:
@@ -62,6 +62,7 @@ nav:
|
|||||||
- Vars Backend: guides/vars-backend.md
|
- Vars Backend: guides/vars-backend.md
|
||||||
- Facts Backend: guides/secrets.md
|
- Facts Backend: guides/secrets.md
|
||||||
- Adding more machines: guides/more-machines.md
|
- Adding more machines: guides/more-machines.md
|
||||||
|
- Target Host: guides/target-host.md
|
||||||
- Inventory:
|
- Inventory:
|
||||||
- Inventory: guides/inventory.md
|
- Inventory: guides/inventory.md
|
||||||
- Secure Boot: guides/secure-boot.md
|
- Secure Boot: guides/secure-boot.md
|
||||||
|
|||||||
82
docs/site/guides/target-host.md
Normal file
82
docs/site/guides/target-host.md
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
# How to Set `targetHost` for a Machine
|
||||||
|
|
||||||
|
The `targetHost` defines where the machine can be reached for operations like SSH or deployment. You can set it in two ways, depending on your use case.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ Option 1: Use the Inventory (Recommended for Static Hosts)
|
||||||
|
|
||||||
|
If the hostname is **static**, like `server.example.com`, set it in the **inventory**:
|
||||||
|
|
||||||
|
```{.nix title="flake.nix" hl_lines="8"}
|
||||||
|
{
|
||||||
|
# edlided
|
||||||
|
outputs =
|
||||||
|
{ self, clan-core, ... }:
|
||||||
|
let
|
||||||
|
clan = clan-core.lib.clan {
|
||||||
|
inventory.machines.jon = {
|
||||||
|
deploy.targetHost = "root@server.example.com";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit (clan.config) nixosConfigurations nixosModules clanInternals;
|
||||||
|
# elided
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is fast, simple and explicit, and doesn’t require evaluating the NixOS config. We can also displayed it in the clan-cli or clan-app.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ Option 2: Use NixOS (Only for Dynamic Hosts)
|
||||||
|
|
||||||
|
If your target host depends on a **dynamic expression** (like using the machine’s evaluated FQDN), set it inside the NixOS module:
|
||||||
|
|
||||||
|
```{.nix title="flake.nix" hl_lines="8"}
|
||||||
|
{
|
||||||
|
# edlided
|
||||||
|
outputs =
|
||||||
|
{ self, clan-core, ... }:
|
||||||
|
let
|
||||||
|
clan = clan-core.lib.clan {
|
||||||
|
machines.jon = {config, ...}: {
|
||||||
|
clan.core.networking.targetHost = "jon@${config.networking.fqdn}";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit (clan.config) nixosConfigurations nixosModules clanInternals;
|
||||||
|
# elided
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Use this **only if the value cannot be made static**, because it’s slower and won't be displayed in the clan-cli or clan-app yet.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 📝 TL;DR
|
||||||
|
|
||||||
|
| Use Case | Use Inventory? | Example |
|
||||||
|
| ------------------------- | -------------- | -------------------------------- |
|
||||||
|
| Static hostname | ✅ Yes | `root@server.example.com` |
|
||||||
|
| Dynamic config expression | ❌ No | `jon@${config.networking.fqdn}` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 🚀 Coming Soon: Unified Networking Module
|
||||||
|
|
||||||
|
We’re working on a new networking module that will automatically do all of this for you.
|
||||||
|
|
||||||
|
- Easier to use
|
||||||
|
- Sane defaults: You’ll always be able to reach the machine — no need to worry about hostnames.
|
||||||
|
- ✨ Migration from **either method** will be supported and simple.
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
- Ask: *Does this hostname dynamically change based on NixOS config?*
|
||||||
|
- If **no**, use the inventory.
|
||||||
|
- If **yes**, then use NixOS config.
|
||||||
@@ -189,9 +189,10 @@ def get_host(
|
|||||||
host_str = inv_machine.get("deploy", {}).get(field)
|
host_str = inv_machine.get("deploy", {}).get(field)
|
||||||
|
|
||||||
if host_str is None:
|
if host_str is None:
|
||||||
machine.warn(
|
machine.info(
|
||||||
f"'{field}' is not set in `inventory.machines.${machine.name}.deploy.{field}` - falling back to _slower_ nixos option: `clan.core.networking.{field}`"
|
f"`inventory.machines.{machine.name}.deploy.{field}` is not set — falling back to `clan.core.networking.{field}`. See: https://docs.clan.lol/guides/target-host"
|
||||||
)
|
)
|
||||||
|
|
||||||
host_str = machine.select(f'config.clan.core.networking."{field}"')
|
host_str = machine.select(f'config.clan.core.networking."{field}"')
|
||||||
source = "machine"
|
source = "machine"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user