Merge pull request 'cli,nix: Add machine_icon, machine_description to vm' (#812) from Qubasa-main into main
All checks were successful
checks-impure / test (push) Successful in 1m37s
checks / test (push) Successful in 2m16s

This commit is contained in:
clan-bot 2024-02-06 12:29:32 +00:00
commit 4d18ce2366
6 changed files with 48 additions and 6 deletions

View File

@ -41,12 +41,10 @@ let
clan-core.nixosModules.clanCore
(machines.${name} or { })
{
clanCore.machineName = name;
clanCore.clanName = clanName;
clanCore.clanIcon = clanIcon;
clanCore.clanDir = directory;
clanCore.machineIcon = clanIcon;
clanCore.machineDescription = null;
clanCore.machineName = name;
nixpkgs.hostPlatform = if forceSystem then lib.mkForce system else lib.mkDefault system;
# speeds up nix commands by using the nixpkgs from the host system (especially useful in VMs)

View File

@ -8,12 +8,14 @@
};
machineIcon = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
the location of the machine icon
'';
};
machineDescription = lib.mkOption {
type = lib.types.str;
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
the description of the machine
'';

View File

@ -172,6 +172,30 @@ in
whether to enable native wayland window passthrough with waypipe for the vm
'';
};
machine_icon = lib.mkOption {
type = lib.types.nullOr lib.types.path;
internal = true;
readOnly = true;
description = ''
the location of the clan icon
'';
};
machine_name = lib.mkOption {
type = lib.types.str;
internal = true;
readOnly = true;
description = ''
the name of the vm
'';
};
machine_description = lib.mkOption {
type = lib.types.nullOr lib.types.str;
internal = true;
readOnly = true;
description = ''
the description of the vm
'';
};
};
};
@ -179,6 +203,9 @@ in
# for clan vm inspect
clanCore.vm.inspect = {
clan_name = config.clanCore.clanName;
machine_icon = config.clanCore.machineIcon or config.clanCore.clanIcon;
machine_name = config.clanCore.machineName;
machine_description = config.clanCore.machineDescription;
memory_size = config.clan.virtualisation.memorySize;
inherit (config.clan.virtualisation) cores graphics waypipe;
};

View File

@ -7,7 +7,7 @@ from ..dirs import machine_gcroot
from ..errors import ClanError
from ..machines.list import list_machines
from ..machines.machines import Machine
from ..nix import nix_build, nix_config, nix_eval, nix_metadata
from ..nix import nix_add_to_gcroots, nix_build, nix_config, nix_eval, nix_metadata
from ..vms.inspect import VmConfig, inspect_vm
@ -44,6 +44,14 @@ def inspect_flake(flake_url: str | Path, machine_name: str) -> FlakeConfig:
machine = Machine(machine_name, flake_url)
vm = inspect_vm(machine)
# Make symlink to gcroots from vm.machine_icon
if vm.machine_icon:
gcroot_icon: Path = (
machine_gcroot(clan_name=vm.clan_name, flake_url=str(flake_url))
/ vm.machine_name
)
nix_add_to_gcroots(vm.machine_icon, gcroot_icon)
# Get the cLAN name
cmd = nix_eval(
[

View File

@ -53,6 +53,11 @@ def nix_build(flags: list[str], gcroot: Path | None = None) -> list[str]:
)
def nix_add_to_gcroots(nix_path: Path, dest: Path) -> None:
cmd = ["nix-store", "--realise", f"{nix_path}", "--add-root", f"{dest}"]
run(cmd)
def nix_config() -> dict[str, Any]:
cmd = nix_command(["show-config", "--json"])
proc = run(cmd)

View File

@ -9,6 +9,8 @@ from ..machines.machines import Machine
@dataclass
class VmConfig:
machine_name: str
machine_icon: Path
machine_description: str
flake_url: str | Path
clan_name: str
@ -20,7 +22,7 @@ class VmConfig:
def inspect_vm(machine: Machine) -> VmConfig:
data = json.loads(machine.eval_nix("config.clanCore.vm.inspect"))
return VmConfig(machine_name=machine.name, flake_url=machine.flake, **data)
return VmConfig(flake_url=machine.flake, **data)
@dataclass