Cleanup templates

This commit is contained in:
pinpox
2025-06-26 11:41:08 +02:00
committed by Johannes Kirschbauer
parent 7ad7c3f859
commit 77d8f76eb8
22 changed files with 110 additions and 377 deletions

View File

@@ -93,7 +93,7 @@ def test_clan_core_templates(
] ]
clan_core_template_keys = list(clan_core_templates.keys()) clan_core_template_keys = list(clan_core_templates.keys())
expected_templates = ["default", "flake-parts", "minimal", "minimal-flake-parts"] expected_templates = ["classic", "default", "minimal"]
assert clan_core_template_keys == expected_templates assert clan_core_template_keys == expected_templates
vlist_temps = list_templates("clan", clan_dir) vlist_temps = list_templates("clan", clan_dir)
@@ -114,14 +114,13 @@ def test_clan_core_templates(
) )
assert (new_clan / "flake.nix").exists() assert (new_clan / "flake.nix").exists()
assert (new_clan / "machines").is_dir() assert (new_clan / "machines").is_dir()
assert (new_clan / "machines" / "jon").is_dir() # config_nix_p = new_clan / "machines" / "jon" / "configuration.nix"
config_nix_p = new_clan / "machines" / "jon" / "configuration.nix" # assert (config_nix_p).is_file()
assert (config_nix_p).is_file()
# Test if we can write to the configuration.nix file # Test if we can write to the configuration.nix file
with config_nix_p.open("r+") as f: # with config_nix_p.open("r+") as f:
data = f.read() # data = f.read()
f.write(data) # f.write(data)
# Test Case 1: Minimal input with empty templates # Test Case 1: Minimal input with empty templates

View File

