summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--krebs/3modules/default.nix2
-rw-r--r--krebs/3modules/tv/default.nix22
-rw-r--r--lib/default.nix46
-rw-r--r--lib/types.nix1
-rw-r--r--tv/2configs/default.nix2
5 files changed, 60 insertions, 13 deletions
diff --git a/krebs/3modules/default.nix b/krebs/3modules/default.nix
index d24cea1a2..a46b8af15 100644
--- a/krebs/3modules/default.nix
+++ b/krebs/3modules/default.nix
@@ -67,7 +67,7 @@ let
# TODO search-domains :: listOf hostname
search-domain = mkOption {
type = types.hostname;
- default = "retiolum";
+ default = "r";
};
zone-head-config = mkOption {
type = with types; attrsOf str;
diff --git a/krebs/3modules/tv/default.nix b/krebs/3modules/tv/default.nix
index 48b110fac..2da38e08d 100644
--- a/krebs/3modules/tv/default.nix
+++ b/krebs/3modules/tv/default.nix
@@ -12,7 +12,7 @@ with import <stockholm/lib>;
nets = {
retiolum = {
ip4.addr = "10.243.21.1";
- ip6.addr = "42:0:0:0:0:0:0:2101";
+ ip6.addr = "42::2101";
aliases = [
"alnus.r"
];
@@ -53,7 +53,7 @@ with import <stockholm/lib>;
retiolum = {
via = config.krebs.hosts.caxi.nets.internet;
ip4.addr = "10.243.113.226";
- ip6.addr = "42:4522:25f8:36bb:8ccb:0150:231a:2af6";
+ ip6.addr = "42:4522:25f8:36bb:8ccb:150:231a:2af6";
aliases = [
"caxi.r"
];
@@ -94,7 +94,7 @@ with import <stockholm/lib>;
retiolum = {
via = config.krebs.hosts.cd.nets.internet;
ip4.addr = "10.243.113.222";
- ip6.addr = "42:4522:25f8:36bb:8ccb:0150:231a:2af3";
+ ip6.addr = "42:4522:25f8:36bb:8ccb:150:231a:2af3";
aliases = [
"cd.r"
"cgit.cd.r"
@@ -129,7 +129,7 @@ with import <stockholm/lib>;
};
retiolum = {
ip4.addr = "10.243.13.39";
- ip6.addr = "42:0:0:0:0:0:0:1339";
+ ip6.addr = "42::1339";
aliases = [
"ju.r"
];
@@ -164,7 +164,7 @@ with import <stockholm/lib>;
};
retiolum = {
ip4.addr = "10.243.166.2";
- ip6.addr = "42:0b9d:6660:d07c:2bb7:4e91:1a01:2e7d";
+ ip6.addr = "42:b9d:6660:d07c:2bb7:4e91:1a01:2e7d";
aliases = [
"kaepsele.r"
];
@@ -187,7 +187,7 @@ with import <stockholm/lib>;
nets = {
retiolum = {
ip4.addr = "10.243.20.1";
- ip6.addr = "42:0:0:0:0:0:0:2001";
+ ip6.addr = "42::2001";
aliases = [
"mu.r"
];
@@ -226,7 +226,7 @@ with import <stockholm/lib>;
retiolum = {
via = config.krebs.hosts.ni.nets.internet;
ip4.addr = "10.243.113.223";
- ip6.addr = "42:4522:25f8:36bb:8ccb:0150:231a:2af4";
+ ip6.addr = "42:4522:25f8:36bb:8ccb:150:231a:2af4";
aliases = [
"ni.r"
"cgit.ni.r"
@@ -260,7 +260,7 @@ with import <stockholm/lib>;
};
retiolum = {
ip4.addr = "10.243.0.110";
- ip6.addr = "42:02d5:733f:d6da:c0f5:2bb7:2b18:09ec";
+ ip6.addr = "42:2d5:733f:d6da:c0f5:2bb7:2b18:9ec";
aliases = [
"nomic.r"
"cgit.nomic.r"
@@ -318,7 +318,7 @@ with import <stockholm/lib>;
};
retiolum = {
ip4.addr = "10.243.13.37";
- ip6.addr = "42:0:0:0:0:0:0:1337";
+ ip6.addr = "42::1337";
aliases = [
"wu.r"
"cgit.wu.r"
@@ -355,7 +355,7 @@ with import <stockholm/lib>;
};
retiolum = {
ip4.addr = "10.243.13.38";
- ip6.addr = "42:0:0:0:0:0:0:1338";
+ ip6.addr = "42::1338";
aliases = [
"xu.r"
];
@@ -387,7 +387,7 @@ with import <stockholm/lib>;
};
retiolum = {
ip4.addr = "10.243.13.40";
- ip6.addr = "42:0:0:0:0:0:0:1340";
+ ip6.addr = "42::1340";
aliases = [
"zu.r"
];
diff --git a/lib/default.nix b/lib/default.nix
index 7e61c9413..9399a0107 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -41,6 +41,52 @@ let
indent = replaceChars ["\n"] ["\n "];
+ # https://tools.ietf.org/html/rfc5952
+ normalize-ip6-addr =
+ let
+ max-run-0 =
+ let
+ both = v: { off = v; pos = v; };
+ gt = a: b: a.pos - a.off > b.pos - b.off;
+
+ chkmax = ctx: {
+ cur = both (ctx.cur.pos + 1);
+ max = if gt ctx.cur ctx.max then ctx.cur else ctx.max;
+ };
+
+ incpos = ctx: recursiveUpdate ctx {
+ cur.pos = ctx.cur.pos + 1;
+ };
+
+ f = ctx: blk: (if blk == "0" then incpos else chkmax) ctx;
+ z = { cur = both 0; max = both 0; };
+ in
+ blks: (chkmax (foldl' f z blks)).max;
+
+ group-zeros = a:
+ let
+ blks = splitString ":" a;
+ max = max-run-0 blks;
+ lhs = take max.off blks;
+ rhs = drop max.pos blks;
+ in
+ if max.pos == 0
+ then a
+ else "${concatStringsSep ":" lhs}::${concatStringsSep ":" rhs}";
+
+ drop-leading-zeros =
+ let
+ f = block:
+ let
+ res = match "0*(.+)" block;
+ in
+ if res == null
+ then block # empty block
+ else elemAt res 0;
+ in
+ a: concatStringsSep ":" (map f (splitString ":" a));
+ in
+ a: toLower (group-zeros (drop-leading-zeros a));
};
in
diff --git a/lib/types.nix b/lib/types.nix
index 8a3c76483..f511541bd 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -103,6 +103,7 @@ rec {
options = {
addr = mkOption {
type = addr6;
+ apply = lib.normalize-ip6-addr;
};
prefix = mkOption ({
type = str; # TODO routing prefix (CIDR)
diff --git a/tv/2configs/default.nix b/tv/2configs/default.nix
index 618dcdccb..d070273e1 100644
--- a/tv/2configs/default.nix
+++ b/tv/2configs/default.nix
@@ -14,7 +14,7 @@ with import <stockholm/lib>;
stockholm.file = "/home/tv/stockholm";
nixpkgs.git = {
url = https://github.com/NixOS/nixpkgs;
- ref = "69d9061908162bd973fcf34d0fc6dc9d9f8cf9ed"; # nixos-17.03
+ ref = "33bd699008c8cb3d92a379de99aa1c65e6b1f8d1"; # nixos-17.03
};
} // optionalAttrs host.secure {
secrets-master.file = "/home/tv/secrets/master";