mirror of https://gitlab.crans.org/nounous/nixos
Merge branch 'hosts-v2' into 'main'
Module pour les infos.nix See merge request nounous/nixos!104sondages
commit
198500b0a3
|
|
@ -5,6 +5,7 @@
|
|||
./hardware-configuration.nix
|
||||
./networking.nix
|
||||
./nginx.nix
|
||||
./restic.nix
|
||||
];
|
||||
|
||||
networking.hostId = "bbdd1133";
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@
|
|||
|
||||
enable = true;
|
||||
|
||||
networking.adm.enable = false;
|
||||
resticClient.enable = false;
|
||||
networking = {
|
||||
adm.enable = false;
|
||||
};
|
||||
|
||||
services = {
|
||||
resticServer = {
|
||||
enable = true;
|
||||
port = 4242;
|
||||
};
|
||||
monitoring = {
|
||||
nginx.enable = true;
|
||||
};
|
||||
|
||||
resticClient.enable = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
config.crans.services = {
|
||||
resticServer = {
|
||||
enable = true;
|
||||
port = 4242;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -9,5 +9,9 @@
|
|||
srv-nat.enable = true;
|
||||
};
|
||||
|
||||
monitoring = {
|
||||
nginx.enable = true;
|
||||
};
|
||||
|
||||
resticClient.enable = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,14 @@
|
|||
adm.enable = true;
|
||||
srv = {
|
||||
enable = true;
|
||||
ipv4 = "185.230.79.19";
|
||||
ipv4.address = "185.230.79.19";
|
||||
};
|
||||
};
|
||||
|
||||
monitoring = {
|
||||
nginx.enable = true;
|
||||
};
|
||||
|
||||
resticClient.when = "06:07";
|
||||
|
||||
services = {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
# secrets de turn.
|
||||
#
|
||||
|
||||
{ config, pkgs, lib, ... }:
|
||||
{ config, info, pkgs, lib, ... }:
|
||||
|
||||
let
|
||||
keyFile = "/run/livekit.key";
|
||||
|
|
@ -24,7 +24,7 @@ in
|
|||
|
||||
rtc = {
|
||||
use_external_ip = false;
|
||||
node_ip = config.crans.networking.srv.ipv4;
|
||||
node_ip = info.networking.srv.ipv4.address;
|
||||
tcp_port = 8101;
|
||||
port_range_start = 50000;
|
||||
port_range_end = 52000;
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@
|
|||
adm.enable = true;
|
||||
srv = {
|
||||
enable = true;
|
||||
ipv4 = "185.230.79.15";
|
||||
ipv4.address = "185.230.79.15";
|
||||
};
|
||||
};
|
||||
|
||||
monitoring = {
|
||||
nginx.enable = true;
|
||||
};
|
||||
|
||||
resticClient.when = "02:34";
|
||||
|
||||
services = {
|
||||
acme.enable = true;
|
||||
};
|
||||
|
||||
|
||||
public-ssh = "";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,9 @@
|
|||
srv-nat.enable = true;
|
||||
};
|
||||
|
||||
monitoring = {
|
||||
nginx.enable = true;
|
||||
};
|
||||
|
||||
resticClient.when = "03:45";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,9 @@
|
|||
srv-nat.enable = true;
|
||||
};
|
||||
|
||||
monitoring = {
|
||||
nginx.enable = true;
|
||||
};
|
||||
|
||||
resticClient.when = "06:47";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,14 @@
|
|||
networking = {
|
||||
srv = {
|
||||
enable = true;
|
||||
ipv4 = "185.230.79.5";
|
||||
ipv4.address = "185.230.79.5";
|
||||
};
|
||||
};
|
||||
|
||||
monitoring = {
|
||||
nginx.enable = true;
|
||||
};
|
||||
|
||||
resticClient.when = "04:56";
|
||||
|
||||
services = {
|
||||
|
|
|
|||
|
|
@ -18,5 +18,9 @@
|
|||
|
||||
homeAdh.enable = true;
|
||||
|
||||
monitoring = {
|
||||
nginx.enable = true;
|
||||
};
|
||||
|
||||
resticClient.enable = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,9 @@
|
|||
srv-nat.enable = true;
|
||||
};
|
||||
|
||||
monitoring = {
|
||||
nginx.enable = true;
|
||||
};
|
||||
|
||||
resticClient.when = "02:56";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,10 +10,15 @@
|
|||
srv = {
|
||||
enable = true;
|
||||
interface = "ens20";
|
||||
ipv4 = "185.230.79.42";
|
||||
ipv4.address = "185.230.79.42";
|
||||
};
|
||||
};
|
||||
|
||||
services.acme.enable = true;
|
||||
|
||||
monitoring = {
|
||||
nginx.enable = true;
|
||||
};
|
||||
|
||||
resticClient.when = "03:42";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -230,10 +230,6 @@ in
|
|||
"zero".proxyPass = "172.16.10.130";
|
||||
};
|
||||
};
|
||||
|
||||
services = {
|
||||
acme.enable = true;
|
||||
};
|
||||
};
|
||||
|
||||
# Règle particulières
|
||||
|
|
|
|||
|
|
@ -9,5 +9,9 @@
|
|||
srv-nat.enable = true;
|
||||
};
|
||||
|
||||
monitoring = {
|
||||
nginx.enable = true;
|
||||
};
|
||||
|
||||
resticClient.when = "04:44";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
# XXX: Transformer en module NixOs
|
||||
vlans = import ./vlans.nix;
|
||||
switchs = import ./switchs.nix;
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
[
|
||||
"arceus"
|
||||
"carapuce"
|
||||
"salameche"
|
||||
"horst"
|
||||
]
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
{
|
||||
|
||||
srv = {
|
||||
id = 2;
|
||||
description = "Réseau public";
|
||||
interface = "ens19";
|
||||
ipv4 = {
|
||||
address = "185.230.79.0";
|
||||
prefixLength = 26;
|
||||
routes = [
|
||||
{
|
||||
address = "0.0.0.0";
|
||||
via = "185.230.79.62";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
ipv6 = {
|
||||
address = "2a0c:700:10::";
|
||||
routes = [
|
||||
{
|
||||
address = "::";
|
||||
via = "2a0c:700:2::ff:fe00:9902";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
srv-nat = {
|
||||
id = 3;
|
||||
description = "Réseau derrière un NAT";
|
||||
interface = "ens19";
|
||||
ipv4.routes = [
|
||||
{
|
||||
address = "0.0.0.0";
|
||||
via = "172.16.3.99";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
ipv6 = {
|
||||
address = "2a0c:700:3::";
|
||||
routes = [
|
||||
{
|
||||
address = "::";
|
||||
via = "2a0c:700:3::ff:fe00:9903";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
san = {
|
||||
id = 4;
|
||||
description = "Accès aux baies de stockages";
|
||||
interface = "ens19";
|
||||
};
|
||||
|
||||
ceph = {
|
||||
id = 6;
|
||||
description = "Réseau interne à ceph";
|
||||
interface = "ens20";
|
||||
};
|
||||
|
||||
adm = {
|
||||
id = 10;
|
||||
description = "Réseau interne";
|
||||
interface = "ens18";
|
||||
};
|
||||
|
||||
adh = {
|
||||
id = 12;
|
||||
description = "Réseau adhérent";
|
||||
ipv4 = {
|
||||
address = "185.230.78.0";
|
||||
routes = [
|
||||
{
|
||||
address = "0.0.0.0";
|
||||
via = "185.230.78.12";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
ipv6 = {
|
||||
address = "2a0c:700:12::";
|
||||
prefixLength = 48;
|
||||
routes = [
|
||||
{
|
||||
address = "::";
|
||||
via = "2a0c:700:12::ff:fe00:9912";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
adh-adm = {
|
||||
id = 13;
|
||||
description = "Réseau d’administration du réseau adhérent";
|
||||
};
|
||||
|
||||
ens = {
|
||||
id = 2751;
|
||||
description = "Interconnexion avec l’ENS.";
|
||||
ipv4 = {
|
||||
address = "138.231.136.0";
|
||||
prefixLength = 29;
|
||||
};
|
||||
ipv6 = null;
|
||||
};
|
||||
|
||||
ens-clubs = {
|
||||
id = 2754;
|
||||
description = "Réseau clubs interconnecté avec l’ENS";
|
||||
ipv6 = null;
|
||||
};
|
||||
|
||||
ens-lp = {
|
||||
id = 2756;
|
||||
description = "Réseau imprimante interconnecté avec l’ENS";
|
||||
ipv6 = null;
|
||||
};
|
||||
|
||||
}
|
||||
41
lib/info.nix
41
lib/info.nix
|
|
@ -3,11 +3,6 @@
|
|||
let
|
||||
inherit (lib)
|
||||
attrNames
|
||||
attrsToList
|
||||
isInt
|
||||
isString
|
||||
join
|
||||
length
|
||||
listToAttrs
|
||||
filter
|
||||
filterAttrs
|
||||
|
|
@ -16,31 +11,9 @@ let
|
|||
nixosSystem
|
||||
readDir
|
||||
warn
|
||||
warnIf
|
||||
warnIfNot
|
||||
;
|
||||
infoRequired = {
|
||||
name = isString;
|
||||
description = isString;
|
||||
id = isInt;
|
||||
};
|
||||
verifyAttrs =
|
||||
info:
|
||||
let
|
||||
missing = filter (n: !(info ? ${n})) (attrNames infoRequired);
|
||||
wrongType = filter (n: info ? ${n.name} && !(n.value info.${n.name})) (attrsToList infoRequired);
|
||||
in
|
||||
(warnIf (
|
||||
length missing > 0
|
||||
) "${info.name}/info.nix : les attributs « ${join ", " missing} » sont manquants")
|
||||
(warnIf (length wrongType > 0)
|
||||
"${info.name}/info.nix : les attributs « ${join ", " (map (i: i.name) wrongType)} » sont mal typés"
|
||||
)
|
||||
(warnIfNot (
|
||||
(info.isDebian or false) || info ? enable
|
||||
) "${info.name}/info.nix : cette machine nix ne définit pas l’attribut enable")
|
||||
info;
|
||||
|
||||
infra = import ../infra;
|
||||
get_hosts_names = path: attrNames (filterAttrs (name: type: type == "directory") (readDir path));
|
||||
get_info =
|
||||
path:
|
||||
|
|
@ -51,7 +24,15 @@ let
|
|||
filePath = path + "/${name}/info.nix";
|
||||
in
|
||||
if builtins.pathExists filePath then
|
||||
verifyAttrs (import filePath)
|
||||
(lib.evalModules {
|
||||
modules = [
|
||||
../modules/info
|
||||
filePath
|
||||
];
|
||||
specialArgs = {
|
||||
inherit infra;
|
||||
};
|
||||
}).config
|
||||
else
|
||||
warn "${toString filePath} not found" null
|
||||
) (get_hosts_names path)
|
||||
|
|
@ -67,10 +48,10 @@ rec {
|
|||
nixosSystem {
|
||||
specialArgs = inputs // {
|
||||
hosts = all_hosts;
|
||||
inherit info infra;
|
||||
};
|
||||
modules = [
|
||||
(path + "/${name}")
|
||||
({ ... }: { config.crans = info; })
|
||||
]
|
||||
++ baseModules;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
{ lib, config, ... }:
|
||||
{
|
||||
lib,
|
||||
info,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.crans;
|
||||
|
||||
inherit (lib)
|
||||
mkEnableOption
|
||||
mkOption
|
||||
mkIf
|
||||
types
|
||||
optional
|
||||
;
|
||||
in
|
||||
|
|
@ -21,76 +20,22 @@ in
|
|||
./ntp.nix
|
||||
./restic_client.nix
|
||||
./monitoring.nix
|
||||
./motd.nix
|
||||
./nullmailer.nix
|
||||
./packages.nix
|
||||
./ssh.nix
|
||||
./store.nix
|
||||
./users.nix
|
||||
./vlans.nix
|
||||
./virtualisation.nix
|
||||
];
|
||||
|
||||
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 ?";
|
||||
};
|
||||
|
||||
isDebian = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
example = "true";
|
||||
description = "Est-ce une machine Debian ?";
|
||||
};
|
||||
|
||||
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 {
|
||||
crans = {
|
||||
homeNounou.enable = lib.mkDefault true;
|
||||
monitoring.enable = true;
|
||||
networking = {
|
||||
enable = lib.mkDefault true;
|
||||
adm.enable = lib.mkDefault true;
|
||||
};
|
||||
resticClient.enable = lib.mkDefault true;
|
||||
users = {
|
||||
ldap.enable = true;
|
||||
};
|
||||
};
|
||||
# Options ../info/meta.nix
|
||||
|
||||
config = mkIf info.enable {
|
||||
warnings = (
|
||||
optional (
|
||||
cfg.isVm != (cfg.id >= 100)
|
||||
) "${cfg.name}: isVm (${toString cfg.isVm}) est incohérent avec son id (${toString cfg.id})"
|
||||
info.isVm != (info.id >= 100)
|
||||
) "${info.name}: isVm (${toString info.isVm}) est incohérent avec son id (${toString info.id})"
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,14 @@
|
|||
{ lib, config, ... }:
|
||||
{ lib, info, ... }:
|
||||
|
||||
let
|
||||
cfg = config.crans;
|
||||
|
||||
inherit (lib) mkEnableOption mkIf;
|
||||
inherit (lib) mkIf;
|
||||
in
|
||||
|
||||
{
|
||||
options.crans = {
|
||||
homeNounou = {
|
||||
enable = mkEnableOption "Monter /home_nounou.";
|
||||
};
|
||||
homeAdh = {
|
||||
enable = mkEnableOption "Monter /home-adh";
|
||||
};
|
||||
};
|
||||
|
||||
# Options ../info/home.nix
|
||||
config = {
|
||||
fileSystems = {
|
||||
home_nounou = mkIf cfg.homeNounou.enable {
|
||||
home_nounou = mkIf info.homeNounou.enable {
|
||||
mountPoint = "/home_nounou";
|
||||
device = "172.16.10.1:/pool/home";
|
||||
fsType = "nfs";
|
||||
|
|
@ -28,7 +18,7 @@ in
|
|||
];
|
||||
};
|
||||
|
||||
home_adh = mkIf cfg.homeAdh.enable {
|
||||
home_adh = mkIf info.homeAdh.enable {
|
||||
mountPoint = "/home-adh";
|
||||
device = "172.16.4.2:/pool/home";
|
||||
fsType = "nfs";
|
||||
|
|
|
|||
|
|
@ -1,32 +1,28 @@
|
|||
{ config, lib, ... }:
|
||||
{
|
||||
config,
|
||||
info,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.crans.monitoring;
|
||||
cfg = info.monitoring;
|
||||
|
||||
inherit (lib)
|
||||
mkEnableOption
|
||||
mkIf
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
nginxEnable = config.services.nginx.enable;
|
||||
inherit (lib) mkIf optional;
|
||||
|
||||
boolToStr = b: if b then "true" else "false";
|
||||
in
|
||||
|
||||
{
|
||||
options.crans.monitoring = {
|
||||
enable = mkEnableOption "Monitoring prometheus de la machine.";
|
||||
# Options ../info/monitoring.nix
|
||||
|
||||
nginx = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = config.services.nginx.enable;
|
||||
example = true;
|
||||
description = "Monitoring de Nginx par prometheus.";
|
||||
};
|
||||
};
|
||||
};
|
||||
config = {
|
||||
warnings = optional (cfg.enable && (nginxEnable != cfg.nginx.enable)) ''
|
||||
${info.name} : config.services.nginx.enable (${boolToStr nginxEnable}) n’est pas cohérent avec le monitoring déclaré dans l’info.nix (${boolToStr cfg.nginx.enable})
|
||||
'';
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
services.prometheus.exporters = {
|
||||
services.prometheus.exporters = mkIf cfg.enable {
|
||||
node = {
|
||||
enable = true;
|
||||
port = 9100;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
{ self, lib, ... }:
|
||||
let
|
||||
inherit (lib) removeSuffix;
|
||||
in
|
||||
{
|
||||
users.motd =
|
||||
let
|
||||
shortRev = self.shortRev or self.dirtyShortRev or "inconnue";
|
||||
rev = self.rev or (removeSuffix "-dirty" (self.dirtyRev or "inconnue"));
|
||||
isDirty = !(self ? rev);
|
||||
in
|
||||
''
|
||||
${
|
||||
if isDirty then "!! DIRTY !! " else ""
|
||||
}Version déployée ${shortRev}, modifiée le ${self.lastModifiedDate or "??"}.
|
||||
|
||||
https://gitlab.crans.org/nounous/nixos/-/commit/${rev}
|
||||
'';
|
||||
}
|
||||
|
|
@ -1,91 +1,26 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
hosts,
|
||||
infra,
|
||||
info,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.crans;
|
||||
cfg-net = cfg.networking;
|
||||
cfg-net = info.networking;
|
||||
|
||||
inherit (lib)
|
||||
mkEnableOption
|
||||
mkIf
|
||||
mkOption
|
||||
mkDefault
|
||||
types
|
||||
mod
|
||||
mapAttrs
|
||||
mapAttrs'
|
||||
filterAttrs
|
||||
mergeAttrsList
|
||||
optional
|
||||
fixedWidthString
|
||||
nameValuePair
|
||||
;
|
||||
in
|
||||
{
|
||||
options.crans.networking = {
|
||||
enable = mkEnableOption "Configuration réseaux commune à toutes les machines du Crans.";
|
||||
}
|
||||
// mapAttrs (
|
||||
vlan: conf:
|
||||
let
|
||||
vlanId = mod conf.id 100;
|
||||
in
|
||||
mergeAttrsList (
|
||||
[
|
||||
{
|
||||
enable = mkEnableOption "Activation du réseau ${vlan}";
|
||||
|
||||
interface = mkOption {
|
||||
type = types.str;
|
||||
description = "Interface pour le réseau ${vlan}";
|
||||
default = conf.interface;
|
||||
};
|
||||
|
||||
defaultRoutes = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Configuration par défaut des routes de ${vlan}";
|
||||
};
|
||||
}
|
||||
]
|
||||
++ optional ((conf.ipv4 or true) != null) {
|
||||
ipv4 = mkOption {
|
||||
type = types.str;
|
||||
description = "Adresse IPv4 de la machine sur le réseau ${vlan}";
|
||||
default = "172.16.${toString vlanId}.${toString cfg.id}";
|
||||
};
|
||||
}
|
||||
++ optional ((conf.ipv6 or true) != null) (
|
||||
let
|
||||
# XXX: Utilisation du masque pour le déterminer à la place ?
|
||||
prefix =
|
||||
if lib.hasPrefix "2a0c:700" conf.ipv6.address then
|
||||
"2a0c:700"
|
||||
else if lib.hasPrefix "fd00:0:0" conf.ipv6.address then
|
||||
"fd00:0:0"
|
||||
else
|
||||
(builtins.warn "Le prefixe de ${conf.ipv6.address} n’est pas reconnu");
|
||||
in
|
||||
{
|
||||
ipv6 = mkOption {
|
||||
type = types.str;
|
||||
description = "Adresse IPv6 de la machine sur le réseau ${vlan}";
|
||||
default = "${prefix}:${toString vlanId}::ff:fe0${toString (cfg.id / 100)}:${toString (mod cfg.id 100)}${
|
||||
fixedWidthString 2 "0" (toString vlanId)
|
||||
}";
|
||||
};
|
||||
}
|
||||
)
|
||||
)
|
||||
) cfg.vlans;
|
||||
|
||||
# Options ../info/networking.nix
|
||||
config = mkIf cfg-net.enable {
|
||||
networking = {
|
||||
hostName = cfg.name;
|
||||
hostName = info.name;
|
||||
useDHCP = false;
|
||||
firewall.enable = mkDefault false;
|
||||
nameservers = [
|
||||
|
|
@ -95,24 +30,24 @@ in
|
|||
];
|
||||
|
||||
interfaces = mapAttrs' (
|
||||
vlan: vconf:
|
||||
vname: _:
|
||||
let
|
||||
conf = cfg-net.${vlan};
|
||||
conf = cfg-net.${vname};
|
||||
in
|
||||
nameValuePair conf.interface (
|
||||
# On itère ipv4 / ipv6
|
||||
builtins.mapAttrs
|
||||
(
|
||||
ipvx: _:
|
||||
mkIf (vconf.${ipvx} != null) {
|
||||
mkIf (conf.${ipvx} != null) {
|
||||
addresses = [
|
||||
{
|
||||
address = conf.${ipvx};
|
||||
prefixLength = vconf.${ipvx}.prefixLength;
|
||||
address = conf.${ipvx}.address;
|
||||
prefixLength = conf.${ipvx}.prefixLength;
|
||||
}
|
||||
];
|
||||
|
||||
routes = mkIf conf.defaultRoutes vconf.${ipvx}.routes;
|
||||
routes = conf.${ipvx}.routes;
|
||||
}
|
||||
)
|
||||
{
|
||||
|
|
@ -120,7 +55,7 @@ in
|
|||
"ipv6" = null;
|
||||
}
|
||||
)
|
||||
) (filterAttrs (n: _: cfg-net.${n}.enable) cfg.vlans); # On filtre les interfaces désactivées.
|
||||
) (filterAttrs (n: _: cfg-net.${n}.enable) infra.vlans); # On filtre les interfaces désactivées.
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,18 @@
|
|||
{ config, lib, ... }:
|
||||
{
|
||||
config,
|
||||
info,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.crans.resticClient;
|
||||
cfg = info.resticClient;
|
||||
|
||||
inherit (lib)
|
||||
mkEnableOption
|
||||
mkIf
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
inherit (lib) mkIf;
|
||||
in
|
||||
|
||||
{
|
||||
options.crans.resticClient = {
|
||||
enable = mkEnableOption "Configuration générale pour le client restic.";
|
||||
|
||||
additionalPaths = mkOption {
|
||||
type = types.listOf types.path;
|
||||
default = [ ];
|
||||
example = [ "/backup" ];
|
||||
description = "Chemins à backuper en plus de ceux par défaut.";
|
||||
};
|
||||
|
||||
additionalExcludes = mkOption {
|
||||
type = types.listOf types.path;
|
||||
default = [ ];
|
||||
example = [ "/var/lib/<service>/cache" ];
|
||||
description = "Chemins à exclure des backups en plus de ceux par défaut.";
|
||||
};
|
||||
|
||||
when = mkOption {
|
||||
type = types.str;
|
||||
example = "05:42";
|
||||
description = "À quelle heure faire les backups.";
|
||||
};
|
||||
};
|
||||
# Options ../info/resticClient.nix
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
age.secrets = {
|
||||
|
|
@ -52,11 +30,13 @@ in
|
|||
paths = [
|
||||
"/etc"
|
||||
"/var"
|
||||
] ++ cfg.additionalPaths;
|
||||
]
|
||||
++ cfg.additionalPaths;
|
||||
exclude = [
|
||||
"/var/cache"
|
||||
"/var/lib/lxcfs"
|
||||
] ++ cfg.additionalExcludes;
|
||||
]
|
||||
++ cfg.additionalExcludes;
|
||||
timerConfig = {
|
||||
OnCalendar = cfg.when;
|
||||
RandomizedDelaySec = "6h";
|
||||
|
|
|
|||
|
|
@ -1,35 +1,9 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
self,
|
||||
...
|
||||
}:
|
||||
|
||||
{ config, info, ... }:
|
||||
let
|
||||
cfg = config.crans.users;
|
||||
|
||||
inherit (lib)
|
||||
mkEnableOption
|
||||
mkOption
|
||||
types
|
||||
;
|
||||
cfg = info.users;
|
||||
in
|
||||
|
||||
{
|
||||
options.crans.users = {
|
||||
ldap = {
|
||||
enable = mkEnableOption "Authentification par le LDAP adm.";
|
||||
};
|
||||
|
||||
root = {
|
||||
passwordFile = mkOption {
|
||||
type = types.path;
|
||||
default = ../../secrets/common/root.age;
|
||||
example = ../../secrets/apprentix/root.age;
|
||||
description = "Fichier chiffré par age contenant le mot de passe root.";
|
||||
};
|
||||
};
|
||||
};
|
||||
# Options : ../info/users.nix
|
||||
|
||||
config = {
|
||||
age.secrets.root-passwd-hash = {
|
||||
|
|
@ -39,20 +13,6 @@ in
|
|||
users = {
|
||||
mutableUsers = false;
|
||||
|
||||
motd =
|
||||
let
|
||||
shortRev = self.shortRev or self.dirtyShortRev or "inconnue";
|
||||
rev = self.rev or (lib.strings.removeSuffix "-dirty" (self.dirtyRev or "inconnue"));
|
||||
isDirty = !(self ? rev);
|
||||
in
|
||||
''
|
||||
${
|
||||
if isDirty then "!! DIRTY !! " else ""
|
||||
}Version déployée ${shortRev}, modifiée le ${self.lastModifiedDate or "??"}.
|
||||
|
||||
https://gitlab.crans.org/nounous/nixos/-/commit/${rev}
|
||||
'';
|
||||
|
||||
users.root = {
|
||||
hashedPasswordFile = config.age.secrets.root-passwd-hash.path;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,230 +0,0 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib)
|
||||
mkOption
|
||||
types
|
||||
mkDefault
|
||||
mkForce
|
||||
;
|
||||
|
||||
vlanConf = {
|
||||
|
||||
srv = {
|
||||
id = 2;
|
||||
description = "Réseau public";
|
||||
interface = "ens19";
|
||||
ipv4 = {
|
||||
address = mkForce "185.230.79.0";
|
||||
prefixLength = 26;
|
||||
routes = [
|
||||
{
|
||||
address = "0.0.0.0";
|
||||
via = "185.230.79.62";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
ipv6 = {
|
||||
address = mkForce "2a0c:700:10::";
|
||||
routes = [
|
||||
{
|
||||
address = "::";
|
||||
via = "2a0c:700:2::ff:fe00:9902";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
srv-nat = {
|
||||
id = 3;
|
||||
description = "Réseau derrière un NAT";
|
||||
interface = "ens19";
|
||||
ipv4.routes = [
|
||||
{
|
||||
address = "0.0.0.0";
|
||||
via = "172.16.3.99";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
ipv6 = {
|
||||
address = mkForce "2a0c:700:3::";
|
||||
routes = [
|
||||
{
|
||||
address = "::";
|
||||
via = "2a0c:700:3::ff:fe00:9903";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
san = {
|
||||
id = 4;
|
||||
description = "Accès aux baies de stockages";
|
||||
interface = "ens19";
|
||||
};
|
||||
|
||||
ceph = {
|
||||
id = 6;
|
||||
description = "Réseau interne à ceph";
|
||||
interface = "ens20";
|
||||
};
|
||||
|
||||
adm = {
|
||||
id = 10;
|
||||
description = "Réseau interne";
|
||||
interface = "ens18";
|
||||
};
|
||||
|
||||
adh = {
|
||||
id = 12;
|
||||
description = "Réseau adhérent";
|
||||
ipv4 = {
|
||||
address = mkForce "185.230.78.0";
|
||||
routes = [
|
||||
{
|
||||
address = "0.0.0.0";
|
||||
via = "185.230.78.12";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
ipv6 = {
|
||||
address = mkForce "2a0c:700:12::";
|
||||
prefixLength = 48;
|
||||
routes = [
|
||||
{
|
||||
address = "::";
|
||||
via = "2a0c:700:12::ff:fe00:9912";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
adh-adm = {
|
||||
id = 13;
|
||||
description = "Réseau d’administration du réseau adhérent";
|
||||
};
|
||||
|
||||
ens = {
|
||||
id = 2751;
|
||||
description = "Interconnexion avec l’ENS.";
|
||||
ipv4 = {
|
||||
address = mkForce "138.231.136.0";
|
||||
prefixLength = 29;
|
||||
};
|
||||
ipv6 = null;
|
||||
};
|
||||
|
||||
ens-clubs = {
|
||||
id = 2754;
|
||||
description = "Réseau clubs interconnecté avec l’ENS";
|
||||
ipv6 = null;
|
||||
};
|
||||
|
||||
ens-lp = {
|
||||
id = 2756;
|
||||
description = "Réseau imprimante interconnecté avec l’ENS";
|
||||
ipv6 = null;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
ipOpt =
|
||||
v:
|
||||
let
|
||||
maxPrefix = if v == 4 then 32 else 128;
|
||||
in
|
||||
types.submodule {
|
||||
options = {
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
description = "Adresses IPv${v} du réseau";
|
||||
};
|
||||
|
||||
prefixLength = mkOption {
|
||||
type = types.ints.between 0 maxPrefix;
|
||||
default = if v == 4 then 24 else 64;
|
||||
description = "Prefixe du réseau";
|
||||
};
|
||||
|
||||
routes = mkOption {
|
||||
default = [ ];
|
||||
description = "Routes par défaut";
|
||||
example = [
|
||||
{
|
||||
address = "0.0.0.0";
|
||||
via = "172.16.3.99";
|
||||
prefixLength = 0;
|
||||
}
|
||||
];
|
||||
type = types.listOf (
|
||||
types.submodule {
|
||||
options = {
|
||||
address = mkOption { type = types.str; };
|
||||
via = mkOption { type = types.str; };
|
||||
prefixLength = mkOption { type = types.ints.between 0 maxPrefix; };
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
options.crans.vlans = mkOption {
|
||||
type = types.attrsOf (
|
||||
types.submodule {
|
||||
options = {
|
||||
id = mkOption {
|
||||
type = types.int;
|
||||
example = "10";
|
||||
description = "Id du VLAN";
|
||||
};
|
||||
|
||||
description = mkOption {
|
||||
type = types.str;
|
||||
description = "Description du VLAN";
|
||||
};
|
||||
|
||||
interface = mkOption {
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
example = "ens19";
|
||||
description = "Interface par défaut du VLAN";
|
||||
};
|
||||
|
||||
ipv4 = mkOption {
|
||||
type = types.nullOr (ipOpt 4);
|
||||
description = "Réseau IPv4 du VLAN.";
|
||||
};
|
||||
|
||||
ipv6 = mkOption {
|
||||
type = types.nullOr (ipOpt 6);
|
||||
description = "Réseau IPv6 du VLAN.";
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
config.crans.vlans = (
|
||||
builtins.mapAttrs (
|
||||
vlan: conf:
|
||||
let
|
||||
vlan = lib.mod conf.id 100;
|
||||
in
|
||||
lib.mkMerge (
|
||||
[ conf ]
|
||||
++ lib.optional ((conf.ipv4 or true) != null) {
|
||||
ipv4.address = mkDefault "172.16.${toString vlan}.0";
|
||||
}
|
||||
++ lib.optional ((conf.ipv6 or true) != null) {
|
||||
ipv6.address = mkDefault "fd00:0:0:${toString vlan}::";
|
||||
}
|
||||
)
|
||||
) vlanConf
|
||||
);
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) mkEnableOption;
|
||||
in
|
||||
{
|
||||
options.services.acme.enable = mkEnableOption "Activer les certificats ACME via let's encrypt.";
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
{ lib, config, ... }:
|
||||
let
|
||||
inherit (lib)
|
||||
mkDefault
|
||||
mkOption
|
||||
mkIf
|
||||
types
|
||||
;
|
||||
in
|
||||
# L’évaluation se fait en deux passes.
|
||||
# 1. La flake.nix avec la lib/info.nix évalue les info.nix
|
||||
# 2. Les VMs évaluent la conf en partant de cette évaluation en paramètre
|
||||
# (anisi que celles des autres machines)
|
||||
{
|
||||
imports = [
|
||||
./acme.nix
|
||||
./home.nix
|
||||
./meta.nix
|
||||
./monitoring.nix
|
||||
./networking.nix
|
||||
./resticClient.nix
|
||||
./users.nix
|
||||
];
|
||||
options.enable = mkOption {
|
||||
type = types.bool;
|
||||
example = true;
|
||||
description = "Activer la configuration Crans par défaut";
|
||||
# On n’utilise pas mkEnableOption pour forcer la définition de enable à true
|
||||
# ou false (et limiter les oublis)
|
||||
};
|
||||
config = mkIf config.enable {
|
||||
homeNounou.enable = mkDefault true;
|
||||
monitoring.enable = mkDefault true;
|
||||
networking = {
|
||||
enable = mkDefault true;
|
||||
adm.enable = mkDefault true;
|
||||
};
|
||||
resticClient.enable = mkDefault true;
|
||||
users = {
|
||||
ldap.enable = mkDefault true;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) mkEnableOption;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
homeNounou.enable = mkEnableOption "Monter /home_nounou.";
|
||||
homeAdh.enable = mkEnableOption "Monter /home-adh.";
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
description = "Nom de la machine.";
|
||||
};
|
||||
|
||||
description = mkOption {
|
||||
type = types.str;
|
||||
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 )
|
||||
";
|
||||
};
|
||||
|
||||
isVm = mkOption {
|
||||
type = types.bool;
|
||||
description = "Est-ce une machine virtuelle ?";
|
||||
};
|
||||
|
||||
isDebian = mkOption {
|
||||
type = types.bool;
|
||||
description = "Est-ce que c’est une machine sous Debian ?";
|
||||
default = false;
|
||||
};
|
||||
|
||||
public-ssh = mkOption {
|
||||
type = types.str;
|
||||
description = "Clé ssh publique de la machine.";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
in
|
||||
{
|
||||
options.monitoring = {
|
||||
enable = mkEnableOption "Monitoring prometheus de la machine.";
|
||||
|
||||
nginx = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
example = true;
|
||||
description = "Monitoring de Nginx par prometheus.";
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
{
|
||||
config,
|
||||
infra,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
inherit (lib)
|
||||
fixedWidthString
|
||||
hasPrefix
|
||||
listToAttrs
|
||||
mapAttrs
|
||||
mergeAttrsList
|
||||
mod
|
||||
mkEnableOption
|
||||
mkOption
|
||||
optional
|
||||
optionalAttrs
|
||||
nameValuePair
|
||||
types
|
||||
;
|
||||
|
||||
switchOptions = listToAttrs (
|
||||
map (
|
||||
n:
|
||||
nameValuePair n (mkOption {
|
||||
type = types.nullOr types.int;
|
||||
description = "Port sur le switch ${n}";
|
||||
default = null;
|
||||
})
|
||||
) infra.switchs
|
||||
);
|
||||
|
||||
routesType = types.listOf (
|
||||
types.submodule {
|
||||
options = {
|
||||
address = mkOption {
|
||||
type = types.str;
|
||||
description = "Réseau de destination";
|
||||
};
|
||||
prefixLength = mkOption {
|
||||
type = types.int;
|
||||
description = "Masque du réseau de destination";
|
||||
};
|
||||
via = mkOption {
|
||||
type = types.str;
|
||||
description = "Ip de la gateway";
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
options = {
|
||||
ilo.id = mkOption {
|
||||
type = types.nullOr types.int;
|
||||
description = "Identifiant de l’ilo";
|
||||
default = null;
|
||||
};
|
||||
ilo.switch = switchOptions;
|
||||
|
||||
# TODO: vérifier que les IPs déclarées sont bien dans le réseau vlan (masque)
|
||||
networking = {
|
||||
enable = mkEnableOption "Activation du réseau Crans";
|
||||
switch = switchOptions;
|
||||
}
|
||||
// mapAttrs (
|
||||
vname: vconf:
|
||||
mergeAttrsList (
|
||||
[
|
||||
{
|
||||
enable = mkEnableOption "Activation du réseau ${vname}";
|
||||
|
||||
interface = mkOption {
|
||||
type = types.str;
|
||||
description = "Interface pour le réseau ${vname}";
|
||||
default = vconf.interface;
|
||||
};
|
||||
|
||||
tag = mkOption {
|
||||
type = types.int;
|
||||
description = "Tag du vlan";
|
||||
readOnly = true;
|
||||
default = vconf.id;
|
||||
};
|
||||
}
|
||||
]
|
||||
++ optional ((vconf.ipv4 or { }) != null) {
|
||||
ipv4.address =
|
||||
mkOption {
|
||||
type = types.str;
|
||||
description = "Adresse IPv4 de la machine sur le réseau ${vname}";
|
||||
}
|
||||
// (optionalAttrs (hasPrefix "172.16" (vconf.ipv4.address or "172.16.0.0")) {
|
||||
default = "172.16.${toString vconf.id}.${toString config.id}";
|
||||
});
|
||||
|
||||
ipv4.prefixLength = mkOption {
|
||||
type = types.int;
|
||||
description = "Masque IPv4 de la machine sur le réseau ${vname}";
|
||||
default = vconf.ipv4.prefixLength or 24;
|
||||
};
|
||||
|
||||
ipv4.routes = mkOption {
|
||||
type = routesType;
|
||||
description = "Routes de l’interface";
|
||||
default = vconf.ipv4.routes or [ ];
|
||||
};
|
||||
}
|
||||
++ optional ((vconf.ipv6 or { }) != null) (
|
||||
let
|
||||
# XXX: Utilisation du masque pour le déterminer à la place ?
|
||||
prefix =
|
||||
if !(vconf ? ipv6) || lib.hasPrefix "fd00:0:0" vconf.ipv6.address then
|
||||
"fd00:0:0"
|
||||
else if lib.hasPrefix "2a0c:700" vconf.ipv6.address then
|
||||
"2a0c:700"
|
||||
else
|
||||
(builtins.warn "Le prefixe de ${vconf.ipv6.address} n’est pas reconnu");
|
||||
in
|
||||
{
|
||||
ipv6.address = mkOption {
|
||||
type = types.str;
|
||||
description = "Adresse IPv6 de la machine sur le réseau ${vname}";
|
||||
default = "${prefix}:${toString vconf.id}::ff:fe0${toString (config.id / 100)}:${toString (mod config.id 100)}${
|
||||
fixedWidthString 2 "0" (toString vconf.id)
|
||||
}";
|
||||
};
|
||||
|
||||
ipv6.prefixLength = mkOption {
|
||||
type = types.int;
|
||||
description = "Masque IPv6 de la machine sur le réseau ${vname}";
|
||||
default = vconf.ipv6.prefixLength or 64;
|
||||
};
|
||||
|
||||
ipv6.routes = mkOption {
|
||||
type = routesType;
|
||||
description = "Routes de l’interface";
|
||||
default = vconf.ipv6.routes or [ ];
|
||||
};
|
||||
}
|
||||
)
|
||||
)
|
||||
) infra.vlans
|
||||
|
||||
;
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
in
|
||||
{
|
||||
options.resticClient = {
|
||||
enable = mkEnableOption "Configuration générale pour le client restic.";
|
||||
|
||||
additionalPaths = mkOption {
|
||||
type = types.listOf types.path;
|
||||
default = [ ];
|
||||
example = [ "/backup" ];
|
||||
description = "Chemins à backuper en plus de ceux par défaut.";
|
||||
};
|
||||
|
||||
additionalExcludes = mkOption {
|
||||
type = types.listOf types.path;
|
||||
default = [ ];
|
||||
example = [ "/var/lib/<service>/cache" ];
|
||||
description = "Chemins à exclure des backups en plus de ceux par défaut.";
|
||||
};
|
||||
|
||||
when = mkOption {
|
||||
type = types.str;
|
||||
example = "05:42";
|
||||
description = "À quelle heure faire les backups.";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
inherit (lib) mkEnableOption mkOption types;
|
||||
in
|
||||
{
|
||||
options.users = {
|
||||
ldap = {
|
||||
enable = mkEnableOption "Authentification par le LDAP adm.";
|
||||
};
|
||||
|
||||
root = {
|
||||
passwordFile = mkOption {
|
||||
type = types.path;
|
||||
default = ../../secrets/common/root.age;
|
||||
example = ../../secrets/apprentix/root.age;
|
||||
description = "Fichier chiffré par agenix contenant le mot de passe root.";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,16 +1,18 @@
|
|||
{ config, lib, ... }:
|
||||
{
|
||||
config,
|
||||
info,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = config.crans.services.acme;
|
||||
cfg = info.services.acme;
|
||||
|
||||
inherit (lib) mkEnableOption mkIf;
|
||||
inherit (lib) mkIf;
|
||||
in
|
||||
|
||||
{
|
||||
options.crans.services.acme = {
|
||||
enable = mkEnableOption "Activer les certificats ACME via let's encrypt.";
|
||||
};
|
||||
|
||||
# Options : ../info/acme.nix
|
||||
config = mkIf cfg.enable {
|
||||
age.secrets = {
|
||||
acme-env.file = ../../secrets/acme/env.age;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,13 @@
|
|||
{ lib, config, ... }:
|
||||
{
|
||||
lib,
|
||||
config,
|
||||
info,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
cfg = info.monitoring;
|
||||
in
|
||||
{
|
||||
services.nginx = lib.mkIf config.services.nginx.enable {
|
||||
recommendedProxySettings = true;
|
||||
|
|
@ -15,7 +23,7 @@
|
|||
real_ip_header X-Real-Ip;
|
||||
'';
|
||||
|
||||
virtualHosts.nginx-stub-status = lib.mkIf config.crans.monitoring.enable {
|
||||
virtualHosts.nginx-stub-status = lib.mkIf (cfg.enable && cfg.nginx.enable) {
|
||||
listen = [
|
||||
{
|
||||
addr = "[::1]";
|
||||
|
|
|
|||
Loading…
Reference in New Issue