Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/runner.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let
inherit (pkgs) lib;

inherit (microvmConfig) hostName vmHostPackages;
inherit (microvmConfig) fqdnOrHostName vmHostPackages;

inherit (import ./. { inherit lib; }) makeMacvtap withDriveLetters extractOptValues extractParamValue;
inherit (import ./volumes.nix { pkgs = microvmConfig.vmHostPackages; }) createVolumesScript;
Expand All @@ -25,7 +25,7 @@ let
setBalloonScript = hypervisorConfig.setBalloonScript or null;

execArg = lib.optionalString microvmConfig.prettyProcnames
''-a "microvm@${hostName}"'';
''-a "microvm@${fqdnOrHostName}"'';


binScripts = microvmConfig.binScripts // {
Expand Down Expand Up @@ -57,11 +57,11 @@ let
};

binScriptPkgs = lib.mapAttrs (scriptName: lines:
vmHostPackages.writeShellScript "microvm-${hostName}-${scriptName}" lines
vmHostPackages.writeShellScript "microvm-${fqdnOrHostName}-${scriptName}" lines
) binScripts;
in

vmHostPackages.buildPackages.runCommand "microvm-${microvmConfig.hypervisor}-${hostName}"
vmHostPackages.buildPackages.runCommand "microvm-${microvmConfig.hypervisor}-${fqdnOrHostName}"
{
# for `nix run`
meta.mainProgram = "microvm-run";
Expand Down
4 changes: 2 additions & 2 deletions lib/runners/firecracker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let
inherit (pkgs) lib;
inherit (pkgs.stdenv.hostPlatform) system;
inherit (microvmConfig)
hostName user socket preStart
fqdnOrHostName user socket preStart
vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem
interfaces volumes shares devices
kernel initrdPath
Expand Down Expand Up @@ -67,7 +67,7 @@ let
};
config = lib.recursiveUpdate baseConfig microvmConfig.firecracker.extraConfig;

configFile = pkgs.writers.writeJSON "firecracker-${hostName}.json" config;
configFile = pkgs.writers.writeJSON "firecracker-${fqdnOrHostName}.json" config;

