clan-core/docs/admins/quickstart.md

136 lines
4.6 KiB
Markdown
Raw Normal View History

2023-08-30 11:51:08 +00:00
# Initializing a New Clan Project
2023-10-27 15:36:06 +00:00
## Create a new flake
2023-08-30 11:51:08 +00:00
1. To start a new project, execute the following command to add the clan cli to your shell:
2023-08-30 11:51:08 +00:00
```shellSession
$ nix shell git+https://git.clan.lol/clan/clan-core
```
2. Then use the following commands to initialize a new clan-flake:
```shellSession
2024-04-03 07:43:24 +00:00
$ clan flakes create my-clan
2023-08-30 11:51:08 +00:00
```
This action will generate two primary files: `flake.nix` and `.clan-flake`.
```shellSession
2023-08-30 11:51:08 +00:00
$ ls -la
drwx------ joerg users 5 B a minute ago ./
drwxrwxrwt root root 139 B 12 seconds ago ../
.rw-r--r-- joerg users 77 B a minute ago .clan-flake
.rw-r--r-- joerg users 4.8 KB a minute ago flake.lock
.rw-r--r-- joerg users 242 B a minute ago flake.nix
```
### Understanding the .clan-flake Marker File
The `.clan-flake` marker file serves an optional purpose: it helps the `clan-cli` utility locate the project's root directory.
If `.clan-flake` is missing, `clan-cli` will instead search for other indicators like `.git`, `.hg`, `.svn`, or `flake.nix` to identify the project root.
2023-10-27 15:36:06 +00:00
## What's next
2023-10-27 15:36:06 +00:00
After creating your flake, you can check out how to add [new machines](./machines.md)
2023-08-30 11:51:08 +00:00
---
# Migrating Existing NixOS Configuration Flake
2023-08-30 13:25:20 +00:00
Absolutely, let's break down the migration step by step, explaining each action in detail:
#### 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
2023-08-30 13:25:20 +00:00
```
2. **Update Flake Inputs**: Add a new input for the `clan-core` dependency:
2023-08-30 13:25:20 +00:00
```nix
inputs.clan-core = {
url = "git+https://git.clan.lol/clan/clan-core";
2023-09-19 09:04:07 +00:00
# Don't do this if your machines are on nixpkgs stable.
2023-08-30 13:25:20 +00:00
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
2023-09-22 08:28:42 +00:00
{
nixosConfigurations.example-desktop = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
./configuration.nix
];
[...]
};
}
2023-08-30 13:25:20 +00:00
```
After change:
```nix
2023-09-22 08:28:42 +00:00
let clan = clan-core.lib.buildClan {
2023-09-19 09:04:07 +00:00
# this needs to point at the repository root
directory = self;
2023-08-30 14:47:05 +00:00
specialArgs = {};
clanName = "NEEDS_TO_BE_UNIQUE"; # TODO: Changeme
2023-08-30 13:25:20 +00:00
machines = {
example-desktop = {
nixpkgs.hostPlatform = "x86_64-linux";
imports = [
./configuration.nix
];
};
};
};
2023-09-27 17:01:51 +00:00
in { inherit (clan) nixosConfigurations clanInternals; }
2023-08-30 13:25:20 +00:00
```
- `nixosConfigurations`: Defines NixOS configurations, using Clan Cores `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`.
2023-09-22 08:28:42 +00:00
- `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
2023-08-30 13:25:20 +00:00
4. **Rebuild and Switch**: Rebuild your NixOS configuration using the updated flake:
```shellSession
$ sudo nixos-rebuild switch --flake .
2023-08-30 13:25:20 +00:00
```
- 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
2023-08-30 13:25:20 +00:00
```
2023-08-30 11:51:08 +00:00
2023-08-30 13:25:20 +00:00
7. **Verify**: After the reboot, confirm that your system is running with the new configuration, and all services and applications are functioning as expected.
2023-08-30 11:51:08 +00:00
2023-08-30 13:25:20 +00:00
By following these steps, you've successfully migrated your NixOS Flake configuration to include the `clan-core` input and adapted the `outputs` section to work with Clan Core's new machine provisioning method.
2023-10-27 15:36:06 +00:00
## What's next
After creating your flake, you can check out how to add [new machines](./machines.md)