1
0
forked from clan/clan-core

Merge pull request 'cli,nix: Add machine_icon, machine_description to vm' (#812) from Qubasa-main into main

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 clan-core.nixosModules.clanCore
(machines.${name} or { }) (machines.${name} or { })
{ {
clanCore.machineName = name;
clanCore.clanName = clanName; clanCore.clanName = clanName;
clanCore.clanIcon = clanIcon; clanCore.clanIcon = clanIcon;
clanCore.clanDir = directory; clanCore.clanDir = directory;
clanCore.machineIcon = clanIcon; clanCore.machineName = name;
clanCore.machineDescription = null;
nixpkgs.hostPlatform = if forceSystem then lib.mkForce system else lib.mkDefault system; 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) # 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 { machineIcon = lib.mkOption {
type = lib.types.nullOr lib.types.path; type = lib.types.nullOr lib.types.path;
default = null;
description = '' description = ''
the location of the machine icon the location of the machine icon
''; '';
}; };
machineDescription = lib.mkOption { machineDescription = lib.mkOption {
type = lib.types.str; type = lib.types.nullOr lib.types.str;
default = null;
description = '' description = ''
the description of the machine the description of the machine
''; '';

View File

@ -172,6 +172,30 @@ in
whether to enable native wayland window passthrough with waypipe for the vm 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 # for clan vm inspect
clanCore.vm.inspect = { clanCore.vm.inspect = {
clan_name = config.clanCore.clanName; 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; memory_size = config.clan.virtualisation.memorySize;
inherit (config.clan.virtualisation) cores graphics waypipe; inherit (config.clan.virtualisation) cores graphics waypipe;
}; };

View File

@ -7,7 +7,7 @@ from ..dirs import machine_gcroot
from ..errors import ClanError from ..errors import ClanError
from ..machines.list import list_machines from ..machines.list import list_machines
from ..machines.machines import Machine 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 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) machine = Machine(machine_name, flake_url)
vm = inspect_vm(machine) 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 # Get the cLAN name
cmd = nix_eval( 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]: def nix_config() -> dict[str, Any]:
cmd = nix_command(["show-config", "--json"]) cmd = nix_command(["show-config", "--json"])
proc = run(cmd) proc = run(cmd)

View File

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