From 814eae09ff808eaf50cfb377d07fc9acf868ef52 Mon Sep 17 00:00:00 2001
From: tv <tv@shackspace.de>
Date: Thu, 16 Jul 2015 17:59:43 +0200
Subject: [PATCH] 3 tv.identity: hosts can have subdomains

---
 3modules/tv/identity.nix | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/3modules/tv/identity.nix b/3modules/tv/identity.nix
index c3c2f17bf..e0cd46c06 100644
--- a/3modules/tv/identity.nix
+++ b/3modules/tv/identity.nix
@@ -1,4 +1,4 @@
-{ lib, ... }:
+{ config, lib, ... }:
 
 with lib;
 let
@@ -6,7 +6,7 @@ let
 
   out = {
     options.tv.identity = api;
-    #config = mkIf cfg.enable imp;
+    config = mkIf cfg.enable imp;
   };
 
   api = {
@@ -22,6 +22,8 @@ let
           #dc = "cac";
           dc = "tv";
           fqdn = "cd.retiolum";
+          subdomains = [
+          ];
           addr = "10.243.113.222";
           #addr6 = "42:4522:25f8:36bb:8ccb:0150:231a:2af3";
           #internet-addr = "162.219.5.183";
@@ -31,6 +33,8 @@ let
           #dc = "cac";
           dc = "tv";
           fqdn = "mkdir.retiolum";
+          subdomains = [
+          ];
           addr = "10.243.113.223";
           cores = 1;
         };
@@ -38,6 +42,8 @@ let
           #dc = "gg";
           dc = "tv";
           fqdn = "nomic.retiolum";
+          subdomains = [
+          ];
           addr = "10.243.0.110";
           cores = 2;
         };
@@ -45,6 +51,8 @@ let
           #dc = "cac";
           dc = "tv";
           fqdn = "rmdir.retiolum";
+          subdomains = [
+          ];
           addr = "10.243.113.224";
           #addr = "42:4522:25f8:36bb:8ccb:0150:231a:2af5";
           cores = 1;
@@ -53,6 +61,8 @@ let
           #dc = "gg";
           dc = "tv";
           fqdn = "wu.retiolum";
+          subdomains = [
+          ];
           addr = "10.243.13.37";
           cores = 8;
         };
@@ -60,8 +70,15 @@ let
     };
   };
 
-  #imp = {
-  #};
+  imp = {
+    networking.extraHosts =
+      let
+        f = name: { addr, fqdn, subdomains, ... }: ''
+          ${addr} ${toString (map (s: "${s}.${name} ${s}.${fqdn}") subdomains)}
+        '';
+      in
+      concatStringsSep "\n" (mapAttrsToList f cfg.hosts);
+  };
 
 in
 out