Sites statics et SSL

hachino-test
Pyjacpp 2026-07-19 12:01:46 +02:00
parent 9222bf3d29
commit fddbbaf10e
No known key found for this signature in database
GPG Key ID: ED479A5A26930939
3 changed files with 60 additions and 13 deletions

View File

@ -135,7 +135,7 @@ let
opts: opts:
pkgs.fetchFromGitLab ( pkgs.fetchFromGitLab (
{ {
domain = "gitlab.adm.crans.org"; domain = "gitlab.crans.org";
owner = "nounous"; owner = "nounous";
} }
// opts // opts
@ -156,10 +156,26 @@ let
mkdocs-material mkdocs-material
]; ];
buildPhase = '' buildPhase = ''
python3 -m mkdocs -- build -d build python3 -m mkdocs -- build -d $out
''; '';
installPhase = '' };
mv build $out
homepagePkg = pkgs.stdenv.mkDerivation {
name = "site-homepage";
src = fetchFromCrans {
repo = "homepage";
rev = "master";
hash = "sha256-e9tttzKEWcBhogQY2ITDqqTbix/zcnBAylj1eKY791E=";
};
nativeBuildInputs = with pkgs; [
hugo
git
];
buildPhase = ''
hugo build -d $out
''; '';
}; };
in in
@ -231,6 +247,12 @@ in
"wikipedia" "wikipedia"
]; ];
}; };
"www" = {
serveLocalFiles = homepagePkg;
serverAliases = [
"."
];
};
}; };
}; };

View File

@ -24,12 +24,17 @@ in
dnsPropagationCheck = false; dnsPropagationCheck = false;
}; };
certs."crans.org" = { certs."all.crans.all" = {
domain = "*.crans.org"; domain = "*.crans.org";
dnsProvider = "rfc2136"; dnsProvider = "rfc2136";
# Contient le serveur à contacter avec le protocole # Contient le serveur à contacter avec le protocole
# et le mot de passe # et le mot de passe
environmentFile = config.age.secrets.acme-env.path; environmentFile = config.age.secrets.acme-env.path;
extraDomainNames = [
"*.crans.fr"
"*.crans.eu"
];
group = config.services.nginx.group;
}; };
}; };
}; };

View File

@ -129,6 +129,24 @@ in
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
}) cfg.virtualHosts; }) cfg.virtualHosts;
# On fait un certificat commun pour tous les hosts
security.acme.certs."all.crans.all" = {
domain = "*.crans.${mainTld}";
dnsProvider = "rfc2136";
# Contient le serveur à contacter avec le protocole
# et le mot de passe
environmentFile = config.age.secrets.acme-env.path;
extraDomainNames =
lib.concatMap (tld: [
"*.crans.${tld}"
"crans.${tld}"
]) otherTld
++ [
"crans.${mainTld}"
];
group = config.services.nginx.group;
};
services = mkIf cfg.enable { services = mkIf cfg.enable {
anubis = { anubis = {
defaultOptions.group = "nginx"; defaultOptions.group = "nginx";
@ -141,8 +159,8 @@ in
BIND_NETWORK = "unix"; BIND_NETWORK = "unix";
METRICS_BIND = "/run/anubis/anubis-${vhostName}/anubis-${vhostName}-metrics.sock"; METRICS_BIND = "/run/anubis/anubis-${vhostName}/anubis-${vhostName}-metrics.sock";
TARGET = "unix:///run/nginx/nginx-${vhostName}.sock"; TARGET = "unix:///run/nginx/nginx-${vhostName}.sock";
COOKIE_DOMAIN = "crans.org"; COOKIE_DOMAIN = "crans.${mainTld}";
REDIRECT_DOMAINS = "${vhostName}.crans.org"; REDIRECT_DOMAINS = "${vhostName}.crans.${mainTld}";
SOCKET_MODE = "0660"; SOCKET_MODE = "0660";
# OpenGraph config # OpenGraph config
OG_PASSTHROUGH = vhostConfig.anubisOpenGraph; OG_PASSTHROUGH = vhostConfig.anubisOpenGraph;
@ -161,9 +179,10 @@ in
vhostName: vhostConfig: vhostName: vhostConfig:
let let
sslConf = { sslConf = {
enableACME = !vhostConfig.httpOnly;
forceSSL = !vhostConfig.httpOnly; forceSSL = !vhostConfig.httpOnly;
rejectSSL = vhostConfig.httpOnly; rejectSSL = vhostConfig.httpOnly;
useACMEHost = mkIf (!vhostConfig.httpOnly) "all.crans.all";
acmeRoot = null;
}; };
# Conf pour lhôte en entrée # Conf pour lhôte en entrée
@ -193,22 +212,23 @@ in
entryExtraConf; entryExtraConf;
# Les alias : vhostName × otherTld U serverAliases × allTld # Les alias : vhostName × otherTld U serverAliases × allTld
mkHostName = als: tld: if als == "." then "crans.${tld}" else "${als}.crans.${tld}";
aliases = aliases =
lib.foldr lib.foldr
( (
tld: acc: tld: acc:
acc acc
++ (lib.foldr (alias: acc: acc ++ [ "${alias}.crans.${tld}" ]) [ ++ (lib.foldr (alias: acc: acc ++ [ (mkHostName alias tld) ]) [
"${vhostName}.crans.${tld}" (mkHostName vhostName tld)
] vhostConfig.serverAliases) ] vhostConfig.serverAliases)
) )
(lib.foldr (alias: acc: acc ++ [ "${alias}.crans.${mainTld}" ]) [ ] vhostConfig.serverAliases) (lib.foldr (alias: acc: acc ++ [ (mkHostName alias mainTld) ]) [ ] vhostConfig.serverAliases)
otherTld; otherTld;
in in
{ {
# Configuration du service à proxy. # Configuration du service à proxy.
"${vhostName}" = vhostExtraConf // { "${vhostName}" = vhostExtraConf // {
serverName = "${vhostName}.crans.${mainTld}"; serverName = mkHostName vhostName mainTld;
locations."/" = mkIf (vhostConfig.proxyPass != null) { locations."/" = mkIf (vhostConfig.proxyPass != null) {
proxyPass = "http://${vhostConfig.proxyPass}"; proxyPass = "http://${vhostConfig.proxyPass}";
proxyWebsockets = vhostConfig.proxyWebsockets; proxyWebsockets = vhostConfig.proxyWebsockets;
@ -221,7 +241,7 @@ in
"${vhostName}-anubis" = mkIf (vhostConfig.anubisConfig != null) ( "${vhostName}-anubis" = mkIf (vhostConfig.anubisConfig != null) (
entryExtraConf entryExtraConf
// { // {
serverName = "${vhostName}.crans.${mainTld}"; serverName = mkHostName vhostName mainTld;
locations."/" = { locations."/" = {
proxyPass = "http://unix:/run/anubis/anubis-${vhostName}/socket.sock"; proxyPass = "http://unix:/run/anubis/anubis-${vhostName}/socket.sock";
proxyWebsockets = vhostConfig.proxyWebsockets; proxyWebsockets = vhostConfig.proxyWebsockets;