@@ -0,0 +1,65 @@
{
inputs.clan-core.url = "https://git.clan.lol/clan/clan-core/archive/main.tar.gz";
inputs.nixpkgs.follows = "clan-core/nixpkgs";
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
inputs.flake-parts.inputs.nixpkgs-lib.follows = "clan-core/nixpkgs";
outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
imports = [ inputs.clan-core.flakeModules.default ];
# https://docs.clan.lol/guides/getting-started/flake-parts/
clan = {
# Ensure this is unique among all clans you want to use.
meta.name = "__CHANGE_ME__";
# Information about your machines. Machines under ./machines will be auto-imported.
inventory.machines = {
somemachine.tags = [ "desktop" ];
somemachine.deploy.targetHost = "root@somemachine";
};
# Clan services to use. See https://docs.clan.lol/reference/clanServices
inventory.instances = {
admin = {
module = {
name = "admin";
input = "clan";
};
roles.default.tags.all = { };
};
zerotier = {
module = {
name = "zerotier";
input = "clan";
};
roles.peer.tags.all = { };
};
};
# A mapping of machine names to their nixos configuration. Allows specifying
# additional configuration.
machines = {
somemachine =
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [ asciinema ];
};
};
};
perSystem =
{ pkgs, inputs', ... }:
{
devShells.default = pkgs.mkShell { packages = [ inputs'.clan-core.packages.clan-cli ]; };
};
};
}

View File

View File

@@ -1,108 +0,0 @@
{
inputs.clan-core.url = "https://git.clan.lol/clan/clan-core/archive/main.tar.gz";
inputs.nixpkgs.follows = "clan-core/nixpkgs";
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
inputs.flake-parts.inputs.nixpkgs-lib.follows = "clan-core/nixpkgs";
outputs =
inputs@{
self,
flake-parts,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
imports = [ inputs.clan-core.flakeModules.default ];
# https://docs.clan.lol/guides/getting-started/flake-parts/
clan = {
meta.name = "__CHANGE_ME__"; # Ensure this is unique among all clans you want to use.
inherit self;
machines = {
# "jon" will be the hostname of the machine
jon =
{ pkgs, ... }:
{
imports = [
./modules/shared.nix
./modules/disko.nix
./machines/jon/configuration.nix
];
nixpkgs.hostPlatform = "x86_64-linux";
# 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.core.networking.targetHost = pkgs.lib.mkDefault "root@jon";
# You can get your disk id by running the following command on the installer:
# Replace <IP> with the IP of the installer printed on the screen or by running the `ip addr` command.
# ssh root@<IP> lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
disko.devices.disk.main = {
device = "/dev/disk/by-id/__CHANGE_ME__";
};
# IMPORTANT! Add your SSH key here
# e.g. > cat ~/.ssh/id_ed25519.pub
users.users.root.openssh.authorizedKeys.keys = throw ''
Don't forget to add your SSH key here!
users.users.root.openssh.authorizedKeys.keys = [ "<YOUR SSH_KEY>" ]
'';
# Zerotier needs one controller to accept new nodes. Once accepted
# the controller can be offline and routing still works.
clan.core.networking.zerotier.controller.enable = true;
};
# "sara" will be the hostname of the machine
sara =
{ pkgs, ... }:
{
imports = [
./modules/shared.nix
./modules/disko.nix
./machines/sara/configuration.nix
];
nixpkgs.hostPlatform = "x86_64-linux";
# 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.core.networking.targetHost = pkgs.lib.mkDefault "root@sara";
# You can get your disk id by running the following command on the installer:
# Replace <IP> with the IP of the installer printed on the screen or by running the `ip addr` command.
# ssh root@<IP> lsblk --output NAME,ID-LINK,FSTYPE,SIZE,MOUNTPOINT
disko.devices.disk.main = {
device = "/dev/disk/by-id/__CHANGE_ME__";
};
# IMPORTANT! Add your SSH key here
# e.g. > cat ~/.ssh/id_ed25519.pub
users.users.root.openssh.authorizedKeys.keys = throw ''
Don't forget to add your SSH key here!
users.users.root.openssh.authorizedKeys.keys = [ "<YOUR SSH_KEY>" ]
'';
/*
After jon is deployed, uncomment the following line
This will allow sara to share the VPN overlay network with jon
The networkId is generated by the first deployment of jon
*/
# clan.core.networking.zerotier.networkId = builtins.readFile ../../vars/per-machine/jon/zerotier/zerotier-network-id/value;
};
};
};
perSystem =
{ pkgs, inputs', ... }:
{
devShells.default = pkgs.mkShell { packages = [ inputs'.clan-core.packages.clan-cli ]; };
};
};
}

View File

@@ -1,38 +0,0 @@
{ config, ... }:
let
username = config.networking.hostName;
in
{
imports = [ ./hardware-configuration.nix ];
# Locale service discovery and mDNS
services.avahi.enable = true;
services.xserver.enable = true;
services.xserver.desktopManager.gnome.enable = true;
services.xserver.displayManager.gdm.enable = true;
# Disable the default gnome apps to speed up deployment
services.gnome.core-utilities.enable = false;
# Enable automatic login for the user.
services.displayManager.autoLogin = {
enable = true;
user = username;
};
users.users.${username} = {
initialPassword = username;
isNormalUser = true;
extraGroups = [
"wheel"
"networkmanager"
"video"
"audio"
"input"
"dialout"
"disk"
];
uid = 1000;
openssh.authorizedKeys.keys = config.users.users.root.openssh.authorizedKeys.keys;
};
}

View File

@@ -1,39 +0,0 @@
{ config, ... }:
let
username = config.networking.hostName;
in
{
imports = [ ./hardware-configuration.nix ];
# Locale service discovery and mDNS
services.avahi.enable = true;
services.xserver.enable = true;
services.xserver.desktopManager.gnome.enable = true;
services.xserver.displayManager.gdm.enable = true;
# Disable the default gnome apps to speed up deployment
services.gnome.core-utilities.enable = false;
# Enable automatic login for the user.
services.displayManager.autoLogin = {
enable = true;
user = username;
};
users.users.${username} = {
initialPassword = username;
isNormalUser = true;
extraGroups = [
"wheel"
"networkmanager"
"video"
"audio"
"input"
"dialout"
"disk"
];
uid = 1000;
openssh.authorizedKeys.keys = config.users.users.root.openssh.authorizedKeys.keys;
};
}

View File

@@ -1,51 +0,0 @@
{ lib, clan-core, ... }:
let
suffix = config.clan.core.vars.generators.disk-id.files.diskId.value;
in
{
imports = [
clan-core.clanModules.disk-id
];
boot.loader.grub.efiSupport = lib.mkDefault true;
boot.loader.grub.efiInstallAsRemovable = lib.mkDefault true;
disko.devices = {
disk = {
"main" = {
# suffix is to prevent disk name collisions
name = "main-" + suffix;
type = "disk";
# Set the following in flake.nix for each maschine:
# device = <uuid>;
content = {
type = "gpt";
partitions = {
"boot" = {
size = "1M";
type = "EF02"; # for grub MBR
priority = 1;
};
"ESP" = {
size = "512M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
"root" = {
size = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
};
};
};
};
};
};
}

View File

@@ -1,14 +0,0 @@
{
clan-core,
# Optional, if you want to access other flakes:
# self,
...
}:
{
imports = [
clan-core.clanModules.sshd
clan-core.clanModules.root-password
# You can access other flakes imported in your flake via `self` like this:
# self.inputs.nix-index-database.nixosModules.nix-index
];
}

View File

@@ -1,22 +0,0 @@
{ self, ... }:
{
perSystem =
{
self',
lib,
system,
...
}:
{
checks =
let
nixosMachines = lib.mapAttrs' (
name: config: lib.nameValuePair "nixos-${name}" config.config.system.build.toplevel
) ((lib.filterAttrs (_: config: config.pkgs.system == system)) self.nixosConfigurations);
packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") self'.packages;
devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") self'.devShells;
in
nixosMachines // packages // devShells;
};
}

View File

@@ -1,13 +0,0 @@
{ self, inputs, ... }:
{
imports = [
inputs.clan.flakeModules.default
];
clan = {
meta.name = "__CHANGE_ME__";
inherit self;
specialArgs = {
inherit inputs;
};
};
}

View File

@@ -1,17 +0,0 @@
_: {
perSystem =
{
pkgs,
inputs',
...
}:
{
devShells = {
default = pkgs.mkShellNoCC {
packages = [
inputs'.clan.packages.default
];
};
};
};
}

View File

@@ -1,31 +0,0 @@
{
inputs = {
clan.url = "https://git.clan.lol/clan/clan-core/archive/main.tar.gz";
nixpkgs.follows = "clan/nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "clan/nixpkgs";
};
outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } (
{ ... }:
{
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
imports = [
./checks.nix
./clan.nix
./devshells.nix
./formatter.nix
];
}
);
}

View File

@@ -1,10 +0,0 @@
_: {
perSystem =
{
pkgs,
...
}:
{
formatter = pkgs.nixfmt;
};
}

View File

@@ -1,15 +1,36 @@
{ {
inputs.clan-core.url = "https://git.clan.lol/clan/clan-core/archive/main.tar.gz";
inputs.nixpkgs.follows = "clan-core/nixpkgs"; inputs = {
clan.url = "https://git.clan.lol/clan/clan-core/archive/main.tar.gz";
nixpkgs.follows = "clan/nixpkgs";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "clan/nixpkgs";
};
outputs = outputs =
{ self, clan-core, ... }: inputs@{ flake-parts, ... }:
let flake-parts.lib.mkFlake { inherit inputs; } (
# Usage see: https://docs.clan.lol { self, lib, ... }:
clan = clan-core.clanLib.buildClan { inherit self; }; {
in
{ imports = [
# all machines managed by Clan inputs.clan.flakeModules.default
inherit (clan) nixosConfigurations nixosModules clanInternals; ];
};
clan = {
inherit self;
specialArgs = { inherit inputs; };
# Ensure this is unique among all clans you want to use.
meta.name = lib.mkDefault "__CHANGE_ME__";
};
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
}
);
} }

View File

@@ -1,5 +0,0 @@
{
"meta": { "name": "__CHANGE_ME__" },
"machines": {},
"services": {}
}

View File

@@ -1,2 +0,0 @@
# DO NOT DELETE
# This file is used by the clan cli to discover a clan flake

View File

@@ -25,20 +25,18 @@
clan = { clan = {
default = { default = {
description = "Initialize a new clan flake"; description = "Initialize a new clan flake";
path = ./clan/new-clan; path = ./clan/default;
}; };
classic = {
description = "Initialize a new clan flake (no flake-parts)";
path = ./clan/classic;
};
minimal = { minimal = {
description = "for clans managed via (G)UI"; description = "for clans managed via (G)UI";
path = ./clan/minimal; path = ./clan/minimal;
}; };
flake-parts = {
description = "Flake-parts";
path = ./clan/flake-parts;
};
minimal-flake-parts = {
description = "Minimal flake-parts clan template";
path = ./clan/minimal-flake-parts;
};
}; };
}; };
}; };