nix-config/lib/yggdrasil-hq.nix

41 lines
986 B
Nix
Raw Normal View History

2019-11-29 21:41:01 +01:00
{ config, lib, ... }:
2019-11-29 21:29:50 +01:00
with lib;
let
cfg = config.hq.yggdrasil;
2019-11-29 21:51:20 +01:00
hostNameHash = builtins.hashString "sha256" config.networking.hostName;
2019-11-29 21:41:01 +01:00
hextets = map (i: substring (4 * i) (4 * (i + 1)) hostNameHash) [ 0 1 2 3 ];
2019-11-29 21:29:50 +01:00
hostAddr = concatStringsSep ":" hextets;
2019-11-29 21:41:01 +01:00
in {
2019-11-29 21:29:50 +01:00
options = with types; {
hq.yggdrasil = {
2019-11-29 21:41:01 +01:00
enable =
mkEnableOption "Configure Yggdrasil access via the Yggdrasil router";
2019-11-29 21:29:50 +01:00
interface = mkOption {
type = nullOr str;
default = "eth0";
description = "Network interface to the C3D2 HQ ethernet";
};
};
};
2019-11-29 21:41:01 +01:00
config = mkIf cfg.enable {
networking.interfaces = {
2019-11-29 21:51:20 +01:00
"${cfg.interface}" = {
"ipv6" = {
addresses = [{
address = "310:5217:69c0:9afc:${hostAddr}";
prefixLength = 64;
}];
routes = [{
address = "200::";
prefixLength = 7;
via = "310:5217:69c0:9afc::1";
}];
};
2019-11-29 21:41:01 +01:00
};
2019-11-29 21:29:50 +01:00
};
};
}