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:
flake.nix
{
# edlided
outputs =
{ self, clan-core, ... }:
let
# Sometimes this attribute set is defined in clan.nix
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:
flake.nix
{
# edlided
outputs =
{ self, clan-core, ... }:
let
# Sometimes this attribute set is defined in clan.nix
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.