--- /dev/null
+{ config, lib, pkgs, nodes, ... }:
+let
+ concatValue = value: if lib.isList value then builtins.concatStringsSep "," value else builtins.toString value;
+ toProperties = properties: builtins.concatStringsSep "\n" (
+ lib.collect
+ (p: !(lib.isAttrs p))
+ (lib.mapAttrsRecursive
+ (path: value: builtins.concatStringsSep "." (builtins.filter (f: f != "") path) + " = " + (concatValue value))
+ properties));
+ before = name: {
+ "${name}" = {
+ status.level = "OK";
+ status.description = "OK";
+ install.type = "PACKAGE";
+ registration.load = "OPEN";
+ };
+ host = {
+ name = "Hetzner";
+ server.type = "PHYSICAL";
+ provider.type = "HOSTEDSERVER";
+ server.distribution = "NixOS";
+ country.name = "Allemagne";
+ country.code = "DE";
+ };
+ };
+ after = name: {
+ file = {
+ class = name;
+ protocol = "ChatonsInfos-0.5";
+ generator = "Nix derivation";
+ };
+ "${name}" = {
+ legal.url = "https://www.immae.eu/mentions.html";
+ guide.technical = "https://git.immae.eu/cgit/perso/Immae/Config/Nix.git/";
+ contact.url = "https://www.immae.eu/contacts_fr.html";
+ contact.email = config.myEnv.tools.contact;
+ startdate = "01/01/2019";
+ };
+ };
+ organization = {
+ file = {
+ class = "organization";
+ protocol = "ChatonsInfos-0.5";
+ datetime = "2021-01-11T22:23:00";
+ generator = "Nix derivation";
+ };
+ organization = {
+ country.name = "France";
+ country.code = "FR";
+ name = "ImmaeEu";
+ description = "ImmaeEu est un CHATONS des Alpes-Maritimes";
+ website = "https://www.immae.eu";
+ logo = "https://assets.immae.eu/logo.jpg";
+ socialnetworks = {
+ diaspora = "https://diaspora.immae.eu/people/1a185f29cc76cb35";
+ facebook = "https://www.facebook.com/ismael.bouya";
+ mastodon = "https://mastodon.immae.eu/@immae";
+ peertube = "https://peertube.immae.eu/accounts/immae/";
+ twitter = "https://twitter.com/_immae";
+ };
+ chatrooms = {
+ xmpp = "ismael@immae.fr";
+ irc = "immae@freenode";
+ matrix = "#support:immae.eu";
+ };
+ contact.url = "https://www.immae.eu/contacts_fr.html";
+ contact.email = config.myEnv.tools.contact;
+ legal.url = "https://www.immae.eu/mentions.html";
+ guide.technical = "https://git.immae.eu/cgit/perso/Immae/Config/Nix.git/";
+ guide.user = "https://www.immae.eu/docs";
+ status.level = "ACTIVE";
+ status.description = "En activité";
+ startdate = "01/01/2019";
+ type = "COMPANY";
+ owner = {
+ logo = "https://assets.immae.eu/logo.jpg";
+ name = "Ismaël Bouya";
+ website = "https://www.immae.eu";
+ };
+ memberof.chatons = {
+ startdate = "01/07/2019";
+ status.level = "ACTIVE";
+ status.description = "Participe au collectif";
+ };
+ };
+ };
+ toOrganizationProperties = name: pkgs.writeText name (toProperties organization + "\n" + (
+ builtins.concatStringsSep "\n" (lib.mapAttrsToList
+ (n: v: "subs.${n} = https://www.immae.eu/.well-known/chatonsinfos/service-${n}.properties") mergedServices
+ )) + "\n" + (
+ builtins.concatStringsSep "\n" (lib.mapAttrsToList
+ (n: v: "subs.hosting-${n} = https://www.immae.eu/.well-known/chatonsinfos/hosting-${n}.properties") mergedHostings
+ )));
+ toHostingProperties = name: content: pkgs.writeText name (toProperties (lib.recursiveUpdate (before "hosting") (lib.recursiveUpdate content (after "hosting"))));
+ toServiceProperties = name: content: pkgs.writeText name (toProperties (lib.recursiveUpdate (before "service") (lib.recursiveUpdate content (after "service"))));
+
+ cfg = config.myServices.chatonsProperties;
+ mergedServices = lib.foldr (v: o: lib.recursiveUpdate o v) {} (lib.mapAttrsToList (k: v: v.config.myServices.chatonsProperties.services) nodes);
+ mergedHostings = lib.foldr (v: o: lib.recursiveUpdate o v) {} (lib.mapAttrsToList (k: v: v.config.myServices.chatonsProperties.hostings) nodes);
+in {
+ options.myServices.chatonsProperties.enable = lib.mkEnableOption "Enable chatons properties";
+ options.myServices.chatonsProperties.organization = lib.mkOption {
+ type = lib.types.attrsOf lib.types.unspecified;
+ default = {};
+ description = ''
+ nested attrs of strings or arrays of strings
+ '';
+ };
+ options.myServices.chatonsProperties.services = lib.mkOption {
+ type = lib.types.attrsOf lib.types.unspecified;
+ default = {};
+ description = ''
+ nested attrs of strings or arrays of strings
+ '';
+ };
+ options.myServices.chatonsProperties.hostings = lib.mkOption {
+ type = lib.types.attrsOf lib.types.unspecified;
+ default = {};
+ description = ''
+ nested attrs of strings or arrays of strings
+ '';
+ };
+ config = lib.mkIf cfg.enable {
+ myServices.chatonsProperties.hostings.infogerance = {
+ file.datetime = "2022-08-27T18:50:00";
+ hosting = {
+ name = "Infogérance";
+ description = "Administration de serveurs";
+ website = "https://www.immae.eu/";
+ logo = "https://assets.immae.eu/logo.jpg";
+ type = "HOSTEDSERVER";
+ status.level = "OK";
+ status.description = "OK";
+ registration.load = "OPEN";
+ install.type = "PACKAGE";
+ };
+ };
+ services.websites.env.production.vhostConfs.immae_production.extraConfig = let
+ chatons = pkgs.runCommand "chatons" {} ''
+ mkdir -p $out
+ cp ${toOrganizationProperties "immae-eu"} $out/immae-eu.properties
+ ${builtins.concatStringsSep "\n" (lib.mapAttrsToList (n: c: "cp ${toHostingProperties n c} $out/hosting-${n}.properties") mergedHostings)}
+ ${builtins.concatStringsSep "\n" (lib.mapAttrsToList (n: c: "cp ${toServiceProperties n c} $out/service-${n}.properties") mergedServices)}
+ '';
+ in [
+ ''
+ Alias /.well-known/chatonsinfos ${chatons}
+ <Directory ${chatons}>
+ Options Indexes FollowSymLinks MultiViews Includes
+ AllowOverride None
+ Require all granted
+ </Directory>
+ ''
+ ];
+ };
+}