add guest network (now with custom mac address generators!)
Signed-off-by: ahuston-0 <aliceghuston@gmail.com>
This commit is contained in:
parent
cc702cb5fe
commit
d29b2ecbab
@ -57,5 +57,30 @@
|
|||||||
# type:
|
# type:
|
||||||
# fileList :: Path -> String -> [Path]
|
# fileList :: Path -> String -> [Path]
|
||||||
fileList = dir: map (file: dir + "/${file}") (ls dir);
|
fileList = dir: map (file: dir + "/${file}") (ls dir);
|
||||||
|
|
||||||
|
# constructs a mac address from a string's hash
|
||||||
|
#
|
||||||
|
# args:
|
||||||
|
# hashable: the string to hash
|
||||||
|
#
|
||||||
|
# type:
|
||||||
|
# strToMac :: String -> String
|
||||||
|
strToMac =
|
||||||
|
hashable:
|
||||||
|
let
|
||||||
|
# computes sha512 hash of input
|
||||||
|
hashStr = builtins.hashString "sha512" hashable;
|
||||||
|
# grabs first 12 letters of hash
|
||||||
|
hashSub = start: builtins.substring start 2 (builtins.substring 0 12 hashStr);
|
||||||
|
# joins list of strings with a delimiter between
|
||||||
|
joiner =
|
||||||
|
delim: arr:
|
||||||
|
builtins.foldl' (
|
||||||
|
a: b: lib.concatStrings ([ a ] ++ (lib.optionals (a != "") [ delim ]) ++ [ b ])
|
||||||
|
) "" arr;
|
||||||
|
# generates a list of indexes for the hash
|
||||||
|
starts = builtins.genList (x: x * 2) 6;
|
||||||
|
in
|
||||||
|
joiner ":" (map hashSub starts);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -5,15 +5,18 @@ rec {
|
|||||||
lib.mapAttrs (
|
lib.mapAttrs (
|
||||||
host:
|
host:
|
||||||
{
|
{
|
||||||
ipv4,
|
address,
|
||||||
|
gateway,
|
||||||
machine-id,
|
machine-id,
|
||||||
server ? false,
|
server ? false,
|
||||||
}:
|
}:
|
||||||
genMicroVM host ipv4 "x86_64-linux" machine-id (if server then server-config else agent-config)
|
genMicroVM host address gateway "x86_64-linux" machine-id (
|
||||||
|
if server then server-config else agent-config
|
||||||
|
)
|
||||||
) vms;
|
) vms;
|
||||||
|
|
||||||
genMicroVM =
|
genMicroVM =
|
||||||
hostName: ipv4: _system: machine-id: vm-config:
|
hostName: address: gateway: _system: machine-id: vm-config:
|
||||||
# microvm refers to microvm.nixosModules
|
# microvm refers to microvm.nixosModules
|
||||||
|
|
||||||
# {
|
# {
|
||||||
@ -44,32 +47,47 @@ rec {
|
|||||||
text = machine-id + "\n";
|
text = machine-id + "\n";
|
||||||
};
|
};
|
||||||
|
|
||||||
microvm.shares = [
|
networking.hostName = hostName;
|
||||||
{
|
|
||||||
source = "/nix/store";
|
|
||||||
mountPoint = "/nix/.ro-store";
|
|
||||||
tag = "ro-store";
|
|
||||||
proto = "virtiofs";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# On the host
|
|
||||||
source = "/var/lib/microvms/${hostName}/journal";
|
|
||||||
# In the MicroVM
|
|
||||||
mountPoint = "/var/log/journal";
|
|
||||||
tag = "journal";
|
|
||||||
proto = "virtiofs";
|
|
||||||
socket = "journal.sock";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
networking = {
|
microvm = {
|
||||||
inherit hostName;
|
interfaces = [
|
||||||
interfaces.ether.ipv4.addresses = [
|
|
||||||
{
|
{
|
||||||
address = ipv4;
|
type = "tap";
|
||||||
prefixLength = 32;
|
# bridge = "ztkubnet";
|
||||||
|
id = "vm-${hostName}";
|
||||||
|
mac = lib.rad-dev.strToMac hostName;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
shares = [
|
||||||
|
{
|
||||||
|
source = "/nix/store";
|
||||||
|
mountPoint = "/nix/.ro-store";
|
||||||
|
tag = "ro-store";
|
||||||
|
proto = "virtiofs";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# On the host
|
||||||
|
source = "/var/lib/microvms/${hostName}/journal";
|
||||||
|
# In the MicroVM
|
||||||
|
mountPoint = "/var/log/journal";
|
||||||
|
tag = "journal";
|
||||||
|
proto = "virtiofs";
|
||||||
|
socket = "journal.sock";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.network.enable = true;
|
||||||
|
|
||||||
|
systemd.network.networks."20-lan" = {
|
||||||
|
matchConfig.Type = "ether";
|
||||||
|
networkConfig = {
|
||||||
|
Address = address;
|
||||||
|
Gateway = gateway;
|
||||||
|
DNS = [ "9.9.9.9" ];
|
||||||
|
IPv6AcceptRA = true;
|
||||||
|
DHCP = "no";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
services.openssh = {
|
services.openssh = {
|
||||||
|
@ -38,7 +38,10 @@ in
|
|||||||
};
|
};
|
||||||
networks = {
|
networks = {
|
||||||
"30-ztkubnet" = {
|
"30-ztkubnet" = {
|
||||||
matchConfig.Name = "ztkubnet";
|
matchConfig.Name = [
|
||||||
|
"ztkubnet"
|
||||||
|
"vm-*"
|
||||||
|
];
|
||||||
networkConfig.Bridge = "brkubnet";
|
networkConfig.Bridge = "brkubnet";
|
||||||
linkConfig.RequiredForOnline = "enslaved";
|
linkConfig.RequiredForOnline = "enslaved";
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,8 @@ in
|
|||||||
genK3SVM (src + "/modules/opt/k3s-server.nix") (src + "/modules/opt/k3s-agent.nix")
|
genK3SVM (src + "/modules/opt/k3s-server.nix") (src + "/modules/opt/k3s-agent.nix")
|
||||||
{
|
{
|
||||||
"ph-server-1" = {
|
"ph-server-1" = {
|
||||||
ipv4 = "192.168.69.10";
|
address = [ "192.168.69.10/24" ];
|
||||||
|
gateway = "192.168.69.1";
|
||||||
machine-id = "d694ad1e88b356887bb204ac665263f7";
|
machine-id = "d694ad1e88b356887bb204ac665263f7";
|
||||||
server = true;
|
server = true;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user