4.2 KiB
Initializing a New Clan Project
Clone the Clan Template
- To start a new project, execute the following command to add the clan cli to your shell:
$ nix shell git+https://git.clan.lol/clan/clan-core
- Than use the following command to clone the clan core template into the current directory:
$ clan create .
This action will generate two primary files: flake.nix and .clan-flake.
$ 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.
Modifying the configuration
After cloning the template the next step is to modify the flake.nix and follow the instructions in it to add more machines.
Migrating Existing NixOS Configuration Flake
Absolutely, let's break down the migration step by step, explaining each action in detail:
Before You Begin
-
Backup Your Current Configuration: Always start by making a backup of your current NixOS configuration to ensure you can revert if needed.
cp -r /etc/nixos ~/nixos-backup -
Update Flake Inputs: The patch adds a new input named
clan-coreto yourflake.nix. This input points to a Git repository for Clan Core. Here's the addition: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 samenixpkgsinput as your main input (in this case, it followsnixpkgs).
-
Update Outputs: Then modify the
outputssection of yourflake.nixto adapt to Clan Core's new provisioning method. The key changes are as follows:Add
clan-coreto the output- outputs = { self, nixpkgs, }: + outputs = { self, nixpkgs, clan-core }:Previous configuration:
nixosConfigurations.example-desktop = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ ./configuration.nix ]; [...] };After change:
nixosConfigurations = clan-core.lib.buildClan { # this needs to point at the repository root directory = self; specialArgs = {}; machines = { example-desktop = { nixpkgs.hostPlatform = "x86_64-linux"; imports = [ ./configuration.nix ]; }; }; };nixosConfigurations: Defines NixOS configurations, using Clan Core’sbuildClanfunction to manage the machines.- Inside
machines, a new machine configuration is defined (in this case,example-desktop). - Inside
example-desktopwhich is the target machine hostname,nixpkgs.hostPlatformspecifies the host platform asx86_64-linux.
-
Rebuild and Switch: Rebuild your NixOS configuration using the updated flake:
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.
- This command rebuilds and switches to the new configuration. Make sure to include the
-
Test Configuration: Before rebooting, verify that your new configuration builds without errors or warnings.
-
Reboot: If everything is fine, you can reboot your system to apply the changes:
sudo reboot -
Verify: After the reboot, confirm that your system is running with the new configuration, and all services and applications are functioning as expected.
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.