in {
command =
Expand Down
6 changes: 3 additions & 3 deletions lib/runners/kvmtool.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let
inherit (pkgs) lib;
inherit (microvmConfig)
hostName preStart user
fqdnOrHostName preStart user
vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem interfaces volumes shares devices vsock
kernel initrdPath credentialFiles
storeDisk storeOnDisk;
Expand All @@ -30,7 +30,7 @@ in {
else builtins.concatStringsSep " " (
[
"${pkgs.kvmtool}/bin/lkvm" "run"
"--name" (lib.escapeShellArg hostName)
"--name" (lib.escapeShellArg fqdnOrHostName)
"-m" (toString mem)
"-c" (toString vcpu)
"--console" "serial"
Expand Down Expand Up @@ -99,6 +99,6 @@ in {
else
ARGS="-i $SIZE"
fi
HOME=$PWD ${pkgs.kvmtool}/bin/lkvm balloon $ARGS -n ${hostName}
HOME=$PWD ${pkgs.kvmtool}/bin/lkvm balloon $ARGS -n ${fqdnOrHostName}
'';
}
7 changes: 3 additions & 4 deletions lib/runners/qemu.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ let
then "io_uring"
else "threads";

inherit (microvmConfig) hostName vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces shares socket forwardPorts devices vsock graphics storeOnDisk kernel initrdPath storeDisk credentialFiles;
inherit (microvmConfig) fqdnOrHostName vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces shares socket forwardPorts devices vsock graphics storeOnDisk kernel initrdPath storeDisk credentialFiles;
inherit (microvmConfig.qemu) machine extraArgs serialConsole pcieRootPorts;


volumes = withDriveLetters microvmConfig;

requireUsb =
Expand Down Expand Up @@ -184,7 +183,7 @@ lib.warnIf (mem == 2048) ''
else lib.escapeShellArgs (
[
"${qemu}/bin/qemu-system-${arch}"
"-name" hostName
"-name" fqdnOrHostName
"-M" machineConfig
"-m" (toString mem)
"-smp" (toString vcpu)
Expand Down Expand Up @@ -301,7 +300,7 @@ lib.warnIf (mem == 2048) ''
lib.warnIf (
forwardPorts != [] &&
! builtins.any ({ type, ... }: type == "user") interfaces
) "${hostName}: forwardPortsOptions only running with user network" (
) "${fqdnOrHostName}: forwardPortsOptions only running with user network" (
builtins.concatMap ({ type, id, mac, bridge, ... }: [
"-netdev" (
lib.concatStringsSep "," (
Expand Down
6 changes: 3 additions & 3 deletions lib/runners/stratovirt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let
inherit (pkgs.stdenv.hostPlatform) system;

inherit (microvmConfig)
hostName
fqdnOrHostName
vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem interfaces shares socket forwardPorts devices
kernel initrdPath credentialFiles
storeOnDisk storeDisk;
Expand Down Expand Up @@ -86,7 +86,7 @@ in {
[
"${pkgs.expect}/bin/unbuffer"
"${pkgs.stratovirt}/bin/stratovirt"
"-name" hostName
"-name" fqdnOrHostName
"-machine" machine
"-m" (toString mem)
"-smp" (toString vcpu)
Expand Down Expand Up @@ -140,7 +140,7 @@ in {
lib.warnIf (
forwardPorts != [] &&
! builtins.any ({ type, ... }: type == "user") interfaces
) "${hostName}: forwardPortsOptions only running with user network" (
) "${fqdnOrHostName}: forwardPortsOptions only running with user network" (
builtins.concatMap ({ type, id, mac, bridge, ... }: [
"-netdev" (
lib.concatStringsSep "," (
Expand Down
2 changes: 1 addition & 1 deletion nixos-modules/host/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
extraConfig = ({ lib, ... }: {
_file = "module at ${__curPos.file}:${toString __curPos.line}";
config = {
networking.hostName = lib.mkDefault name;
networking.fqdnOrHostName = lib.mkDefault name;
};
});
in [
Expand Down
24 changes: 12 additions & 12 deletions nixos-modules/microvm/asserts.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ config, lib, ... }:
let
inherit (config.networking) hostName;
inherit (config.networking) fqdnOrHostName;

in
lib.mkIf config.microvm.guest.enable {
Expand All @@ -9,7 +9,7 @@ lib.mkIf config.microvm.guest.enable {
map (volumes: {
assertion = builtins.length volumes == 1;
message = ''
MicroVM ${hostName}: volume image "${(builtins.head volumes).image}" is used ${toString (builtins.length volumes)} > 1 times.
MicroVM ${fqdnOrHostName}: volume image "${(builtins.head volumes).image}" is used ${toString (builtins.length volumes)} > 1 times.
'';
}) (
builtins.attrValues (
Expand All @@ -21,7 +21,7 @@ lib.mkIf config.microvm.guest.enable {
map (interfaces: {
assertion = builtins.length interfaces == 1;
message = ''
MicroVM ${hostName}: interface id "${(builtins.head interfaces).id}" is used ${toString (builtins.length interfaces)} > 1 times.
MicroVM ${fqdnOrHostName}: interface id "${(builtins.head interfaces).id}" is used ${toString (builtins.length interfaces)} > 1 times.
'';
}) (
builtins.attrValues (
Expand All @@ -35,14 +35,14 @@ lib.mkIf config.microvm.guest.enable {
then {
assertion = bridge != null;
message = ''
MicroVM ${hostName}: interface ${id} is of type "bridge"
MicroVM ${fqdnOrHostName}: interface ${id} is of type "bridge"
but doesn't have a bridge to attach to defined.
'';
}
else {
assertion = bridge == null;
message = ''
MicroVM ${hostName}: interface ${id} is not of type "bridge"
MicroVM ${fqdnOrHostName}: interface ${id} is not of type "bridge"
and therefore shouldn't have a "bridge" option defined.
'';
}
Expand All @@ -52,7 +52,7 @@ lib.mkIf config.microvm.guest.enable {
map ({ id, ... }: {
assertion = builtins.stringLength id <= 15;
message = ''
MicroVM ${hostName}: interface name ${id} is longer than the
MicroVM ${fqdnOrHostName}: interface name ${id} is longer than the
the maximum length of 15 characters on Linux.
'';
}) config.microvm.interfaces
Expand All @@ -61,7 +61,7 @@ lib.mkIf config.microvm.guest.enable {
map (shares: {
assertion = builtins.length shares == 1;
message = ''
MicroVM ${hostName}: share tag "${(builtins.head shares).tag}" is used ${toString (builtins.length shares)} > 1 times.
MicroVM ${fqdnOrHostName}: share tag "${(builtins.head shares).tag}" is used ${toString (builtins.length shares)} > 1 times.
'';
}) (
builtins.attrValues (
Expand All @@ -73,7 +73,7 @@ lib.mkIf config.microvm.guest.enable {
map (shares: {
assertion = builtins.length shares == 1;
message = ''
MicroVM ${hostName}: share socket "${(builtins.head shares).socket}" is used ${toString (builtins.length shares)} > 1 times.
MicroVM ${fqdnOrHostName}: share socket "${(builtins.head shares).socket}" is used ${toString (builtins.length shares)} > 1 times.
'';
}) (
builtins.attrValues (
Expand All @@ -88,7 +88,7 @@ lib.mkIf config.microvm.guest.enable {
map ({ tag, socket, ... }: {
assertion = socket != null;
message = ''
MicroVM ${hostName}: virtiofs share with tag "${tag}" is missing a `socket` path.
MicroVM ${fqdnOrHostName}: virtiofs share with tag "${tag}" is missing a `socket` path.
'';
}) (
builtins.filter ({ proto, ... }: proto == "virtiofs")
Expand All @@ -103,22 +103,22 @@ lib.mkIf config.microvm.guest.enable {
builtins.any ({ type, ... }: type == "user") config.microvm.interfaces
);
message = ''
MicroVM ${hostName}: `config.microvm.forwardPorts` works only with qemu and one network interface with `type = "user"`
MicroVM ${fqdnOrHostName}: `config.microvm.forwardPorts` works only with qemu and one network interface with `type = "user"`
'';
} ]
++
# cloud-hypervisor specific asserts
lib.optionals (config.microvm.hypervisor == "cloud-hypervisor") [ {
assertion = ! (lib.any (str: lib.hasInfix "oem_strings" str) config.microvm.cloud-hypervisor.platformOEMStrings);
message = ''
MicroVM ${hostName}: `config.microvm.cloud-hypervisor.platformOEMStrings` items must not contain `oem_strings`
MicroVM ${fqdnOrHostName}: `config.microvm.cloud-hypervisor.platformOEMStrings` items must not contain `oem_strings`
'';
} ];


warnings =
# 32 MB is just an optimistic guess, not based on experience
lib.optional (config.microvm.mem < 32) ''
MicroVM ${hostName}: ${toString config.microvm.mem} MB of RAM is uncomfortably narrow.
MicroVM ${fqdnOrHostName}: ${toString config.microvm.mem} MB of RAM is uncomfortably narrow.
'';
}
2 changes: 1 addition & 1 deletion nixos-modules/microvm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ in
microvm-lib.buildRunner {
inherit pkgs;
microvmConfig = config.microvm // {
inherit (config.networking) hostName;
inherit (config.networking) fqdnOrHostName;
inherit hypervisor;
};
inherit (config.system.build) toplevel;
Expand Down
10 changes: 5 additions & 5 deletions nixos-modules/microvm/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let
};

cfg = config.microvm;
hostName = config.networking.hostName or "$HOSTNAME";
fqdnOrHostName = config.networking.fqdnOrHostName or "$fqdnOrHostName";
kernelAtLeast = lib.versionAtLeast config.boot.kernelPackages.kernel.version;
in
{
Expand Down Expand Up @@ -76,8 +76,8 @@ in

socket = mkOption {
description = "Hypervisor control socket path";
default = "${hostName}.sock";
defaultText = literalExpression ''"''${hostName}.sock"'';
default = "${fqdnOrHostName}.sock";
defaultText = literalExpression ''"''${fqdnOrHostName}.sock"'';
type = with types; nullOr str;
};

Expand Down Expand Up @@ -359,7 +359,7 @@ in
type = nullOr str;
default =
if config.proto == "virtiofs"
then "${hostName}-virtiofs-${config.tag}.sock"
then "${fqdnOrHostName}-virtiofs-${config.tag}.sock"
else null;
description = "Socket for communication with virtiofs daemon";
};
Expand Down Expand Up @@ -528,7 +528,7 @@ in

socket = mkOption {
type = types.str;
default = "${hostName}-gpu.sock";
default = "${fqdnOrHostName}-gpu.sock";
description = ''
Path of vhost-user socket
'';
Expand Down
Loading