nix/profiles/vogon/guest.nix

58 lines
No EOL
1.7 KiB
Nix

{ config, lib, network, name, ... }:
let
inherit (lib) mkOption types;
cfg = config.vogon;
node = network.infra.nodes.${name};
in
{
options.vogon = {
networking = {
last-octet = mkOption {
type = types.listOf (types.ints.between 161 174);
description = ''
Liste des derniers octets de l'IPv4 de la machine.
'';
example = [ 163 165 ];
};
wan-mac = mkOption {
type = types.str;
description = ''
Adresse MAC de l'interface réseau WAN
qui portera l'IPv4 interne.
'';
example = "BC:24:11:B7:AE:80";
};
ssh-octets = mkOption {
type = types.listOf (types.ints.between 161 174);
default = [ (builtins.head cfg.networking.last-octet) ];
defaultText = "[ (first element of last-octet) ]";
description = ''
Liste des octets à utiliser pour la configuration SSH.
Par défaut, utilise le premier élément de last-octet.
'';
example = [ 163 165 ];
};
};
};
config = {
systemd.network = {
links."10-wan" = {
matchConfig.MACAddress = cfg.networking.wan-mac;
linkConfig.Name = "wan";
};
networks."10-wan" = {
matchConfig.Name = "wan";
address = map (octet: "193.54.193.${toString octet}/28") cfg.networking.last-octet;
routes = [ { Gateway = "193.54.193.174"; } ];
linkConfig.RequiredForOnline = "routable";
};
};
services.openssh.listenAddresses = [
{ addr = node.ipv4; port = 22; }
{ addr = node.ipv6; port = 22; }
] ++ map (octet: { addr = "193.54.193.${toString octet}"; port = 22; }) cfg.networking.ssh-octets;
};
}