clan-core/docs/admins/08-flake-parts.md
Johannes Kirschbauer 960e560d84
All checks were successful
checks / check-links (pull_request) Successful in 14s
checks / checks-impure (pull_request) Successful in 1m49s
checks / checks (pull_request) Successful in 3m43s
docs: fix links
2024-04-10 13:37:54 +02:00

2.9 KiB

08 Clan with flake-parts

Clan supports integration with flake.parts a tool which allows modular compositions.

Here's how to set up Clan using flakes and flake-parts.

1. Update Your Flake Inputs

To begin, you'll need to add flake-parts as a new dependency in your flake's inputs. This is alongside the already existing dependencies, such as flake-parts and nixpkgs. Here's how you can update your flake.nix file:

# flake.nix
inputs = {
  nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";

  # New flake-parts input
  flake-parts.url = "github:hercules-ci/flake-parts";
  flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
  
  clan-core = {
    url = "git+https://git.clan.lol/clan/clan-core";
    inputs.nixpkgs.follows = "nixpkgs"; # Needed if your configuration uses nixpkgs unstable.
    # New
    inputs.flake-parts.follows = "flake-parts";
  };
}

2. Import Clan-Core Flake Module

After updating your flake inputs, the next step is to import the clan-core flake module. This will make the clan options available within mkFlake.

  outputs =
    inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } (
      {
        imports = [
          inputs.clan-core.flakeModules.default
        ];
      }
    );

3. Configure Clan Settings and Define Machines

Configure your clan settings and define machine configurations.

Below is a guide on how to structure this in your flake.nix:

  outputs =
    inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } (
      {
        imports = [
          inputs.clan-core.flakeModules.default
        ];
        clan = {
          ## Clan wide settings. (Required)
          clanName = "__CHANGE_ME__"; # Ensure to choose a unique name.
          directory = self; # Point this to the repository root.

          specialArgs = { }; # Add arguments to every nix import in here
          
          machines = {
            jons-desktop = {
              nixpkgs.hostPlatform = "x86_64-linux";
              imports = [
                clan-core.clanModules.sshd # Add openssh server for Clan management
                ./configuration.nix
              ];
            };
          };
        };
      }
    );

For detailed information about configuring flake-parts and the available options within Clan, refer to the Clan module documentation located here.

Next Steps

With your flake created, explore how to add new machines by reviewing the documentation provided here.


TODO

  • How do I use Clan machines install to setup my current machine?
  • I probably need the clan-core sshd module for that?
  • We need to tell them that configuration.nix of a machine NEEDS to be under the directory CLAN_ROOT/machines/ I think?