diff --git a/README.md b/README.md index ebb4b0a..a8203b0 100644 --- a/README.md +++ b/README.md @@ -71,3 +71,36 @@ commande : ```bash $ nix fmt ``` + +## Colmena + +Pour faciliter le redeploiement des machines, l'outils colmena est utilisé. +Pour cela, l'ensemble des machines doivent être écrite dans la `flake` au +format `colmena.`. Des tags peuvent être ajouté avec `deployment.tags` +afin redéployer un groupe de machines en même temps. + +Pour utiliser les commandes suivantes, il est nécessaire d'avoir colmena sur +son ordinateur. La commande `nix develop` s'en chargera. + +Remarque : + +> Si l'ensemble des fichiers du repertoire ne sont pas commit, alors colmena +> considérera que le répertoire est "impure". S'il est vraiment nécessaire +> d'appliquer la confifuration, il est possible de le faire à l'aide du flag +> `--impure`. + +### Build + +```bash +$ colmena build # Build toutes les machines +$ colmena build --on # Build uniquement la machine +$ colmena build --on @ # Build les machines possédant ce tag +``` + +### Apply + +```bash +$ colmena apply # Apply toutes les machines +$ colmena apply --on # Apply uniquement la machine +$ colmena apply --on @ # Apply les machines possédant ce tag +``` diff --git a/flake.nix b/flake.nix index 490228c..7142a29 100644 --- a/flake.nix +++ b/flake.nix @@ -34,78 +34,86 @@ }: flake-parts.lib.mkFlake { inherit inputs; } { imports = [ inputs.treefmt-nix.flakeModule ]; - systems = [ "x86_64-linux" ]; - flake = with nixpkgs.lib; { - colmena = { - meta = { - nixpkgs = import nixpkgs { - system = "x86_64-linux"; - overlays = [ ]; + flake = with nixpkgs.lib; + let + defaultConfig = [ + ./profiles/common + + agenix.nixosModules.default + disko.nixosModules.disko + ]; + defaultVM = [ + ./profiles/vm + ./disks/layout_vm.nix + ] + ++ defaultConfig; + machines = { + jitsi = { + domain = "pub.infra.auro.re"; + tags = [ "vm" ]; + config = [ ./hosts/vm/jitsi ] ++ defaultVM; }; - - }; - - jitsi = { - deployment = { - targetHost = "jitsi.pub.infra.auro.re"; - targetPort = 22; - targetUser = "root"; - tags = [ "services" ]; - }; - - imports = [ - ./profiles/common - agenix.nixosModules.default - disko.nixosModules.disko - ./profiles/vm - ./disks/layout_vm.nix - ./hosts/vm/jitsi - ]; - }; - }; - - nixosConfigurations = - let - defaultConfig = [ - ./profiles/common - - agenix.nixosModules.default - disko.nixosModules.disko - ]; - defaultVM = [ - ./profiles/vm - ./disks/layout_vm.nix - ] - ++ defaultConfig; - in - { - grafana = nixosSystem { - specialArgs = inputs; - modules = [ + grafana = { + domain = "ext.infra.auro.re"; + tags = [ "vm" ]; + config = [ ./hosts/vm/grafana - ] - ++ defaultVM; + ] ++ defaultVM; }; - log-2 = nixosSystem { - specialArgs = inputs; - modules = [ + log-2 = { + domain = "int.infra.auro.re"; + tags = [ "vm" "log" ]; + config = [ ./hosts/vm/log-2 ./disks/layout_vm_log.nix - ] - ++ defaultVM; - }; - # VL: Peut-être avoir de l'auto-discovery: On a beaucoup trop de machines - jitsi = nixosSystem { - specialArgs = inputs; - modules = [ - ./hosts/vm/jitsi - ] - ++ defaultVM; + ] ++ defaultVM; }; }; - }; + colmena_conf = builtins.mapAttrs + ( + name: conf: { + deployment = { + targetHost = "${name}.${conf.domain}"; + targetPort = 22; + targetUser = "root"; + tags = conf.tags; + }; + networking = { + hostName = name; + domain = conf.domain; + }; + imports = conf.config; + } + ) + machines; + nixos_conf = builtins.mapAttrs + ( + name: conf: nixosSystem { + specialArgs = inputs; + modules = [{ + networking = { + hostName = name; + domain = conf.domain; + }; + }] ++ conf.config; + } + ) + machines; + in + { + colmena = { + meta = { + nixpkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ ]; + }; + }; + } // colmena_conf; + + nixosConfigurations = nixos_conf; + }; perSystem = { config, pkgs, system, ... }: { @@ -116,13 +124,9 @@ # Formatter treefmt.config = { package = pkgs.treefmt; - programs = { - # *.nix - nixpkgs-fmt.enable = true; - - # *.md (and more) - prettier.enable = true; + nixpkgs-fmt.enable = true; # *.nix + prettier.enable = true; # *.md (and more) }; }; }; diff --git a/hosts/vm/grafana/default.nix b/hosts/vm/grafana/default.nix index 3672d7a..9d1b380 100644 --- a/hosts/vm/grafana/default.nix +++ b/hosts/vm/grafana/default.nix @@ -5,11 +5,6 @@ ./grafana.nix ]; - networking = { - hostName = "grafana"; - domain = "ext.infra.auro.re"; - }; - boot.loader.systemd-boot.enable = true; systemd.network = { diff --git a/hosts/vm/jitsi/default.nix b/hosts/vm/jitsi/default.nix index 8eff76b..8b7fb1a 100644 --- a/hosts/vm/jitsi/default.nix +++ b/hosts/vm/jitsi/default.nix @@ -5,11 +5,6 @@ ./jitsi.nix ]; - networking = { - hostName = "jitsi"; - domain = "pub.infra.auro.re"; - }; - boot.loader.systemd-boot.enable = true; systemd.network = { diff --git a/hosts/vm/log-2/default.nix b/hosts/vm/log-2/default.nix index 114891d..216ca2b 100644 --- a/hosts/vm/log-2/default.nix +++ b/hosts/vm/log-2/default.nix @@ -7,11 +7,6 @@ disko.devices.disk.logs.device = "/dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi1"; - networking = { - hostName = "log-2"; - domain = "int.infra.auro.re"; - }; - boot.loader.systemd-boot.enable = true; systemd.network = {