diff --git a/README.md b/README.md index 4b86f9f..48bc191 100644 --- a/README.md +++ b/README.md @@ -67,23 +67,27 @@ nixos-infra/ │ ├── hosts/ # Configurations par machine │ ├── servers/ # Serveurs (hyperviseurs, VMs, LXCs) -│ │ ├── hyperv1/ # Hyperviseur 1 +│ │ ├── pve01/ # Hyperviseur 1 │ │ │ └── configuration.nix -│ │ ├── hyperv2/ # Hyperviseur 2 +│ │ ├── pve02/ # Hyperviseur 2 │ │ │ └── configuration.nix -│ │ ├── dns01/ # Conteneur LXC pour DNS +│ │ ├── dns01/ # Conteneur LXC pour DNS (master) +│ │ │ └── configuration.nix +│ │ ├── dns02/ # Conteneur LXC pour DNS (slave) │ │ │ └── configuration.nix │ │ ├── gitea01/ # Conteneur LXC pour Gitea │ │ │ └── configuration.nix -│ │ └── bitwarden/ # Conteneur LXC pour Bitwarden +│ │ └── vaultwarden/ # Conteneur LXC pour Vaultwarden +│ │ └── configuration.nix +│ │ └── rp01/ # Conteneur LXC reverse proxy │ │ └── configuration.nix │ │ │ └── workstations/ # Stations de travail -│ ├── dev-xavier/ # Station de Xavier +│ ├── sting/ # Station de Xavier (admin, dev, mao) │ │ └── configuration.nix -│ ├── mao-julien/ # Station MAO +│ ├── PC-FRIDA/ # Station de Frida (bureautique) │ │ └── configuration.nix -│ └── bureautique/ # Station bureautique +│ └── gaia/ # Portable de Xavier (MAO) │ └── configuration.nix │ ├── modules/ # Modules autonomes @@ -99,7 +103,9 @@ nixos-infra/ │ │ │ └── options.nix # Options exposées │ │ ├── gitea/ │ │ │ └── default.nix -│ │ ├── bitwarden/ +│ │ ├── password-manager/ +│ │ │ └── default.nix +│ │ ├── reverse-proxy/ │ │ │ └── default.nix │ │ └── ... │ │ @@ -112,8 +118,6 @@ nixos-infra/ ├── users/ # Utilisateurs concrets │ ├── root/ │ │ └── configuration.nix -│ ├── admin/ -│ │ └── configuration.nix │ ├── xavier/ │ │ └── configuration.nix │ ├── frida/ @@ -170,18 +174,18 @@ nixos-infra/ ### **1. Liste des Machines** -| Nom | Type de Machine | Services | IPv4 | Token IPv6 | -| ---------| --------------------| ----------------| ------| ------------| -| pve01 | Hyperviseur | Proxmox | | | -| pve02 | Hyperviseur | Proxmox | | | -| dns01 | Conteneur LXC | DNS | | | -| gitea01 | Conteneur LXC | Gitea | | | -| vault01 | Conteneur LXC | Vaultwarden | | | -| sting | Station de travail | Développement, | | | -| | | Bureautique, | | | -| | | MAO, | | | -| | | Administration | | | -| marley | Station de travail | Bureautique | | | +| Nom | Type de Machine | Services | IPv4 | Token IPv6 | +| ---------| --------------------| -------------| ------| ------------| +| pve01 | Hyperviseur | Proxmox | | | +| pve02 | Hyperviseur | Proxmox | | | +| dns01 | Conteneur LXC | DNS | | | +| gitea01 | Conteneur LXC | Gitea | | | +| vault01 | Conteneur LXC | Vaultwarden | | | +| sting | Station de travail | | | | +| | | | | | +| | | | | | +| | | | | | +| marley | Station de travail | | | | --- @@ -206,7 +210,6 @@ nixos-infra/ | --------| -----------------------| -----------| | root | Superutilisateur | ❌ | | xavier | Utilisateur principal | ✅ | -| | | | | frida | Utilisateur | ✅ | | guest | Invité | ❌ | @@ -328,6 +331,3 @@ nixos-infra/ --- -**Prochaine étape** : -Ce canvas peut être placé à la racine de votre dépôt sous le nom `README.md` ou dans un dossier `docs/`. -Souhaitez-vous que j'ajoute ou modifie des sections spécifiques (ex: détails sur un service, un exemple de module, ou un guide de déploiement pas à pas) ? \ No newline at end of file diff --git a/nixos-infra/hosts/servers/rp01/configuration.nix b/nixos-infra/hosts/servers/rp01/configuration.nix new file mode 100644 index 0000000..e5e3e38 --- /dev/null +++ b/nixos-infra/hosts/servers/rp01/configuration.nix @@ -0,0 +1,32 @@ +{ config, pkgs, lib, ... }: + +{ + imports = [ + # Module pour les conteneurs LXC + (builtins.callPackage ../../../modules/machine-types/lxc.nix {}) + # Module pour le reverse proxy + (builtins.callPackage ../../../modules/services/reverse-proxy/default.nix {}) + ]; + + # Configuration réseau (IPv4 + IPv6) + networking.hostName = "rp01"; + networking.interfaces.eth0.ipv4.addresses = [ + { address = "192.168.1.100"; prefixLength = 24; } + ]; + # networking.interfaces.eth0.ipv6.addresses = [ + # { address = "2001:db8::1"; prefixLength = 64; } + # ]; + + # Liste des services à exposer via le reverse proxy + services.reverse-proxy.publicServices = [ + { host = "gitea"; internalHost = "gitea01"; port = 3000; } + { host = "vaultwarden"; internalHost = "vault01"; port = 80; } + # Ajoutez ici d'autres services (ex: dns01, etc.) + ]; + + # Configuration spécifique à Caddy (optionnelle) + services.caddy = { + # Vous pouvez surcharger des paramètres ici si besoin + email = "xavier@lagraula.fr"; # Email pour Let's Encrypt + }; +} \ No newline at end of file diff --git a/nixos-infra/modules/machine-types/lxc.nix b/nixos-infra/modules/machine-types/lxc.nix index e69de29..5a5eac4 100644 --- a/nixos-infra/modules/machine-types/lxc.nix +++ b/nixos-infra/modules/machine-types/lxc.nix @@ -0,0 +1,65 @@ +{ config, modulesPath, pkgs, lib, ... }: +{ + imports = [ (modulesPath + "/virtualisation/proxmox-lxc.nix") ]; + nix.settings = { sandbox = false; }; + proxmoxLXC = { + manageNetwork = false; + privileged = true; + }; + + # Enable LXC specific options + options.lxc = { + enable = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Enable LXC machine type"; + }; + }; + + services.fstrim.enable = false; # Let Proxmox host handle fstrim + + # Cache DNS lookups to improve performance + services.resolved = { + extraConfig = '' + Cache=true + CacheFromLocalhost=true + ''; + }; + + # Prise en charge IPv6 + # TODO : check whether explicitly enabling IPv6 is still encessary in 2026 + networking.ipv6.forwarding = true; + + # Default configuration for a LXC container + config = lib.mkIf config.lxc.enable { + # Disabling useless services + services.avahi.daemon.enable = false; # TODO : review the need for avahi in a container + services.bluetooth.enable = false; + services.printing.enable = false; + + # Optimzing for conainters + boot.kernelModules = [ ]; # TODO : review the disabling of all kernelModules in a container + powerManagement.enable = false; + + # Enable SSH for deployment + # TODO : maybe move this to a module shared by all machines + services.openssh = { + enable = true; + openFirewall = true; + settings = { + PermitRootLogin = "yes"; + PasswordAuthentication = true; + # TODO : confirm that SSH//PermitEmptyPasswords is not actually needed. + # PermitEmptyPasswords = "yes"; + }; + }; + + # Limiter les ressources si nécessaire + # TODO : review the need to limit ZFS pools in the LXC container configuration, in my ZFSless context + boot.zfs.extraPools = [ ]; + + }; + + system.stateVersion = "25.11"; + +} diff --git a/nixos-infra/modules/services/reverse-proxy/default.nix b/nixos-infra/modules/services/reverse-proxy/default.nix new file mode 100644 index 0000000..2fe9cd6 --- /dev/null +++ b/nixos-infra/modules/services/reverse-proxy/default.nix @@ -0,0 +1,57 @@ +{ config, pkgs, lib, ... }: + +let + # Récupère la liste des services depuis la configuration + publicServices = config.services.reverse-proxy.publicServices or []; +in +{ + # Options pour le module reverse-proxy + options.services.reverse-proxy = { + publicServices = lib.mkOption { + type = lib.types.listOf (lib.types.submodule { + options = { + host = lib.mkOption { type = lib.types.str; }; + internalHost = lib.mkOption { type = lib.types.str; }; + port = lib.mkOption { type = lib.types.int; default = 80; }; + }; + }); + default = []; + description = "Liste des services à exposer via le reverse proxy"; + }; + }; + + # Configuration de Caddy + config = lib.mkIf (config.services.reverse-proxy.publicServices or []) != [] { + services.caddy = { + enable = true; + virtualHosts = map (service: { + host = "${service.host}.lagraula.fr"; + reverseProxy = "http://${service.internalHost}.lagraula.fr:${toString service.port}"; + # Challenge ACME HTTP-01 (par défaut) + tls = { + email = "xavier@lagraula.fr"; # À adapter + }; + }) (config.services.reverse-proxy.publicServices or []); + + # Configuration globale pour Caddy + extraConfig = '' + { + # Rate limiting global (optionnel) + rate_limit { + requests 100 + burst 200 + interval 1m + } + # Logging + log { + output file /var/log/caddy/access.log + } + } + ''; + }; + + # Ouvrir les ports firewall pour HTTP/HTTPS + networking.firewall.allowedTCPPorts = [ 80 443 ]; + networking.firewall.allowedUDPPorts = []; + }; +} \ No newline at end of file diff --git a/nixos-infra/scripts/deploy.sh b/nixos-infra/scripts/deploy.sh index e69de29..69d1717 100644 --- a/nixos-infra/scripts/deploy.sh +++ b/nixos-infra/scripts/deploy.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash +set -euo pipefail + +REPO_URL="https://gitea.lagraula.fr/xavier/nixos-infra.git" +REPO_DIR="/etc/nixos-infra" +BRANCH="main" +HOSTNAME=$(hostname) + +if [ "$(id -u)" -ne 0 ]; then + echo "Ce script doit être exécuté en tant que root." >&2 + exit 1 +fi + +# Cloner ou mettre à jour le dépôt +if [ -d "$REPO_DIR/.git" ]; then + echo "Mise à jour du dépôt dans $REPO_DIR..." + cd "$REPO_DIR" + git fetch origin + git checkout "$BRANCH" + git pull origin "$BRANCH" +else + echo "Clonage du dépôt dans $REPO_DIR..." + mkdir -p "$REPO_DIR" + git clone --branch "$BRANCH" "$REPO_URL" "$REPO_DIR" +fi + +# Trouver la configuration pour cette machine +CONFIG_PATH="$REPO_DIR/hosts/servers/$HOSTNAME/configuration.nix" +if [ ! -f "$CONFIG_PATH" ]; then + CONFIG_PATH="$REPO_DIR/hosts/workstations/$HOSTNAME/configuration.nix" +fi + +if [ ! -f "$CONFIG_PATH" ]; then + echo "Erreur : Aucune configuration trouvée pour $HOSTNAME dans $REPO_DIR" >&2 + exit 1 +fi + +# Appliquer la configuration +echo "Déploiement de la configuration pour $HOSTNAME..." +nixos-rebuild switch -I nixos-config="$CONFIG_PATH" + +echo "Déploiement terminé avec succès !" \ No newline at end of file diff --git a/nixos-infra/scripts/initial-configuration.nix b/nixos-infra/scripts/initial-configuration.nix index e69de29..29940b8 100644 --- a/nixos-infra/scripts/initial-configuration.nix +++ b/nixos-infra/scripts/initial-configuration.nix @@ -0,0 +1,29 @@ +{ config, pkgs, ... }: + +{ + # Activer SSH pour le déploiement + services.openssh = { + enable = true; + permitRootLogin = "yes"; + passwordAuthentication = true; + }; + + # Installer Git, curl, et les outils nécessaires + environment.systemPackages = with pkgs; [ git curl ]; + + # Ajouter le script de déploiement + system.activationScripts.setup-deploy = '' + #!${pkgs.bash}/bin/bash + set -euo pipefail + + # Télécharger le script de déploiement depuis Gitea + curl -o /usr/local/bin/deploy-nixos https://gitea.lagraula.fr/xavier/nixos-infra/raw/main/scripts/deploy.sh + chmod +x /usr/local/bin/deploy-nixos + + # Cloner le dépôt (si ce n'est pas déjà fait) + mkdir -p /etc/nixos-infra + if [ ! -d "/etc/nixos-infra/.git" ]; then + git clone https://gitea.lagraula.fr/xavier/nixos-infra.git /etc/nixos-infra + fi + ''; +} \ No newline at end of file