From e4310e96c7827f8502f2f3d1c06885b67cdd38b4 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Thu, 28 Nov 2024 11:17:43 +0100 Subject: [PATCH 1/4] Templates: move all clan templates into subfolder 'clan' --- templates/{ => clan}/flake-parts/flake.nix | 0 .../flake-parts/machines/jon/configuration.nix | 0 .../machines/jon/hardware-configuration.nix | 0 .../flake-parts/machines/sara/configuration.nix | 0 .../machines/sara/hardware-configuration.nix | 0 templates/{ => clan}/flake-parts/modules/disko.nix | 0 templates/{ => clan}/flake-parts/modules/shared.nix | 0 .../machines/flash-installer/configuration.nix | 0 .../machines/flash-installer/disko.nix | 0 .../machines/new-machine/configuration.nix | 0 templates/{ => clan}/minimal-flake-parts/.gitignore | 0 templates/{ => clan}/minimal-flake-parts/checks.nix | 0 templates/{ => clan}/minimal-flake-parts/clan.nix | 0 templates/{ => clan}/minimal-flake-parts/devshells.nix | 0 templates/{ => clan}/minimal-flake-parts/flake.nix | 0 templates/{ => clan}/minimal-flake-parts/formatter.nix | 0 templates/{ => clan}/minimal/flake.nix | 0 templates/{ => clan}/minimal/inventory.json | 0 templates/{ => clan}/new-clan/.clan-flake | 0 templates/{ => clan}/new-clan/.envrc | 0 templates/{ => clan}/new-clan/flake.nix | 0 .../{ => clan}/new-clan/machines/jon/configuration.nix | 0 .../new-clan/machines/jon/hardware-configuration.nix | 0 .../new-clan/machines/sara/configuration.nix | 0 .../new-clan/machines/sara/hardware-configuration.nix | 0 templates/{ => clan}/new-clan/modules/disko.nix | 0 templates/{ => clan}/new-clan/modules/gnome.nix | 0 templates/{ => clan}/new-clan/modules/shared.nix | 0 templates/flake.nix | 10 +++++----- 29 files changed, 5 insertions(+), 5 deletions(-) rename templates/{ => clan}/flake-parts/flake.nix (100%) rename templates/{ => clan}/flake-parts/machines/jon/configuration.nix (100%) rename templates/{ => clan}/flake-parts/machines/jon/hardware-configuration.nix (100%) rename templates/{ => clan}/flake-parts/machines/sara/configuration.nix (100%) rename templates/{ => clan}/flake-parts/machines/sara/hardware-configuration.nix (100%) rename templates/{ => clan}/flake-parts/modules/disko.nix (100%) rename templates/{ => clan}/flake-parts/modules/shared.nix (100%) rename templates/{ => clan}/machineTemplates/machines/flash-installer/configuration.nix (100%) rename templates/{ => clan}/machineTemplates/machines/flash-installer/disko.nix (100%) rename templates/{ => clan}/machineTemplates/machines/new-machine/configuration.nix (100%) rename templates/{ => clan}/minimal-flake-parts/.gitignore (100%) rename templates/{ => clan}/minimal-flake-parts/checks.nix (100%) rename templates/{ => clan}/minimal-flake-parts/clan.nix (100%) rename templates/{ => clan}/minimal-flake-parts/devshells.nix (100%) rename templates/{ => clan}/minimal-flake-parts/flake.nix (100%) rename templates/{ => clan}/minimal-flake-parts/formatter.nix (100%) rename templates/{ => clan}/minimal/flake.nix (100%) rename templates/{ => clan}/minimal/inventory.json (100%) rename templates/{ => clan}/new-clan/.clan-flake (100%) rename templates/{ => clan}/new-clan/.envrc (100%) rename templates/{ => clan}/new-clan/flake.nix (100%) rename templates/{ => clan}/new-clan/machines/jon/configuration.nix (100%) rename templates/{ => clan}/new-clan/machines/jon/hardware-configuration.nix (100%) rename templates/{ => clan}/new-clan/machines/sara/configuration.nix (100%) rename templates/{ => clan}/new-clan/machines/sara/hardware-configuration.nix (100%) rename templates/{ => clan}/new-clan/modules/disko.nix (100%) rename templates/{ => clan}/new-clan/modules/gnome.nix (100%) rename templates/{ => clan}/new-clan/modules/shared.nix (100%) diff --git a/templates/flake-parts/flake.nix b/templates/clan/flake-parts/flake.nix similarity index 100% rename from templates/flake-parts/flake.nix rename to templates/clan/flake-parts/flake.nix diff --git a/templates/flake-parts/machines/jon/configuration.nix b/templates/clan/flake-parts/machines/jon/configuration.nix similarity index 100% rename from templates/flake-parts/machines/jon/configuration.nix rename to templates/clan/flake-parts/machines/jon/configuration.nix diff --git a/templates/flake-parts/machines/jon/hardware-configuration.nix b/templates/clan/flake-parts/machines/jon/hardware-configuration.nix similarity index 100% rename from templates/flake-parts/machines/jon/hardware-configuration.nix rename to templates/clan/flake-parts/machines/jon/hardware-configuration.nix diff --git a/templates/flake-parts/machines/sara/configuration.nix b/templates/clan/flake-parts/machines/sara/configuration.nix similarity index 100% rename from templates/flake-parts/machines/sara/configuration.nix rename to templates/clan/flake-parts/machines/sara/configuration.nix diff --git a/templates/flake-parts/machines/sara/hardware-configuration.nix b/templates/clan/flake-parts/machines/sara/hardware-configuration.nix similarity index 100% rename from templates/flake-parts/machines/sara/hardware-configuration.nix rename to templates/clan/flake-parts/machines/sara/hardware-configuration.nix diff --git a/templates/flake-parts/modules/disko.nix b/templates/clan/flake-parts/modules/disko.nix similarity index 100% rename from templates/flake-parts/modules/disko.nix rename to templates/clan/flake-parts/modules/disko.nix diff --git a/templates/flake-parts/modules/shared.nix b/templates/clan/flake-parts/modules/shared.nix similarity index 100% rename from templates/flake-parts/modules/shared.nix rename to templates/clan/flake-parts/modules/shared.nix diff --git a/templates/machineTemplates/machines/flash-installer/configuration.nix b/templates/clan/machineTemplates/machines/flash-installer/configuration.nix similarity index 100% rename from templates/machineTemplates/machines/flash-installer/configuration.nix rename to templates/clan/machineTemplates/machines/flash-installer/configuration.nix diff --git a/templates/machineTemplates/machines/flash-installer/disko.nix b/templates/clan/machineTemplates/machines/flash-installer/disko.nix similarity index 100% rename from templates/machineTemplates/machines/flash-installer/disko.nix rename to templates/clan/machineTemplates/machines/flash-installer/disko.nix diff --git a/templates/machineTemplates/machines/new-machine/configuration.nix b/templates/clan/machineTemplates/machines/new-machine/configuration.nix similarity index 100% rename from templates/machineTemplates/machines/new-machine/configuration.nix rename to templates/clan/machineTemplates/machines/new-machine/configuration.nix diff --git a/templates/minimal-flake-parts/.gitignore b/templates/clan/minimal-flake-parts/.gitignore similarity index 100% rename from templates/minimal-flake-parts/.gitignore rename to templates/clan/minimal-flake-parts/.gitignore diff --git a/templates/minimal-flake-parts/checks.nix b/templates/clan/minimal-flake-parts/checks.nix similarity index 100% rename from templates/minimal-flake-parts/checks.nix rename to templates/clan/minimal-flake-parts/checks.nix diff --git a/templates/minimal-flake-parts/clan.nix b/templates/clan/minimal-flake-parts/clan.nix similarity index 100% rename from templates/minimal-flake-parts/clan.nix rename to templates/clan/minimal-flake-parts/clan.nix diff --git a/templates/minimal-flake-parts/devshells.nix b/templates/clan/minimal-flake-parts/devshells.nix similarity index 100% rename from templates/minimal-flake-parts/devshells.nix rename to templates/clan/minimal-flake-parts/devshells.nix diff --git a/templates/minimal-flake-parts/flake.nix b/templates/clan/minimal-flake-parts/flake.nix similarity index 100% rename from templates/minimal-flake-parts/flake.nix rename to templates/clan/minimal-flake-parts/flake.nix diff --git a/templates/minimal-flake-parts/formatter.nix b/templates/clan/minimal-flake-parts/formatter.nix similarity index 100% rename from templates/minimal-flake-parts/formatter.nix rename to templates/clan/minimal-flake-parts/formatter.nix diff --git a/templates/minimal/flake.nix b/templates/clan/minimal/flake.nix similarity index 100% rename from templates/minimal/flake.nix rename to templates/clan/minimal/flake.nix diff --git a/templates/minimal/inventory.json b/templates/clan/minimal/inventory.json similarity index 100% rename from templates/minimal/inventory.json rename to templates/clan/minimal/inventory.json diff --git a/templates/new-clan/.clan-flake b/templates/clan/new-clan/.clan-flake similarity index 100% rename from templates/new-clan/.clan-flake rename to templates/clan/new-clan/.clan-flake diff --git a/templates/new-clan/.envrc b/templates/clan/new-clan/.envrc similarity index 100% rename from templates/new-clan/.envrc rename to templates/clan/new-clan/.envrc diff --git a/templates/new-clan/flake.nix b/templates/clan/new-clan/flake.nix similarity index 100% rename from templates/new-clan/flake.nix rename to templates/clan/new-clan/flake.nix diff --git a/templates/new-clan/machines/jon/configuration.nix b/templates/clan/new-clan/machines/jon/configuration.nix similarity index 100% rename from templates/new-clan/machines/jon/configuration.nix rename to templates/clan/new-clan/machines/jon/configuration.nix diff --git a/templates/new-clan/machines/jon/hardware-configuration.nix b/templates/clan/new-clan/machines/jon/hardware-configuration.nix similarity index 100% rename from templates/new-clan/machines/jon/hardware-configuration.nix rename to templates/clan/new-clan/machines/jon/hardware-configuration.nix diff --git a/templates/new-clan/machines/sara/configuration.nix b/templates/clan/new-clan/machines/sara/configuration.nix similarity index 100% rename from templates/new-clan/machines/sara/configuration.nix rename to templates/clan/new-clan/machines/sara/configuration.nix diff --git a/templates/new-clan/machines/sara/hardware-configuration.nix b/templates/clan/new-clan/machines/sara/hardware-configuration.nix similarity index 100% rename from templates/new-clan/machines/sara/hardware-configuration.nix rename to templates/clan/new-clan/machines/sara/hardware-configuration.nix diff --git a/templates/new-clan/modules/disko.nix b/templates/clan/new-clan/modules/disko.nix similarity index 100% rename from templates/new-clan/modules/disko.nix rename to templates/clan/new-clan/modules/disko.nix diff --git a/templates/new-clan/modules/gnome.nix b/templates/clan/new-clan/modules/gnome.nix similarity index 100% rename from templates/new-clan/modules/gnome.nix rename to templates/clan/new-clan/modules/gnome.nix diff --git a/templates/new-clan/modules/shared.nix b/templates/clan/new-clan/modules/shared.nix similarity index 100% rename from templates/new-clan/modules/shared.nix rename to templates/clan/new-clan/modules/shared.nix diff --git a/templates/flake.nix b/templates/flake.nix index aa89d5e9d..8be797338 100644 --- a/templates/flake.nix +++ b/templates/flake.nix @@ -5,23 +5,23 @@ templates = { default = { description = "Initialize a new clan flake"; - path = ./new-clan; + path = ./clan/new-clan; }; minimal = { description = "for clans managed via (G)UI"; - path = ./minimal; + path = ./clan/minimal; }; flake-parts = { description = "Flake-parts"; - path = ./flake-parts; + path = ./clan/flake-parts; }; minimal-flake-parts = { description = "Minimal flake-parts clan template"; - path = ./minimal-flake-parts; + path = ./clan/minimal-flake-parts; }; machineTemplates = { description = "Machine templates"; - path = ./machineTemplates; + path = ./clan/machineTemplates; }; }; }; From de475c6aadc9f081d98f65bcdaaead186c6432ca Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Thu, 28 Nov 2024 11:19:20 +0100 Subject: [PATCH 2/4] Templates: init disko single disk template file --- templates/disk/single-disk.nix | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 templates/disk/single-disk.nix diff --git a/templates/disk/single-disk.nix b/templates/disk/single-disk.nix new file mode 100644 index 000000000..bb3a11aa9 --- /dev/null +++ b/templates/disk/single-disk.nix @@ -0,0 +1,39 @@ +{ + disko.devices = { + disk = { + main = { + device = "{{mainDisk}}"; + type = "disk"; + content = { + type = "gpt"; + partitions = { + ESP = { + type = "EF00"; + size = "500M"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ "umask=0077" ]; + }; + }; + root = { + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + swap = { + size = "{{swapSize}}"; + content = { + type = "swap"; + }; + }; + }; + }; + }; + }; + }; +} From 3b7559e066ec66faa5ba6c2ba8b939a5332997dd Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Thu, 28 Nov 2024 11:44:44 +0100 Subject: [PATCH 3/4] CLI: use new template path --- pkgs/clan-cli/clan_cli/clan/create.py | 4 ++-- pkgs/clan-cli/clan_cli/dirs.py | 13 ++++++++++--- pkgs/clan-cli/clan_cli/machines/create.py | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/clan/create.py b/pkgs/clan-cli/clan_cli/clan/create.py index 698b36906..8d224474a 100644 --- a/pkgs/clan-cli/clan_cli/clan/create.py +++ b/pkgs/clan-cli/clan_cli/clan/create.py @@ -6,7 +6,7 @@ from pathlib import Path from clan_cli.api import API from clan_cli.cmd import CmdOut, run -from clan_cli.dirs import clan_templates +from clan_cli.dirs import TemplateType, clan_templates from clan_cli.errors import ClanError from clan_cli.inventory import Inventory, init_inventory from clan_cli.nix import nix_command, nix_shell @@ -38,7 +38,7 @@ def git_command(directory: Path, *args: str) -> list[str]: @API.register def create_clan(options: CreateOptions) -> CreateClanResponse: directory = Path(options.directory).resolve() - template_url = f"{clan_templates()}#{options.template}" + template_url = f"{clan_templates(TemplateType.CLAN)}#{options.template}" if not directory.exists(): directory.mkdir() else: diff --git a/pkgs/clan-cli/clan_cli/dirs.py b/pkgs/clan-cli/clan_cli/dirs.py index a39f64044..09b777727 100644 --- a/pkgs/clan-cli/clan_cli/dirs.py +++ b/pkgs/clan-cli/clan_cli/dirs.py @@ -2,6 +2,7 @@ import logging import os import sys import urllib +from enum import Enum from pathlib import Path from clan_cli.clan_uri import FlakeId @@ -45,11 +46,17 @@ def find_toplevel(top_level_files: list[str]) -> Path | None: return None -def clan_templates() -> Path: - template_path = module_root().parent.parent.parent / "templates" +class TemplateType(Enum): + CLAN = "clan" + + +def clan_templates(template_type: TemplateType) -> Path: + template_path = ( + module_root().parent.parent.parent / "templates" / template_type.value + ) if template_path.exists(): return template_path - template_path = module_root() / "templates" + template_path = module_root() / "templates" / template_type.value if not template_path.exists(): msg = f"BUG! clan core not found at {template_path}. This is an issue with packaging the cli" raise ClanError(msg) diff --git a/pkgs/clan-cli/clan_cli/machines/create.py b/pkgs/clan-cli/clan_cli/machines/create.py index fc73cac93..3c95d9fa3 100644 --- a/pkgs/clan-cli/clan_cli/machines/create.py +++ b/pkgs/clan-cli/clan_cli/machines/create.py @@ -11,7 +11,7 @@ from clan_cli.clan.create import git_command from clan_cli.clan_uri import FlakeId from clan_cli.cmd import Log, run from clan_cli.completions import add_dynamic_completer, complete_tags -from clan_cli.dirs import clan_templates, get_clan_flake_toplevel_or_env +from clan_cli.dirs import TemplateType, clan_templates, get_clan_flake_toplevel_or_env from clan_cli.errors import ClanError from clan_cli.inventory import Machine as InventoryMachine from clan_cli.inventory import ( @@ -56,7 +56,7 @@ def create_machine(opts: CreateOptions) -> None: raise ClanError(msg, description=description) if not opts.template_src: - opts.template_src = FlakeId(str(clan_templates())) + opts.template_src = FlakeId(str(clan_templates(TemplateType.CLAN))) if not opts.template_name: opts.template_name = "new-machine" From ffff5aa5ae2cae396188055d6ac4f7d45b269a67 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Thu, 28 Nov 2024 11:56:12 +0100 Subject: [PATCH 4/4] CLI/tests: use correct fixture paths --- pkgs/clan-cli/tests/fixtures_flakes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/clan-cli/tests/fixtures_flakes.py b/pkgs/clan-cli/tests/fixtures_flakes.py index 2e92f1006..b7e6f41a8 100644 --- a/pkgs/clan-cli/tests/fixtures_flakes.py +++ b/pkgs/clan-cli/tests/fixtures_flakes.py @@ -10,7 +10,7 @@ from pathlib import Path from typing import Any, NamedTuple import pytest -from clan_cli.dirs import nixpkgs_source +from clan_cli.dirs import TemplateType, clan_templates, nixpkgs_source from clan_cli.locked_open import locked_open from fixture_error import FixtureError from root import CLAN_CORE @@ -213,7 +213,7 @@ def minimal_flake_template() -> Iterator[ClanFlake]: mp.setenv("HOME", home) flake = ClanFlake( temporary_home=Path(home), - flake_template=CLAN_CORE / "templates" / "minimal", + flake_template=clan_templates(TemplateType.CLAN) / "minimal", ) flake.init_from_template() yield flake