templates: allow specifying from flake-parts module

This commit is contained in:
Michael Hoang
2025-02-13 15:09:17 +07:00
parent 09f650dab0
commit 742040cd03
6 changed files with 111 additions and 44 deletions

View File

@@ -43,10 +43,6 @@
meta.name = "clan-core"; meta.name = "clan-core";
}; };
flake = {
clan.templates = import ./templates { };
};
systems = import systems; systems = import systems;
imports = imports =
# only importing existing paths allows to minimize the flake for test # only importing existing paths allows to minimize the flake for test

View File

@@ -27,9 +27,13 @@ in
}; };
options.flake = flake-parts-lib.mkSubmoduleOptions { options.flake = flake-parts-lib.mkSubmoduleOptions {
clan = lib.mkOption { type = types.raw; };
clanInternals = lib.mkOption { type = types.raw; }; clanInternals = lib.mkOption { type = types.raw; };
}; };
config = { config = {
flake.clan = {
inherit (config.clan.clanInternals) templates;
};
flake.clanInternals = config.clan.clanInternals; flake.clanInternals = config.clan.clanInternals;
flake.nixosConfigurations = config.clan.nixosConfigurations; flake.nixosConfigurations = config.clan.nixosConfigurations;
}; };

View File

@@ -69,6 +69,15 @@ in
``` ```
''; '';
}; };
templates = lib.mkOption {
type = types.submodule { imports = [ ./templates/interface.nix ]; };
default = { };
description = ''
Define Clan templates.
'';
};
inventory = lib.mkOption { inventory = lib.mkOption {
type = types.submodule { imports = [ ../inventory/build-inventory/interface.nix ]; }; type = types.submodule { imports = [ ../inventory/build-inventory/interface.nix ]; };
description = '' description = ''
@@ -112,11 +121,11 @@ in
type = types.lazyAttrsOf types.raw; type = types.lazyAttrsOf types.raw;
default = { }; default = { };
}; };
# flake.clanInternals # flake.clanInternals
clanInternals = lib.mkOption { clanInternals = lib.mkOption {
# Hide from documentation. Exposes internals to the cli. # Hide from documentation. Exposes internals to the cli.
visible = false; visible = false;
# type = types.raw;
# ClanInternals # ClanInternals
type = types.submodule { type = types.submodule {
options = { options = {

View File

@@ -0,0 +1,57 @@
{
lib,
...
}:
let
inherit (lib) types;
templateType = types.submodule (
{ name, ... }:
{
options.description = lib.mkOption {
type = types.str;
default = name;
description = ''
The name of the template.
'';
};
options.path = lib.mkOption {
type = types.path;
description = ''
Holds the path to the clan template.
'';
};
}
);
in
{
options = {
# clan.templates.clan
clan = lib.mkOption {
type = types.attrsOf templateType;
default = { };
description = ''
Holds the different clan templates.
'';
};
# clan.templates.disko
disko = lib.mkOption {
type = types.attrsOf templateType;
default = { };
description = ''
Holds different disko templates.
'';
};
# clan.templates.machine
machine = lib.mkOption {
type = types.attrsOf templateType;
default = { };
description = ''
Holds the different machine templates.
'';
};
};
}

View File

@@ -1,39 +0,0 @@
{ ... }:
{
disko = {
single-disk = {
description = "A simple ext4 disk with a single partition";
path = ./disk/single-disk;
};
};
machine = {
flash-installer = {
description = "Initialize a new flash-installer machine";
path = ./clan/machineTemplates/machines/flash-installer;
};
new-machine = {
description = "Initialize a new machine";
path = ./clan/machineTemplates/machines/new-machine;
};
};
clan = {
default = {
description = "Initialize a new clan flake";
path = ./clan/new-clan;
};
minimal = {
description = "for clans managed via (G)UI";
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;
};
};
}

View File

@@ -1,5 +1,45 @@
{ self, inputs, ... }: { self, inputs, ... }:
{ {
clan.templates = {
disko = {
single-disk = {
description = "A simple ext4 disk with a single partition";
path = ./disk/single-disk;
};
};
machine = {
flash-installer = {
description = "Initialize a new flash-installer machine";
path = ./clan/machineTemplates/machines/flash-installer;
};
new-machine = {
description = "Initialize a new machine";
path = ./clan/machineTemplates/machines/new-machine;
};
};
clan = {
default = {
description = "Initialize a new clan flake";
path = ./clan/new-clan;
};
minimal = {
description = "for clans managed via (G)UI";
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;
};
};
};
flake = { flake = {
checks.x86_64-linux.template-minimal = checks.x86_64-linux.template-minimal =
let let