Clan: Difference between revisions
first version with initial description, link and categories |
I added a migration guide |
||
Line 1: | Line 1: | ||
[https://clan.lol/ Clan] is a peer-to-peer computer management framework for NixOS. It is possible to just start the custom NixOS installer on a device and integrate unconfigured systems via barcode scan into the managed systems. | [https://clan.lol/ Clan] is a peer-to-peer computer management framework for NixOS. It is possible to just start the custom NixOS installer on a device and integrate unconfigured systems via barcode scan into the managed systems. | ||
== Migrating Existing NixOS Configuration Flake == | |||
This guide will help you move your existing Nix configurations into Clan. Keep in mind, though, this approach can be trickier and might lead to bugs or unexpected issues. We recommend following the [https://docs.clan.lol/getting-started/) Getting Started guide] first. Once you have a working setup, you can easily transfer your Nix configurations over. | |||
<nowiki>####</nowiki> Before You Begin | |||
1. **Backup Your Current Configuration**: Always start by making a backup of your current NixOS configuration to ensure you can revert if needed. | |||
```shellSession | |||
$ cp -r /etc/nixos ~/nixos-backup | |||
``` | |||
2. **Update Flake Inputs**: Add a new input for the `clan-core` dependency: | |||
```nix | |||
inputs.clan-core = { | |||
url = "git+<nowiki>https://git.clan.lol/clan/clan-core</nowiki>"; | |||
# Don't do this if your machines are on nixpkgs stable. | |||
inputs.nixpkgs.follows = "nixpkgs"; | |||
}; | |||
``` | |||
- `url`: Specifies the Git repository URL for Clan Core. | |||
- `inputs.nixpkgs.follows`: Tells Nix to use the same `nixpkgs` input as your main input (in this case, it follows `nixpkgs`). | |||
3. **Update Outputs**: Then modify the `outputs` section of your `flake.nix` to adapt to Clan Core's new provisioning method. The key changes are as follows: | |||
Add `clan-core` to the output | |||
```diff | |||
- outputs = { self, nixpkgs, }: | |||
+ outputs = { self, nixpkgs, clan-core }: | |||
``` | |||
Previous configuration: | |||
```nix | |||
{ | |||
nixosConfigurations.example-desktop = nixpkgs.lib.nixosSystem { | |||
system = "x86_64-linux"; | |||
modules = [ | |||
./configuration.nix | |||
]; | |||
[...] | |||
}; | |||
} | |||
``` | |||
After change: | |||
```nix | |||
let clan = clan-core.lib.buildClan { | |||
# this needs to point at the repository root | |||
directory = self; | |||
specialArgs = {}; | |||
clanName = "NEEDS_TO_BE_UNIQUE"; # TODO: Changeme | |||
machines = { | |||
example-desktop = { | |||
nixpkgs.hostPlatform = "x86_64-linux"; | |||
imports = [ | |||
./configuration.nix | |||
]; | |||
}; | |||
}; | |||
}; | |||
in { inherit (clan) nixosConfigurations clanInternals; } | |||
``` | |||
- `nixosConfigurations`: Defines NixOS configurations, using Clan Core’s `buildClan` function to manage the machines. | |||
- Inside `machines`, a new machine configuration is defined (in this case, `example-desktop`). | |||
- Inside `example-desktop` which is the target machine hostname, `nixpkgs.hostPlatform` specifies the host platform as `x86_64-linux`. | |||
- `clanInternals`: Is required to enable evaluation of the secret generation/upload script on every architecture | |||
- `clanName`: Is required and needs to be globally unique, as else we have a cLAN name clash | |||
4. **Rebuild and Switch**: Rebuild your NixOS configuration using the updated flake: | |||
```shellSession | |||
$ sudo nixos-rebuild switch --flake . | |||
``` | |||
- This command rebuilds and switches to the new configuration. Make sure to include the `--flake .` argument to use the current directory as the flake source. | |||
5. **Test Configuration**: Before rebooting, verify that your new configuration builds without errors or warnings. | |||
6. **Reboot**: If everything is fine, you can reboot your system to apply the changes: | |||
```shellSession | |||
$ sudo reboot | |||
``` | |||
7. **Verify**: After the reboot, confirm that your system is running with the new configuration, and all services and applications are functioning as expected. | |||
Revision as of 18:21, 8 January 2025
Clan is a peer-to-peer computer management framework for NixOS. It is possible to just start the custom NixOS installer on a device and integrate unconfigured systems via barcode scan into the managed systems.
Migrating Existing NixOS Configuration Flake
This guide will help you move your existing Nix configurations into Clan. Keep in mind, though, this approach can be trickier and might lead to bugs or unexpected issues. We recommend following the Getting Started guide first. Once you have a working setup, you can easily transfer your Nix configurations over.
#### Before You Begin
1. **Backup Your Current Configuration**: Always start by making a backup of your current NixOS configuration to ensure you can revert if needed.
```shellSession
$ cp -r /etc/nixos ~/nixos-backup
```
2. **Update Flake Inputs**: Add a new input for the `clan-core` dependency:
```nix
inputs.clan-core = {
url = "git+https://git.clan.lol/clan/clan-core";
# Don't do this if your machines are on nixpkgs stable.
inputs.nixpkgs.follows = "nixpkgs";
};
```
- `url`: Specifies the Git repository URL for Clan Core.
- `inputs.nixpkgs.follows`: Tells Nix to use the same `nixpkgs` input as your main input (in this case, it follows `nixpkgs`).
3. **Update Outputs**: Then modify the `outputs` section of your `flake.nix` to adapt to Clan Core's new provisioning method. The key changes are as follows:
Add `clan-core` to the output
```diff
- outputs = { self, nixpkgs, }:
+ outputs = { self, nixpkgs, clan-core }:
```
Previous configuration:
```nix
{
nixosConfigurations.example-desktop = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
];
[...]
};
}
```
After change:
```nix
let clan = clan-core.lib.buildClan {
# this needs to point at the repository root
directory = self;
specialArgs = {};
clanName = "NEEDS_TO_BE_UNIQUE"; # TODO: Changeme
machines = {
example-desktop = {
nixpkgs.hostPlatform = "x86_64-linux";
imports = [
./configuration.nix
];
};
};
};
in { inherit (clan) nixosConfigurations clanInternals; }
```
- `nixosConfigurations`: Defines NixOS configurations, using Clan Core’s `buildClan` function to manage the machines.
- Inside `machines`, a new machine configuration is defined (in this case, `example-desktop`).
- Inside `example-desktop` which is the target machine hostname, `nixpkgs.hostPlatform` specifies the host platform as `x86_64-linux`.
- `clanInternals`: Is required to enable evaluation of the secret generation/upload script on every architecture
- `clanName`: Is required and needs to be globally unique, as else we have a cLAN name clash
4. **Rebuild and Switch**: Rebuild your NixOS configuration using the updated flake:
```shellSession
$ sudo nixos-rebuild switch --flake .
```
- This command rebuilds and switches to the new configuration. Make sure to include the `--flake .` argument to use the current directory as the flake source.
5. **Test Configuration**: Before rebooting, verify that your new configuration builds without errors or warnings.
6. **Reboot**: If everything is fine, you can reboot your system to apply the changes:
```shellSession
$ sudo reboot
```
7. **Verify**: After the reboot, confirm that your system is running with the new configuration, and all services and applications are functioning as expected.