]> git.immae.eu Git - perso/Immae/Config/Nix.git/blob - modules/private/chatons.nix
Add chatons infos
[perso/Immae/Config/Nix.git] / modules / private / chatons.nix
1 { config, lib, pkgs, nodes, ... }:
2 let
3 concatValue = value: if lib.isList value then builtins.concatStringsSep "," value else builtins.toString value;
4 toProperties = properties: builtins.concatStringsSep "\n" (
5 lib.collect
6 (p: !(lib.isAttrs p))
7 (lib.mapAttrsRecursive
8 (path: value: builtins.concatStringsSep "." (builtins.filter (f: f != "") path) + " = " + (concatValue value))
9 properties));
10 before = name: {
11 "${name}" = {
12 status.level = "OK";
13 status.description = "OK";
14 install.type = "PACKAGE";
15 registration.load = "OPEN";
16 };
17 host = {
18 name = "Hetzner";
19 server.type = "PHYSICAL";
20 provider.type = "HOSTEDSERVER";
21 server.distribution = "NixOS";
22 country.name = "Allemagne";
23 country.code = "DE";
24 };
25 };
26 after = name: {
27 file = {
28 class = name;
29 protocol = "ChatonsInfos-0.5";
30 generator = "Nix derivation";
31 };
32 "${name}" = {
33 legal.url = "https://www.immae.eu/mentions.html";
34 guide.technical = "https://git.immae.eu/cgit/perso/Immae/Config/Nix.git/";
35 contact.url = "https://www.immae.eu/contacts_fr.html";
36 contact.email = config.myEnv.tools.contact;
37 startdate = "01/01/2019";
38 };
39 };
40 organization = {
41 file = {
42 class = "organization";
43 protocol = "ChatonsInfos-0.5";
44 datetime = "2021-01-11T22:23:00";
45 generator = "Nix derivation";
46 };
47 organization = {
48 country.name = "France";
49 country.code = "FR";
50 name = "ImmaeEu";
51 description = "ImmaeEu est un CHATONS des Alpes-Maritimes";
52 website = "https://www.immae.eu";
53 logo = "https://assets.immae.eu/logo.jpg";
54 socialnetworks = {
55 diaspora = "https://diaspora.immae.eu/people/1a185f29cc76cb35";
56 facebook = "https://www.facebook.com/ismael.bouya";
57 mastodon = "https://mastodon.immae.eu/@immae";
58 peertube = "https://peertube.immae.eu/accounts/immae/";
59 twitter = "https://twitter.com/_immae";
60 };
61 chatrooms = {
62 xmpp = "ismael@immae.fr";
63 irc = "immae@freenode";
64 matrix = "#support:immae.eu";
65 };
66 contact.url = "https://www.immae.eu/contacts_fr.html";
67 contact.email = config.myEnv.tools.contact;
68 legal.url = "https://www.immae.eu/mentions.html";
69 guide.technical = "https://git.immae.eu/cgit/perso/Immae/Config/Nix.git/";
70 guide.user = "https://www.immae.eu/docs";
71 status.level = "ACTIVE";
72 status.description = "En activité";
73 startdate = "01/01/2019";
74 type = "COMPANY";
75 owner = {
76 logo = "https://assets.immae.eu/logo.jpg";
77 name = "Ismaël Bouya";
78 website = "https://www.immae.eu";
79 };
80 memberof.chatons = {
81 startdate = "01/07/2019";
82 status.level = "ACTIVE";
83 status.description = "Participe au collectif";
84 };
85 };
86 };
87 toOrganizationProperties = name: pkgs.writeText name (toProperties organization + "\n" + (
88 builtins.concatStringsSep "\n" (lib.mapAttrsToList
89 (n: v: "subs.${n} = https://www.immae.eu/.well-known/chatonsinfos/service-${n}.properties") mergedServices
90 )) + "\n" + (
91 builtins.concatStringsSep "\n" (lib.mapAttrsToList
92 (n: v: "subs.hosting-${n} = https://www.immae.eu/.well-known/chatonsinfos/hosting-${n}.properties") mergedHostings
93 )));
94 toHostingProperties = name: content: pkgs.writeText name (toProperties (lib.recursiveUpdate (before "hosting") (lib.recursiveUpdate content (after "hosting"))));
95 toServiceProperties = name: content: pkgs.writeText name (toProperties (lib.recursiveUpdate (before "service") (lib.recursiveUpdate content (after "service"))));
96
97 cfg = config.myServices.chatonsProperties;
98 mergedServices = lib.foldr (v: o: lib.recursiveUpdate o v) {} (lib.mapAttrsToList (k: v: v.config.myServices.chatonsProperties.services) nodes);
99 mergedHostings = lib.foldr (v: o: lib.recursiveUpdate o v) {} (lib.mapAttrsToList (k: v: v.config.myServices.chatonsProperties.hostings) nodes);
100 in {
101 options.myServices.chatonsProperties.enable = lib.mkEnableOption "Enable chatons properties";
102 options.myServices.chatonsProperties.organization = lib.mkOption {
103 type = lib.types.attrsOf lib.types.unspecified;
104 default = {};
105 description = ''
106 nested attrs of strings or arrays of strings
107 '';
108 };
109 options.myServices.chatonsProperties.services = lib.mkOption {
110 type = lib.types.attrsOf lib.types.unspecified;
111 default = {};
112 description = ''
113 nested attrs of strings or arrays of strings
114 '';
115 };
116 options.myServices.chatonsProperties.hostings = lib.mkOption {
117 type = lib.types.attrsOf lib.types.unspecified;
118 default = {};
119 description = ''
120 nested attrs of strings or arrays of strings
121 '';
122 };
123 config = lib.mkIf cfg.enable {
124 myServices.chatonsProperties.hostings.infogerance = {
125 file.datetime = "2022-08-27T18:50:00";
126 hosting = {
127 name = "Infogérance";
128 description = "Administration de serveurs";
129 website = "https://www.immae.eu/";
130 logo = "https://assets.immae.eu/logo.jpg";
131 type = "HOSTEDSERVER";
132 status.level = "OK";
133 status.description = "OK";
134 registration.load = "OPEN";
135 install.type = "PACKAGE";
136 };
137 };
138 services.websites.env.production.vhostConfs.immae_production.extraConfig = let
139 chatons = pkgs.runCommand "chatons" {} ''
140 mkdir -p $out
141 cp ${toOrganizationProperties "immae-eu"} $out/immae-eu.properties
142 ${builtins.concatStringsSep "\n" (lib.mapAttrsToList (n: c: "cp ${toHostingProperties n c} $out/hosting-${n}.properties") mergedHostings)}
143 ${builtins.concatStringsSep "\n" (lib.mapAttrsToList (n: c: "cp ${toServiceProperties n c} $out/service-${n}.properties") mergedServices)}
144 '';
145 in [
146 ''
147 Alias /.well-known/chatonsinfos ${chatons}
148 <Directory ${chatons}>
149 Options Indexes FollowSymLinks MultiViews Includes
150 AllowOverride None
151 Require all granted
152 </Directory>
153 ''
154 ];
155 };
156 }