Skip to content

Commit

Permalink
Central database for internal IP addresses
Browse files Browse the repository at this point in the history
- Implements a common database for internal IP addresses
- All VMs read this to get it's assigned IP
- Resolves:
  https://jira.tii.ae/browse/SSRCSP-5674

Signed-off-by: Ganga Ram <[email protected]>
  • Loading branch information
gngram committed Dec 10, 2024
1 parent 8938072 commit eccc0a3
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 59 deletions.
63 changes: 63 additions & 0 deletions modules/common/networking/hosts-entries.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
let
hostsEntries = [
{
ip = 1;
name = "net-vm";
}
{
ip = 2;
name = "ghaf-host";
}
{
ip = 3;
name = "gui-vm";
}
{
ip = 4;
name = "ids-vm";
}
{
ip = 5;
name = "audio-vm";
}
{
ip = 10;
name = "admin-vm";
}
{
ip = 100;
name = "chrome-vm";
}
{
ip = 101;
name = "gala-vm";
}
{
ip = 102;
name = "zathura-vm";
}
{
ip = 103;
name = "comms-vm";
}
{
ip = 104;
name = "business-vm";
}
];
# Create a lookup map from entries
lookupMap = builtins.listToAttrs (
map (entry: {
inherit (entry) name;
value = entry.ip;
}) hostsEntries
);

# Function to find the corresponding IP address by name
ipByName = name: lookupMap.${name};

in
{
inherit ipByName;
inherit hostsEntries;
}
49 changes: 2 additions & 47 deletions modules/common/networking/hosts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,53 +36,8 @@ let
# debug network hosts are post-fixed: <hostname>-debug
ipBase = "192.168.100";
debugBase = "192.168.101";
hostsEntries = [
{
ip = 1;
name = "net-vm";
}
{
ip = 2;
name = "ghaf-host";
}
{
ip = 3;
name = "gui-vm";
}
{
ip = 4;
name = "ids-vm";
}
{
ip = 5;
name = "audio-vm";
}
{
ip = 10;
name = "admin-vm";
}
{
ip = 100;
name = "chrome-vm";
}
{
ip = 101;
name = "gala-vm";
}
{
ip = 102;
name = "zathura-vm";
}
{
ip = 103;
name = "comms-vm";
}
{
ip = 104;
name = "business-vm";
}
];

hosts-entries = import ./hosts-entries.nix;
inherit (hosts-entries) hostsEntries;
mkHostEntry =
{ ip, name }:
{
Expand Down
3 changes: 2 additions & 1 deletion modules/microvm/virtualization/microvm/adminvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ let
vmName = "admin-vm";
macAddress = "02:00:00:AD:01:01";
isLoggingEnabled = config.ghaf.logging.client.enable;
hostsEntries = import ../../../common/networking/hosts-entries.nix;

adminvmBaseConfiguration = {
imports = [
Expand All @@ -19,7 +20,7 @@ let
vmName
macAddress
;
internalIP = 10;
internalIP = hostsEntries.ipByName vmName;
})
# We need to retrieve mac address and start log aggregator
../../../common/logging/hw-mac-retrieve.nix
Expand Down
9 changes: 7 additions & 2 deletions modules/microvm/virtualization/microvm/appvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ let
inputs.self.nixosModules.givc-appvm
(import ./common/vm-networking.nix {
inherit config lib vmName;
inherit (vm) macAddress;
internalIP = vmIndex + 100;
inherit (vm) macAddress internalIP;
})

./common/ghaf-audio.nix
Expand Down Expand Up @@ -240,6 +239,12 @@ in
'';
type = types.str;
};
internalIP = mkOption {
description = ''
Internal IP address for this AppVM
'';
type = types.int;
};
ramMb = mkOption {
description = ''
Amount of RAM for this AppVM
Expand Down
3 changes: 2 additions & 1 deletion modules/microvm/virtualization/microvm/audiovm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let
macAddress = "02:00:00:03:03:03";
isGuiVmEnabled = config.ghaf.virtualization.microvm.guivm.enable;
has_acpi_path = config.ghaf.hardware.definition.audio.acpiPath != null;
hostsEntries = import ../../../common/networking/hosts-entries.nix;

sshKeysHelper = pkgs.callPackage ../../../../packages/ssh-keys-helper {
inherit pkgs;
Expand All @@ -30,7 +31,7 @@ let
vmName
macAddress
;
internalIP = 5;
internalIP = hostsEntries.ipByName vmName;
})
./common/storagevm.nix
../../../common/logging/client.nix
Expand Down
4 changes: 3 additions & 1 deletion modules/microvm/virtualization/microvm/guivm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ let
vmName = "gui-vm";
macAddress = "02:00:00:02:02:02";
inherit (import ../../../../lib/launcher.nix { inherit pkgs lib; }) rmDesktopEntries;
hostsEntries = import ../../../common/networking/hosts-entries.nix;

guivmBaseConfiguration = {
imports = [
inputs.impermanence.nixosModules.impermanence
Expand All @@ -22,7 +24,7 @@ let
vmName
macAddress
;
internalIP = 3;
internalIP = hostsEntries.ipByName vmName;
})

