Draft of nix files for a reverse proxy and of deployment scripts. Not tested, not functional.

This commit is contained in:
2026-04-29 20:15:30 +02:00
parent 10399460f4
commit c1864fdb9c
6 changed files with 251 additions and 26 deletions
+20 -20
View File
@@ -67,23 +67,27 @@ nixos-infra/
├── hosts/ # Configurations par machine ├── hosts/ # Configurations par machine
│ ├── servers/ # Serveurs (hyperviseurs, VMs, LXCs) │ ├── servers/ # Serveurs (hyperviseurs, VMs, LXCs)
│ │ ├── hyperv1/ # Hyperviseur 1 │ │ ├── pve01/ # Hyperviseur 1
│ │ │ └── configuration.nix │ │ │ └── configuration.nix
│ │ ├── hyperv2/ # Hyperviseur 2 │ │ ├── pve02/ # Hyperviseur 2
│ │ │ └── configuration.nix │ │ │ └── configuration.nix
│ │ ├── dns01/ # Conteneur LXC pour DNS │ │ ├── dns01/ # Conteneur LXC pour DNS (master)
│ │ │ └── configuration.nix
│ │ ├── dns02/ # Conteneur LXC pour DNS (slave)
│ │ │ └── configuration.nix │ │ │ └── configuration.nix
│ │ ├── gitea01/ # Conteneur LXC pour Gitea │ │ ├── gitea01/ # Conteneur LXC pour Gitea
│ │ │ └── configuration.nix │ │ │ └── configuration.nix
│ │ └── bitwarden/ # Conteneur LXC pour Bitwarden │ │ └── vaultwarden/ # Conteneur LXC pour Vaultwarden
│ │ └── configuration.nix
│ │ └── rp01/ # Conteneur LXC reverse proxy
│ │ └── configuration.nix │ │ └── configuration.nix
│ │ │ │
│ └── workstations/ # Stations de travail │ └── workstations/ # Stations de travail
│ ├── dev-xavier/ # Station de Xavier │ ├── sting/ # Station de Xavier (admin, dev, mao)
│ │ └── configuration.nix │ │ └── configuration.nix
│ ├── mao-julien/ # Station MAO │ ├── PC-FRIDA/ # Station de Frida (bureautique)
│ │ └── configuration.nix │ │ └── configuration.nix
│ └── bureautique/ # Station bureautique │ └── gaia/ # Portable de Xavier (MAO)
│ └── configuration.nix │ └── configuration.nix
├── modules/ # Modules autonomes ├── modules/ # Modules autonomes
@@ -99,7 +103,9 @@ nixos-infra/
│ │ │ └── options.nix # Options exposées │ │ │ └── options.nix # Options exposées
│ │ ├── gitea/ │ │ ├── gitea/
│ │ │ └── default.nix │ │ │ └── default.nix
│ │ ├── bitwarden/ │ │ ├── password-manager/
│ │ │ └── default.nix
│ │ ├── reverse-proxy/
│ │ │ └── default.nix │ │ │ └── default.nix
│ │ └── ... │ │ └── ...
│ │ │ │
@@ -112,8 +118,6 @@ nixos-infra/
├── users/ # Utilisateurs concrets ├── users/ # Utilisateurs concrets
│ ├── root/ │ ├── root/
│ │ └── configuration.nix │ │ └── configuration.nix
│ ├── admin/
│ │ └── configuration.nix
│ ├── xavier/ │ ├── xavier/
│ │ └── configuration.nix │ │ └── configuration.nix
│ ├── frida/ │ ├── frida/
@@ -171,17 +175,17 @@ nixos-infra/
| Nom | Type de Machine | Services | IPv4 | Token IPv6 | | Nom | Type de Machine | Services | IPv4 | Token IPv6 |
| ---------| --------------------| ----------------| ------| ------------| | ---------| --------------------| -------------| ------| ------------|
| pve01 | Hyperviseur | Proxmox | | | | pve01 | Hyperviseur | Proxmox | | |
| pve02 | Hyperviseur | Proxmox | | | | pve02 | Hyperviseur | Proxmox | | |
| dns01 | Conteneur LXC | DNS | | | | dns01 | Conteneur LXC | DNS | | |
| gitea01 | Conteneur LXC | Gitea | | | | gitea01 | Conteneur LXC | Gitea | | |
| vault01 | Conteneur LXC | Vaultwarden | | | | vault01 | Conteneur LXC | Vaultwarden | | |
| sting | Station de travail | Développement, | | | | sting | Station de travail | | | |
| | | Bureautique, | | | | | | | | |
| | | MAO, | | | | | | | | |
| | | Administration | | | | | | | | |
| marley | Station de travail | Bureautique | | | | marley | Station de travail | | | |
--- ---
@@ -206,7 +210,6 @@ nixos-infra/
| --------| -----------------------| -----------| | --------| -----------------------| -----------|
| root | Superutilisateur | ❌ | | root | Superutilisateur | ❌ |
| xavier | Utilisateur principal | ✅ | | xavier | Utilisateur principal | ✅ |
| | | |
| frida | Utilisateur | ✅ | | frida | Utilisateur | ✅ |
| guest | Invité | ❌ | | 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) ?
@@ -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
};
}
+65
View File
@@ -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";
}
@@ -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 = [];
};
}
+42
View File
@@ -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 !"
@@ -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
'';
}