summaryrefslogtreecommitdiffstats
path: root/krebs/3modules/hosts.nix
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2019-01-21 11:17:36 +0100
committermakefu <github@syntax-fehler.de>2019-01-21 11:17:36 +0100
commit93f1ce72844bf2bc63cd919c38c3323a6f8f14ef (patch)
tree8c2f5d6da31608387a69fea93355b8f1ecd326ef /krebs/3modules/hosts.nix
parent6af865b1e6bba605f11f5d4c6cfb7e92b4f01666 (diff)
parentaf0463b23493d8c31ce725beb8ff5a2fd0398001 (diff)
Merge branch 'master' of http://cgit.ni/stockholm
Diffstat (limited to 'krebs/3modules/hosts.nix')
-rw-r--r--krebs/3modules/hosts.nix36
1 files changed, 36 insertions, 0 deletions
diff --git a/krebs/3modules/hosts.nix b/krebs/3modules/hosts.nix
new file mode 100644
index 000000000..a95557b3d
--- /dev/null
+++ b/krebs/3modules/hosts.nix
@@ -0,0 +1,36 @@
+with import <stockholm/lib>;
+{ config, ... }: let
+ # TODO dedup functions with ./retiolum-hosts.nix
+ check = hostname: any (domain: hasSuffix ".${domain}" hostname) domains;
+ domains = attrNames (filterAttrs (_: eq "hosts") config.krebs.dns.providers);
+in {
+
+ options = {
+ krebs.hosts = mkOption {
+ default = {};
+ type = types.attrsOf types.host;
+ };
+ };
+
+ config = {
+ networking.extraHosts =
+ concatStringsSep
+ "\n"
+ (flatten
+ (mapAttrsToList
+ (hostname: host:
+ mapAttrsToList
+ (netname: net: let
+ aliases = longs ++ shorts;
+ longs = filter check net.aliases;
+ shorts = let s = ".${config.krebs.dns.search-domain}"; in
+ map (removeSuffix s) (filter (hasSuffix s) longs);
+ in
+ optionals
+ (aliases != [])
+ (map (addr: "${addr} ${toString aliases}") net.addrs))
+ (filterAttrs (name: host: host.aliases != []) host.nets))
+ config.krebs.hosts));
+ };
+
+}