2024-02-01 21:57:18 +00:00
|
|
|
{ pkgs, lib, config, hypervisorConfig, ... }: {
|
2024-02-07 22:15:48 +00:00
|
|
|
imports = [ ./docker_swarm.nix ];
|
|
|
|
|
2024-01-30 21:32:09 +00:00
|
|
|
options.lab.vm = {
|
2024-02-27 22:28:52 +00:00
|
|
|
# TODO: make global.
|
2024-02-01 21:57:18 +00:00
|
|
|
baseMACAddress = lib.mkOption {
|
|
|
|
default = "BA:DB:EE:F0:00:00";
|
2024-01-29 21:21:15 +00:00
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
2024-02-01 21:57:18 +00:00
|
|
|
Base MAC address for VMs in the DMZ.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
id = lib.mkOption {
|
|
|
|
type = lib.types.int;
|
|
|
|
description = ''
|
|
|
|
Unique identifier of this VM from wich the MAC address is derived.
|
2024-01-29 21:21:15 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-02-07 22:15:48 +00:00
|
|
|
shares = lib.mkOption {
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
Directories mounted on the VM using VirtioFS.
|
|
|
|
'';
|
|
|
|
type = lib.types.listOf (lib.types.submodule ({ config, ... }: {
|
|
|
|
options = {
|
|
|
|
name = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
The name of the directory share.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
mountPoint = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = ''
|
|
|
|
The mount point of the directory share inside the virtual machine.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
};
|
2024-01-28 11:06:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
system.stateVersion = hypervisorConfig.system.stateVersion;
|
|
|
|
|
2024-02-07 22:15:48 +00:00
|
|
|
lab.vm.shares = [{
|
|
|
|
name = "host_keys";
|
|
|
|
mountPoint = "/etc/ssh/host_keys";
|
|
|
|
}];
|
|
|
|
|
2024-02-27 22:28:52 +00:00
|
|
|
services.openssh =
|
|
|
|
let
|
|
|
|
hostKeyPath = "/etc/ssh/host_keys/ssh_host_ed25519_key";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
hostKeys = [{
|
|
|
|
path = hostKeyPath;
|
|
|
|
type = "ed25519";
|
|
|
|
}];
|
|
|
|
|
|
|
|
extraConfig = ''
|
|
|
|
HostKey ${hostKeyPath}
|
|
|
|
'';
|
|
|
|
};
|
2024-02-07 21:22:10 +00:00
|
|
|
|
|
|
|
microvm = {
|
2024-02-08 22:44:36 +00:00
|
|
|
# TODO: make this dependent on the host CPU
|
|
|
|
vcpu = 4;
|
|
|
|
|
2024-02-07 22:15:48 +00:00
|
|
|
shares = [{
|
|
|
|
source = "/nix/store";
|
|
|
|
mountPoint = "/nix/.ro-store";
|
|
|
|
tag = "ro-store";
|
|
|
|
proto = "virtiofs";
|
|
|
|
}] ++ map
|
|
|
|
(share: {
|
|
|
|
source = "/var/lib/microvms/${config.networking.hostName}/shares/${share.name}";
|
|
|
|
mountPoint = share.mountPoint;
|
|
|
|
tag = share.name;
|
2024-02-07 21:22:10 +00:00
|
|
|
proto = "virtiofs";
|
2024-02-07 22:15:48 +00:00
|
|
|
})
|
|
|
|
config.lab.vm.shares;
|
2024-02-07 21:22:10 +00:00
|
|
|
|
2024-01-28 11:06:30 +00:00
|
|
|
interfaces = [{
|
|
|
|
type = "tap";
|
2024-01-28 11:55:58 +00:00
|
|
|
id = "vm-${config.networking.hostName}";
|
2024-02-01 21:57:18 +00:00
|
|
|
mac = pkgs.lib.net.mac.add config.lab.vm.id config.lab.vm.baseMACAddress;
|
2024-01-28 11:06:30 +00:00
|
|
|
}];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|