network options working for basic functionality

This commit is contained in:
Git Sagar 2024-06-03 20:36:30 -03:00
parent e4cdc2cae5
commit 392375b046
9 changed files with 348 additions and 221 deletions

125
nixos/vm/options.nix Normal file
View file

@ -0,0 +1,125 @@
{ config, pkgs, lib, ... }:
with lib;
let
networkModule = import ./network.nix { inherit config pkgs lib ;};
in
{
options = {
cpu =
mkOption {
type = types.str;
default = "host";
description = ''
The CPU model to emulate.
'';
};
smp =
mkOption {
type = types.ints.positive;
default = 1;
description = ''
Specify the number of cores the guest is permitted to use.
The number can be higher than the available cores on the
host system.
'';
};
memSize =
mkOption {
type = types.ints.positive;
default = 1024;
description = ''
The memory size in megabytes of the virtual machine.
'';
};
diskSize =
mkOption {
type = types.str;
default = "";
description = ''
The disk size in qemu params.
'';
};
osImage =
mkOption {
type = types.package;
description = ''
OS image stored in the nix store, either built with vmixLib.images or fetched from the internet.
'';
};
persistantOverlayImagePath =
mkOption {
type = types.nullOr types.path;
default = null;
description = ''
Path where the persistant overlay is stored. If path is non-existant, a qcow2 image backed by the original osImage is created.
'';
};
startOnBoot =
mkOption {
type = types.bool;
description = ''
Whether to start the VM automatically on system boot.
'';
default = true;
};
sharedDirectories =
lib.mkOption {
type = types.attrsOf
(types.submodule {
options = {
source = lib.mkOption {
type = types.str;
description = "The path of the directory to share, can be a shell variable";
};
target = lib.mkOption {
type = types.str;
description = "The mount point of the directory inside the virtual machine";
};
};
});
example = {
my-share = { source = "/path/to/be/shared"; target = "/mnt/shared"; };
};
default = { };
};
networks = lib.mkOption {
type = types.attrsOf
(types.submodule networkModule);
example = {
my-share = { source = "/path/to/be/shared"; target = "/mnt/shared"; };
};
default = { };
};
};
functions.mkVMService = name: cfg:
let
vmCfg = cfg // { inherit name };
mkDiskImageFrom
diskImage =
qemuArgs = ''
--name ${vmCfg.name} \
--cpu ${vmCfg.cpu} \
--smp ${vmCfg.cores} \
--
'';
in
{
};
}
//storage
//
//networking - DNS, VPNs, Bridges, NATs, isolation, connecting with others,host
//run adhoc
//run and die
//