cleanup hosts-v2

hosts-v2
Pyjacpp 2026-09-06 14:47:13 +02:00
parent 7ba95e86a4
commit fefefa84ea
No known key found for this signature in database
GPG Key ID: ED479A5A26930939
3 changed files with 50 additions and 57 deletions

View File

@ -26,12 +26,15 @@
agenix, agenix,
... ...
}: }:
let
lib = nixpkgs.lib;
in
flake-parts.lib.mkFlake { inherit inputs; } { flake-parts.lib.mkFlake { inherit inputs; } {
imports = [ inputs.treefmt-nix.flakeModule ]; imports = [ inputs.treefmt-nix.flakeModule ];
systems = [ "x86_64-linux" ]; systems = [ "x86_64-linux" ];
flake = with nixpkgs.lib; { flake = with lib; {
nixosConfigurations = nixosConfigurations =
let let
baseModules = [ baseModules = [
@ -40,35 +43,20 @@
]; ];
get_hosts_names = get_hosts_names =
path: attrNames (attrsets.filterAttrs (name: type: type == "directory") (readDir path)); path: attrNames (attrsets.filterAttrs (name: type: type == "directory") (readDir path));
hostVM = get_hosts_names ./hosts/vm;
hostPhysique = get_hosts_names ./hosts/physiques;
get_info = get_info =
path: lists: path:
filter (x: x != null) ( filter (x: x != null) (
map ( map (
name: name:
let let
filePath = path + "/${name}/info.nix"; filePath = path + "/${name}/info.nix";
in in
if builtins.pathExists filePath then if builtins.pathExists filePath then import filePath else warn "${toString filePath} not found" null
{ ) (get_hosts_names path)
crans = import filePath;
}
else
warn "${toString filePath} not found" null
) lists
); );
hosts_vm_info = get_info ./hosts/vm hostVM;
hosts_physique_info = get_info ./hosts/physiques hostPhysique;
listInfoToAttrs = listInfoToAttrs =
path: infos: infos: add: listToAttrs (map (info: lib.nameValuePair info.name (info // add)) infos);
listToAttrs (
map (info: {
name = info.crans.name;
value = info;
}) infos
);
attrsToNixosSystem = attrsToNixosSystem =
path: all_hosts: hosts: path: all_hosts: hosts:
mapAttrs ( mapAttrs (
@ -79,16 +67,17 @@
}; };
modules = [ modules = [
(path + "/${name}") (path + "/${name}")
info ({ ... }: { config.crans = info; })
] ]
++ baseModules; ++ baseModules;
} }
) hosts; ) hosts;
attrs_vm_info = listInfoToAttrs ./hosts/vm hosts_vm_info; attrs_vm_info = listInfoToAttrs (get_info ./hosts/vm) { isVm = true; };
attrs_physique_info = listInfoToAttrs ./hosts/physiques hosts_physique_info; attrs_physique_info = listInfoToAttrs (get_info ./hosts/physiques) { isVm = false; };
attrs_all_info = attrs_physique_info // attrs_vm_info; attrs_all_info = attrs_physique_info // attrs_vm_info;
in in
(attrsToNixosSystem ./hosts/vm attrs_all_info attrs_vm_info) (attrsToNixosSystem ./hosts/vm attrs_all_info attrs_vm_info)
// (attrsToNixosSystem ./hosts/physiques attrs_all_info attrs_physique_info)
// { // {
cransIso = nixosSystem { cransIso = nixosSystem {
system = "x86_64-linux"; system = "x86_64-linux";

View File

@ -3,12 +3,16 @@
let let
cfg = config.crans; cfg = config.crans;
inherit (lib) mkEnableOption mkIf; inherit (lib)
mkEnableOption
mkOption
types
mkIf
;
in in
{ {
imports = [ imports = [
./age.nix ./age.nix
./extra.nix
./grub.nix ./grub.nix
./home.nix ./home.nix
./locale.nix ./locale.nix
@ -26,6 +30,38 @@ in
options.crans = { options.crans = {
enable = mkEnableOption "Configuration commune à toutes les machines du Crans"; enable = mkEnableOption "Configuration commune à toutes les machines du Crans";
name = mkOption {
type = types.str;
example = "vm-test";
description = "Nom de la machine";
};
isVm = mkOption {
type = types.bool;
description = "Est-ce une machine virtuelle ?";
};
description = mkOption {
type = types.str;
example = "VM de test";
description = "Description de la machine";
};
id = mkOption {
type = types.int;
example = 135;
description = ''
ID de la machine :
- < 100 machine physique
- >= 100 VM ( id de la VM dans proxmox )
'';
};
public-ssh = mkOption {
type = types.str;
description = "Clé ssh public de la machine";
};
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {

View File

@ -1,32 +0,0 @@
{ lib, ... }:
with lib;
{
options.crans = {
name = mkOption {
type = types.str;
example = "vm-test";
description = "Nom de la machine";
};
description = mkOption {
type = types.str;
example = "VM de test";
description = "Description de la machine";
};
id = mkOption {
type = types.int;
example = 135;
description = """
ID de la machine :
- < 100 machine physique
- >= 100 VM ( id de la VM dans proxmox )
""";
};
public-ssh = mkOption {
type = types.str;
description = "Clé ssh public de la machine";
};
};
}