./common/storagevm.nix
Expand Down
3 changes: 2 additions & 1 deletion modules/microvm/virtualization/microvm/idsvm/idsvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
let
configHost = config;
vmName = "ids-vm";
hostsEntries = import ../../../../common/networking/hosts-entries.nix;
macAddress = "02:00:00:01:01:02";
idsvmBaseConfiguration = {
imports = [
Expand All @@ -19,7 +20,7 @@ let
vmName
macAddress
;
internalIP = 4;
internalIP = hostsEntries.ipByName vmName;
})
(
{ lib, ... }:
Expand Down
3 changes: 2 additions & 1 deletion modules/microvm/virtualization/microvm/netvm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let
macAddress = "02:00:00:01:01:01";

isGuiVmEnabled = config.ghaf.virtualization.microvm.guivm.enable;
hostsEntries = import ../../../common/networking/hosts-entries.nix;

sshKeysHelper = pkgs.callPackage ../../../../packages/ssh-keys-helper {
inherit pkgs;
Expand All @@ -29,7 +30,7 @@ let
vmName
macAddress
;
internalIP = 1;
internalIP = hostsEntries.ipByName vmName;
isGateway = true;
})

Expand Down
8 changes: 7 additions & 1 deletion modules/reference/appvms/appflowy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
config,
...
}:
{
let
hostsEntries = import ../../common/networking/hosts-entries.nix;
name = "appflowy";
vmname = name + "-vm";
in
rec {
inherit name;
packages = [ pkgs.appflowy ];
macAddress = "02:00:00:03:08:01";
internalIP = hostsEntries.ipByName vmname;
ramMb = 768;
cores = 1;
extraModules = [
Expand Down
4 changes: 4 additions & 0 deletions modules/reference/appvms/business.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ let
inherit (lib) mkIf optionalString;
#TODO: Move this to a common place
name = "business";
hostsEntries = import ../../common/networking/hosts-entries.nix;
vmname = name + "-vm";
proxyUserName = "proxy-user";
proxyGroupName = "proxy-admin";
tiiVpnAddr = "151.253.154.18";
Expand Down Expand Up @@ -114,6 +116,8 @@ in

# TODO create a repository of mac addresses to avoid conflicts
macAddress = "02:00:00:03:10:01";
internalIP = hostsEntries.ipByName vmname;

ramMb = 6144;
cores = 4;
extraModules = [
Expand Down
3 changes: 3 additions & 0 deletions modules/reference/appvms/chromium.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
}:
let
name = "chromium";
hostsEntries = import ../../common/networking/hosts-entries.nix;
vmname = name + "-vm";
in
{
name = "${name}";
Expand All @@ -17,6 +19,7 @@ in
] ++ lib.optional config.ghaf.development.debug.tools.enable pkgs.alsa-utils;
# TODO create a repository of mac addresses to avoid conflicts
macAddress = "02:00:00:03:05:01";
internalIP = hostsEntries.ipByName vmname;
ramMb = 6144;
cores = 4;
extraModules = [
Expand Down
4 changes: 4 additions & 0 deletions modules/reference/appvms/comms.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
}:
let
name = "comms";
hostsEntries = import ../../common/networking/hosts-entries.nix;
vmname = name + "-vm";
inherit (lib) hasAttr optionals;
dendrite-pinecone = pkgs.callPackage ../../../packages/dendrite-pinecone { };
isDendritePineconeEnabled =
Expand All @@ -28,6 +30,8 @@ in
pkgs.tcpdump
] ++ pkgs.lib.optionals isDendritePineconeEnabled [ dendrite-pinecone ];
macAddress = "02:00:00:03:09:01";
internalIP = hostsEntries.ipByName vmname;

ramMb = 4096;
cores = 4;
extraModules = [
Expand Down
8 changes: 7 additions & 1 deletion modules/reference/appvms/gala.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
config,
...
}:
{
let
name = "gala";
hostsEntries = import ../../common/networking/hosts-entries.nix;
vmname = name + "-vm";
in
{
inherit name;
packages = [ pkgs.gala-app ];
macAddress = "02:00:00:03:06:01";
internalIP = hostsEntries.ipByName vmname;
ramMb = 1536;
cores = 2;
extraModules = [
Expand Down
3 changes: 3 additions & 0 deletions modules/reference/appvms/google-chrome.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
}:
let
name = "chrome";
hostsEntries = import ../../common/networking/hosts-entries.nix;
vmname = name + "-vm";
in
{
name = "${name}";
Expand All @@ -17,6 +19,7 @@ in
] ++ lib.optional config.ghaf.development.debug.tools.enable pkgs.alsa-utils;
# TODO create a repository of mac addresses to avoid conflicts
macAddress = "02:00:00:03:11:01";
internalIP = hostsEntries.ipByName vmname;
ramMb = 6144;
cores = 4;
extraModules = [
Expand Down
8 changes: 7 additions & 1 deletion modules/reference/appvms/zathura.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@
config,
...
}:
{
let
name = "zathura";
hostsEntries = import ../../common/networking/hosts-entries.nix;
vmname = name + "-vm";
in
{
inherit name;
packages = [
pkgs.zathura
pkgs.pqiv
];
macAddress = "02:00:00:03:07:01";
internalIP = hostsEntries.ipByName vmname;
ramMb = 512;
cores = 1;
extraModules = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
{
config.ghaf.reference.services.dendrite-pinecone =
let
hostsEntries = import ../../../common/networking/hosts-entries.nix;
vmname = "net-vm";
externalNic =
let
firstPciWifiDevice = lib.head config.ghaf.hardware.definition.network.pciDevices;
Expand All @@ -15,9 +17,9 @@
vmNetworking = import ../../../microvm/virtualization/microvm/common/vm-networking.nix {
inherit config;
inherit lib;
vmName = "net-vm";
vmName = vmname;
inherit (config.microvm.net-vm) macAddress;
internalIP = 1;
internalIP = hostsEntries.ipByName vmname;
};
in
"${lib.head vmNetworking.networking.nat.internalInterfaces}";
Expand Down

0 comments on commit eccc0a3

Please sign in to comment.