2024-04-12 13:22:20 +00:00
# Deploy Machine
2023-10-27 15:36:06 +00:00
2024-04-13 09:41:00 +00:00
Integrating a new machine into your Clan environment is an easy yet flexible process, allowing for a straight forward management of multiple NixOS configurations.
2024-04-09 07:17:20 +00:00
2024-04-10 16:21:45 +00:00
We'll walk you through adding a new computer to your Clan.
2024-04-09 07:17:20 +00:00
## Installing a New Machine
2023-10-27 15:36:06 +00:00
Clan CLI, in conjunction with [nixos-anywhere ](https://github.com/nix-community/nixos-anywhere ), provides a seamless method for installing NixOS on various machines.
2024-04-10 16:21:45 +00:00
2023-10-27 15:36:06 +00:00
This process involves preparing a suitable hardware and disk partitioning configuration and ensuring the target machine is accessible via SSH.
2024-04-09 07:17:20 +00:00
### Step 0. Prerequisites
2024-04-13 11:59:48 +00:00
=== "**Physical Hardware**"
2024-04-13 15:46:07 +00:00
- [x] **Two Computers** : You need one computer that you're getting ready (we'll call this the Target Computer) and another one to set it up from (we'll call this the Setup Computer). Make sure both can talk to each other over the network using SSH.
- [x] **Machine configuration** : See our basic [configuration guide ](./configure.md )
- [x] **Initialized secrets** : See [secrets ](secrets.md ) for how to initialize your secrets.
- [x] **USB Flash Drive** : See [Clan Installer ](installer.md )
2024-04-13 12:44:33 +00:00
!!! Steps
2024-05-14 14:13:50 +00:00
2024-04-13 11:59:48 +00:00
1. Create a NixOS installer image and transfer it to a bootable USB drive as described in the [installer ](./installer.md ).
2024-05-14 14:13:50 +00:00
2024-04-13 11:59:48 +00:00
2. Boot the target machine and connect it to a network that makes it reachable from your setup computer.
2024-04-09 07:17:20 +00:00
2024-05-10 13:39:46 +00:00
=== "**Remote Machines**"
2024-04-13 11:59:48 +00:00
2024-04-13 15:46:07 +00:00
- [x] **Two Computers** : You need one computer that you're getting ready (we'll call this the Target Computer) and another one to set it up from (we'll call this the Setup Computer). Make sure both can talk to each other over the network using SSH.
- [x] **Machine configuration** : See our basic [configuration guide ](./configure.md )
- [x] **Initialized secrets** : See [secrets ](secrets.md ) for how to initialize your secrets.
2024-04-13 12:44:33 +00:00
!!! Steps
2024-04-13 11:59:48 +00:00
2024-04-13 15:46:07 +00:00
- Any cloud machine if it is reachable via SSH and supports `kexec` .
2024-04-09 07:17:20 +00:00
2024-04-10 09:11:22 +00:00
2024-04-13 15:46:07 +00:00
### Step 1. Deploy the machine
2024-04-10 09:11:22 +00:00
2024-04-10 12:54:41 +00:00
**Finally deployment time!** Use the following command to build and deploy the image via SSH onto your machine.
2024-04-10 09:11:22 +00:00
2024-04-23 15:15:07 +00:00
=== "**Image Installer**"
This method makes use of the image installers of [nixos-images ](https://github.com/nix-community/nixos-images ).
See how to prepare the installer for use [here ](./installer.md ).
The installer will randomly generate a password and local addresses on boot, then run ssh with these preconfigured.
The installer shows it's deployment relevant information in two formats, a text form, as well as a QR code.
2024-05-12 17:31:47 +00:00
This is an example of the booted installer.
2024-05-24 10:37:27 +00:00
```{ .bash .annotate .no-copy .nohighlight}
2024-05-12 17:31:47 +00:00
┌─────────────────────────────────────────────────────────────────────────────────────┐
│ ┌───────────────────────────┐ │
│ │███████████████████████████│ # This is the QR Code (1) │
│ │██ ▄▄▄▄▄ █▀▄█▀█▀▄█ ▄▄▄▄▄ ██│ │
│ │██ █ █ █▀▄▄▄█ ▀█ █ █ ██│ │
│ │██ █▄▄▄█ █▀▄ ▀▄▄▄█ █▄▄▄█ ██│ │
│ │██▄▄▄▄▄▄▄█▄▀ ▀▄▀▄█▄▄▄▄▄▄▄██│ │
│ │███▀▀▀ █▄▄█ ▀▄ ▄▀▄█ ███│ │
│ │██▄██▄▄█▄▄▀▀██▄▀ ▄▄▄ ▄▀█▀██│ │
│ │██ ▄▄▄▄▄ █▄▄▄▄ █ █▄█ █▀ ███│ │
│ │██ █ █ █ █ █ ▄▄▄ ▄▀▀ ██│ │
│ │██ █▄▄▄█ █ ▄ ▄ ▄ ▀█ ▄███│ │
│ │██▄▄▄▄▄▄▄█▄▄▄▄▄▄█▄▄▄▄▄█▄███│ │
│ │███████████████████████████│ │
│ └───────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────────────────────────────────┐ │
│ │Root password: cheesy-capital-unwell # password (2) │ │
│ │Local network addresses: │ │
│ │enp1s0 UP 192.168.178.169/24 metric 1024 fe80::21e:6ff:fe45:3c92/64 │ │
│ │enp2s0 DOWN │ │
│ │wlan0 DOWN # connect to wlan (3) │ │
│ │Onion address: 6evxy5yhzytwpnhc2vpscrbti3iktxdhpnf6yim6bbs25p4v6beemzyd.onion │ │
│ │Multicast DNS: nixos-installer.local │ │
│ └─────────────────────────────────────────────────────────────────────────────────┘ │
│ Press 'Ctrl-C' for console access │
│ │
└─────────────────────────────────────────────────────────────────────────────────────┘
```
1. This is not an actual QR code, because it is displayed rather poorly on text sites.
This would be the actual content of this specific QR code prettified:
```json
{
"pass": "cheesy-capital-unwell",
"tor": "6evxy5yhzytwpnhc2vpscrbti3iktxdhpnf6yim6bbs25p4v6beemzyd.onion",
"addrs": [
"2001:9e8:347:ca00:21e:6ff:fe45:3c92"
]
}
```
2024-05-12 21:09:08 +00:00
2024-05-12 17:31:47 +00:00
To generate the actual QR code, that would be displayed use:
```shellSession
echo '{"pass":"cheesy-capital-unwell","tor":"6evxy5yhzytwpnhc2vpscrbti3iktxdhpnf6yim6bbs25p4v6beemzyd.onion","addrs":["2001:9e8:347:ca00:21e:6ff:fe45:3c92"]}' | nix run nixpkgs#qrencode -- -s 2 -m 2 -t utf8
2024-04-23 15:15:07 +00:00
```
2024-05-12 17:31:47 +00:00
2. The root password for the installer medium.
This password is autogenerated and meant to be easily typeable.
3. See how to connect the installer medium to wlan [here ](./installer.md#optional-connect-to-wifi ).
4. :man_raising_hand: I'm a code annotation! I can contain `code` , __formatted
text__, images, ... basically anything that can be written in Markdown.
2024-04-10 09:11:22 +00:00
2024-04-23 15:15:07 +00:00
!!!tip
2024-05-10 20:59:45 +00:00
For easy sharing of deployment information via QR code, we highly recommend using [KDE Connect ](https://apps.kde.org/de/kdeconnect/ ).
2024-04-23 15:15:07 +00:00
2024-05-10 20:59:45 +00:00
There are two ways to deploy your machine:
2024-04-23 15:15:07 +00:00
2024-05-10 20:59:45 +00:00
1. **SSH with Password Authentication**
Run the following command to install using SSH:
```bash
clan machines install [MACHINE] flash-installer.local
```
2. **Scanning a QR Code for Installation Details**
You can input the information by following one of these methods:
- **Using a JSON String or File Path:**
Provide the path to a JSON string or input the string directly:
```terminal
clan machines install [MACHINE] --json [JSON]
```
- **Using an Image Containing the QR Code:**
Provide the path to an image file containing the relevant QR code:
```terminal
clan machines install [MACHINE] --png [PATH]
```
=== "**SSH access**"
Replace `<target_host>` with the **target computers' ip address** :
```bash
clan machines install [MACHINE] < target_host >
2024-04-23 15:15:07 +00:00
```
2023-10-27 15:36:06 +00:00
2024-05-10 20:59:45 +00:00
2024-05-12 22:09:24 +00:00
If you are using our template `[MACHINE]` would be `jon`
2024-04-10 09:11:22 +00:00
2024-04-13 12:53:09 +00:00
2024-05-12 22:09:24 +00:00
!!! success
2024-04-13 12:53:09 +00:00
Your machine is all set up. 🎉 🚀
2024-04-09 07:17:20 +00:00
2023-10-27 15:36:06 +00:00
## Update Your Machines
2024-02-02 04:32:48 +00:00
Clan CLI enables you to remotely update your machines over SSH. This requires setting up a target address for each target machine.
2023-10-27 15:36:06 +00:00
2024-02-02 04:32:48 +00:00
### Setting the Target Host
2023-10-27 15:36:06 +00:00
2024-05-12 22:09:24 +00:00
Replace `root@jon` with the actual hostname or IP address of your target machine:
2024-05-24 10:37:27 +00:00
```{.nix hl_lines="9" .no-copy}
2024-05-12 22:09:24 +00:00
buildClan {
# ...
machines = {
# "jon" will be the hostname of the machine
"jon" = {
# Set this for clan commands use ssh i.e. `clan machines update`
# If you change the hostname, you need to update this line to root@< new-hostname >
# This only works however if you have avahi running on your admin machine else use IP
clan.networking.targetHost = pkgs.lib.mkDefault "root@jon";
};
};
};
2023-10-27 15:36:06 +00:00
```
2024-05-12 22:09:24 +00:00
2024-04-16 10:28:32 +00:00
!!! warning
The use of `root@` in the target address implies SSH access as the `root` user.
Ensure that the root login is secured and only used when necessary.
2023-10-27 15:36:06 +00:00
2024-02-06 16:44:13 +00:00
### Updating Machine Configurations
Execute the following command to update the specified machine:
2024-04-07 12:32:23 +00:00
```bash
2024-05-12 22:09:24 +00:00
clan machines update jon
2024-02-06 16:44:13 +00:00
```
You can also update all configured machines simultaneously by omitting the machine name:
2024-04-07 12:32:23 +00:00
```bash
clan machines update
2024-02-06 16:44:13 +00:00
```
### Setting a Build Host
2024-02-06 16:26:32 +00:00
If the machine does not have enough resources to run the NixOS evaluation or build itself,
it is also possible to specify a build host instead.
During an update, the cli will ssh into the build host and run `nixos-rebuild` from there.
2024-05-14 14:13:50 +00:00
2024-05-24 10:37:27 +00:00
```{.nix hl_lines="5" .no-copy}
2024-05-14 14:13:50 +00:00
buildClan {
# ...
machines = {
"jon" = {
clan.networking.buildHost = "root@< host_or_ip > ";
};
};
};
2024-02-06 16:26:32 +00:00
```
2024-02-06 16:44:13 +00:00
### Excluding a machine from `clan machine update`
2023-10-27 15:36:06 +00:00
2024-04-13 09:41:00 +00:00
To exclude machines from being updated when running `clan machines update` without any machines specified,
2024-02-06 16:44:13 +00:00
one can set the `clan.deployment.requireExplicitUpdate` option to true:
2023-10-27 15:36:06 +00:00
2024-05-24 10:37:27 +00:00
```{.nix hl_lines="5" .no-copy}
2024-05-14 14:13:50 +00:00
buildClan {
# ...
machines = {
"jon" = {
clan.deployment.requireExplicitUpdate = true;
};
};
};
2023-10-27 15:36:06 +00:00
```
2024-02-06 16:44:13 +00:00
This is useful for machines that are not always online or are not part of the regular update cycle.
2024-04-07 12:32:23 +00:00
---
2024-05-10 20:59:45 +00:00
## What's next ?
2024-05-12 22:09:24 +00:00
- [**Mesh VPN** ](./mesh-vpn.md ): Configuring a secure mesh network.
2024-05-10 20:59:45 +00:00
---