mirror of https://gitlab.crans.org/nounous/nixos
cleanup hosts-v2
parent
7ba95e86a4
commit
fefefa84ea
35
flake.nix
35
flake.nix
|
|
@ -26,12 +26,15 @@
|
|||
agenix,
|
||||
...
|
||||
}:
|
||||
let
|
||||
lib = nixpkgs.lib;
|
||||
in
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [ inputs.treefmt-nix.flakeModule ];
|
||||
|
||||
systems = [ "x86_64-linux" ];
|
||||
|
||||
flake = with nixpkgs.lib; {
|
||||
flake = with lib; {
|
||||
nixosConfigurations =
|
||||
let
|
||||
baseModules = [
|
||||
|
|
@ -40,35 +43,20 @@
|
|||
];
|
||||
get_hosts_names =
|
||||
path: attrNames (attrsets.filterAttrs (name: type: type == "directory") (readDir path));
|
||||
hostVM = get_hosts_names ./hosts/vm;
|
||||
hostPhysique = get_hosts_names ./hosts/physiques;
|
||||
get_info =
|
||||
path: lists:
|
||||
path:
|
||||
filter (x: x != null) (
|
||||
map (
|
||||
name:
|
||||
let
|
||||
filePath = path + "/${name}/info.nix";
|
||||
in
|
||||
if builtins.pathExists filePath then
|
||||
{
|
||||
crans = import filePath;
|
||||
}
|
||||
else
|
||||
warn "${toString filePath} not found" null
|
||||
) lists
|
||||
if builtins.pathExists filePath then import filePath else warn "${toString filePath} not found" null
|
||||
) (get_hosts_names path)
|
||||
);
|
||||
hosts_vm_info = get_info ./hosts/vm hostVM;
|
||||
hosts_physique_info = get_info ./hosts/physiques hostPhysique;
|
||||
|
||||
listInfoToAttrs =
|
||||
path: infos:
|
||||
listToAttrs (
|
||||
map (info: {
|
||||
name = info.crans.name;
|
||||
value = info;
|
||||
}) infos
|
||||
);
|
||||
infos: add: listToAttrs (map (info: lib.nameValuePair info.name (info // add)) infos);
|
||||
attrsToNixosSystem =
|
||||
path: all_hosts: hosts:
|
||||
mapAttrs (
|
||||
|
|
@ -79,16 +67,17 @@
|
|||
};
|
||||
modules = [
|
||||
(path + "/${name}")
|
||||
info
|
||||
({ ... }: { config.crans = info; })
|
||||
]
|
||||
++ baseModules;
|
||||
}
|
||||
) hosts;
|
||||
attrs_vm_info = listInfoToAttrs ./hosts/vm hosts_vm_info;
|
||||
attrs_physique_info = listInfoToAttrs ./hosts/physiques hosts_physique_info;
|
||||
attrs_vm_info = listInfoToAttrs (get_info ./hosts/vm) { isVm = true; };
|
||||
attrs_physique_info = listInfoToAttrs (get_info ./hosts/physiques) { isVm = false; };
|
||||
attrs_all_info = attrs_physique_info // attrs_vm_info;
|
||||
in
|
||||
(attrsToNixosSystem ./hosts/vm attrs_all_info attrs_vm_info)
|
||||
// (attrsToNixosSystem ./hosts/physiques attrs_all_info attrs_physique_info)
|
||||
// {
|
||||
cransIso = nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
|
|
|
|||
|
|
@ -3,12 +3,16 @@
|
|||
let
|
||||
cfg = config.crans;
|
||||
|
||||
inherit (lib) mkEnableOption mkIf;
|
||||
inherit (lib)
|
||||
mkEnableOption
|
||||
mkOption
|
||||
types
|
||||
mkIf
|
||||
;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./age.nix
|
||||
./extra.nix
|
||||
./grub.nix
|
||||
./home.nix
|
||||
./locale.nix
|
||||
|
|
@ -26,6 +30,38 @@ in
|
|||
|
||||
options.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 {
|
||||
|
|
|
|||
|
|
@ -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";
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Reference in New Issue