]>
Commit | Line | Data |
---|---|---|
1 | { | |
2 | inputs.environment.url = "path:../environment"; | |
3 | outputs = { self, environment }: { | |
4 | nixosModule = self.nixosModules.chatons; | |
5 | nixosModules.chatons = { config, lib, pkgs, nodes, ... }: | |
6 | let | |
7 | concatValue = value: if lib.isList value then builtins.concatStringsSep "," value else builtins.toString value; | |
8 | toProperties = properties: builtins.concatStringsSep "\n" ( | |
9 | lib.collect | |
10 | (p: !(lib.isAttrs p)) | |
11 | (lib.mapAttrsRecursive | |
12 | (path: value: builtins.concatStringsSep "." (builtins.filter (f: f != "") path) + " = " + (concatValue value)) | |
13 | properties)); | |
14 | before = name: { | |
15 | "${name}" = { | |
16 | status.level = "OK"; | |
17 | status.description = "OK"; | |
18 | install.type = "PACKAGE"; | |
19 | registration.load = "OPEN"; | |
20 | }; | |
21 | host = { | |
22 | name = "Hetzner"; | |
23 | server.type = "PHYSICAL"; | |
24 | provider.type = "HOSTEDSERVER"; | |
25 | server.distribution = "NixOS"; | |
26 | country.name = "Allemagne"; | |
27 | country.code = "DE"; | |
28 | }; | |
29 | }; | |
30 | after = name: { | |
31 | file = { | |
32 | class = name; | |
33 | protocol = "ChatonsInfos-0.5"; | |
34 | generator = "Nix derivation"; | |
35 | }; | |
36 | "${name}" = { | |
37 | legal.url = "https://www.immae.eu/mentions.html"; | |
38 | guide.technical = "https://git.immae.eu/cgit/perso/Immae/Config/Nix.git/"; | |
39 | contact.url = "https://www.immae.eu/contacts_fr.html"; | |
40 | contact.email = config.myEnv.tools.contact; | |
41 | startdate = "01/01/2019"; | |
42 | }; | |
43 | }; | |
44 | organization = { | |
45 | file = { | |
46 | class = "organization"; | |
47 | protocol = "ChatonsInfos-0.5"; | |
48 | datetime = "2021-01-11T22:23:00"; | |
49 | generator = "Nix derivation"; | |
50 | }; | |
51 | organization = { | |
52 | country.name = "France"; | |
53 | country.code = "FR"; | |
54 | name = "ImmaeEu"; | |
55 | description = "ImmaeEu est un CHATONS des Alpes-Maritimes"; | |
56 | website = "https://www.immae.eu"; | |
57 | logo = "https://assets.immae.eu/logo.jpg"; | |
58 | socialnetworks = { | |
59 | diaspora = "https://diaspora.immae.eu/people/1a185f29cc76cb35"; | |
60 | facebook = "https://www.facebook.com/ismael.bouya"; | |
61 | mastodon = "https://mastodon.immae.eu/@immae"; | |
62 | peertube = "https://peertube.immae.eu/accounts/immae/"; | |
63 | twitter = "https://twitter.com/_immae"; | |
64 | }; | |
65 | chatrooms = { | |
66 | xmpp = "ismael@immae.fr"; | |
67 | irc = "immae@freenode"; | |
68 | matrix = "#support:immae.eu"; | |
69 | }; | |
70 | contact.url = "https://www.immae.eu/contacts_fr.html"; | |
71 | contact.email = config.myEnv.tools.contact; | |
72 | legal.url = "https://www.immae.eu/mentions.html"; | |
73 | guide.technical = "https://git.immae.eu/cgit/perso/Immae/Config/Nix.git/"; | |
74 | guide.user = "https://www.immae.eu/docs"; | |
75 | status.level = "ACTIVE"; | |
76 | status.description = "En activité"; | |
77 | startdate = "01/01/2019"; | |
78 | type = "COMPANY"; | |
79 | owner = { | |
80 | logo = "https://assets.immae.eu/logo.jpg"; | |
81 | name = "Ismaël Bouya"; | |
82 | website = "https://www.immae.eu"; | |
83 | }; | |
84 | memberof.chatons = { | |
85 | startdate = "01/07/2019"; | |
86 | status.level = "ACTIVE"; | |
87 | status.description = "Participe au collectif"; | |
88 | }; | |
89 | }; | |
90 | }; | |
91 | subname = v: if v.published or true then "subs" else "subs-hidden"; | |
92 | toOrganizationProperties = name: pkgs.writeText name (toProperties organization + "\n" + ( | |
93 | builtins.concatStringsSep "\n" (lib.mapAttrsToList | |
94 | (n: v: "${subname v}.${n} = https://www.immae.eu/.well-known/chatonsinfos/service-${n}.properties") mergedServices | |
95 | )) + "\n" + ( | |
96 | builtins.concatStringsSep "\n" (lib.mapAttrsToList | |
97 | (n: v: "subs.hosting-${n} = https://www.immae.eu/.well-known/chatonsinfos/hosting-${n}.properties") mergedHostings | |
98 | ))); | |
99 | toHostingProperties = name: content: pkgs.writeText name (toProperties (lib.recursiveUpdate (before "hosting") (lib.recursiveUpdate content (after "hosting")))); | |
100 | toServiceProperties = name: content: pkgs.writeText name (toProperties (lib.recursiveUpdate (before "service") (lib.recursiveUpdate content (after "service")))); | |
101 | ||
102 | cfg = config.myServices.chatonsProperties; | |
103 | mergedServices = lib.foldr (v: o: lib.recursiveUpdate o v) {} (lib.mapAttrsToList (k: v: if (v.config.myServices or {}) ? "chatonsProperties" then v.config.myServices.chatonsProperties.services else {}) nodes); | |
104 | mergedHostings = lib.foldr (v: o: lib.recursiveUpdate o v) {} (lib.mapAttrsToList (k: v: if (v.config.myServices or {}) ? "chatonsProperties" then v.config.myServices.chatonsProperties.hostings else {}) nodes); | |
105 | in { | |
106 | imports = [ | |
107 | environment.nixosModule | |
108 | ]; | |
109 | options.myServices.chatonsProperties.organization = 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.services = 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 | options.myServices.chatonsProperties.hostings = lib.mkOption { | |
124 | type = lib.types.attrsOf lib.types.unspecified; | |
125 | default = {}; | |
126 | description = '' | |
127 | nested attrs of strings or arrays of strings | |
128 | ''; | |
129 | }; | |
130 | options.myServices.chatonsProperties.propertiesPath = lib.mkOption { | |
131 | type = lib.types.package; | |
132 | readOnly = true; | |
133 | default = pkgs.runCommand "chatons" {} '' | |
134 | mkdir -p $out | |
135 | cp ${toOrganizationProperties "immae-eu"} $out/immae-eu.properties | |
136 | ${builtins.concatStringsSep "\n" (lib.mapAttrsToList (n: c: "cp ${toHostingProperties n c} $out/hosting-${n}.properties") mergedHostings)} | |
137 | ${builtins.concatStringsSep "\n" (lib.mapAttrsToList (n: c: "cp ${toServiceProperties n c} $out/service-${n}.properties") mergedServices)} | |
138 | ''; | |
139 | }; | |
140 | }; | |
141 | }; | |
142 | } |