Merge pull request 'Fixes for aarch64 support' (#2293) from Qubasa/clan-core:Qubasa-main into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/2293
This commit is contained in:
@@ -3,6 +3,7 @@ let
|
|||||||
types = lib.types;
|
types = lib.types;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
# Required options
|
# Required options
|
||||||
directory = lib.mkOption {
|
directory = lib.mkOption {
|
||||||
@@ -69,18 +70,6 @@ in
|
|||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
pkgsForSystem = lib.mkOption {
|
|
||||||
type = types.functionTo (types.nullOr types.attrs);
|
|
||||||
default = _: null;
|
|
||||||
defaultText = "Lambda :: String -> { ... } | null";
|
|
||||||
description = ''
|
|
||||||
A function that maps from architecture to pkg. `( string -> pkgs )`
|
|
||||||
|
|
||||||
If specified this nixpkgs will be only imported once for each system.
|
|
||||||
This improves performance, but all nipxkgs.* options will be ignored.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
# Outputs
|
# Outputs
|
||||||
nixosConfigurations = lib.mkOption {
|
nixosConfigurations = lib.mkOption {
|
||||||
# Hide from documentation.
|
# Hide from documentation.
|
||||||
@@ -112,4 +101,5 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ let
|
|||||||
inherit (config)
|
inherit (config)
|
||||||
directory
|
directory
|
||||||
machines
|
machines
|
||||||
pkgsForSystem
|
|
||||||
specialArgs
|
specialArgs
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -58,7 +57,7 @@ let
|
|||||||
# Settings
|
# Settings
|
||||||
clan.core.clanDir = directory;
|
clan.core.clanDir = directory;
|
||||||
# Inherited from clan wide settings
|
# Inherited from clan wide settings
|
||||||
# TODO: remove these
|
# TODO: remove these`
|
||||||
clan.core.name = config.inventory.meta.name;
|
clan.core.name = config.inventory.meta.name;
|
||||||
clan.core.icon = config.inventory.meta.icon;
|
clan.core.icon = config.inventory.meta.icon;
|
||||||
|
|
||||||
@@ -105,7 +104,12 @@ let
|
|||||||
name: _:
|
name: _:
|
||||||
nixosConfiguration {
|
nixosConfiguration {
|
||||||
inherit name system;
|
inherit name system;
|
||||||
pkgs = pkgsForSystem system;
|
|
||||||
|
# We removed pkgsForSystems because we have the problem that nixpkgs.* options are then ignored
|
||||||
|
# However our current model is to have the hardware config read and then set nixpkgs.hostPlatform automatically
|
||||||
|
# which gets ignored if we set pkgsForSystems. pkgsForSystems also needed to be set as else
|
||||||
|
# pkgs was equals to null in nixosConfiguration above which broke something else
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
}
|
}
|
||||||
) allMachines
|
) allMachines
|
||||||
)
|
)
|
||||||
@@ -122,7 +126,7 @@ let
|
|||||||
args
|
args
|
||||||
// {
|
// {
|
||||||
inherit name system;
|
inherit name system;
|
||||||
pkgs = pkgsForSystem system;
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
) allMachines
|
) allMachines
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from clan_cli.completions import (
|
|||||||
complete_machines,
|
complete_machines,
|
||||||
complete_target_host,
|
complete_target_host,
|
||||||
)
|
)
|
||||||
|
from clan_cli.errors import ClanError
|
||||||
from clan_cli.facts.generate import generate_facts
|
from clan_cli.facts.generate import generate_facts
|
||||||
from clan_cli.machines.hardware import HardwareConfig
|
from clan_cli.machines.hardware import HardwareConfig
|
||||||
from clan_cli.machines.machines import Machine
|
from clan_cli.machines.machines import Machine
|
||||||
@@ -25,10 +26,6 @@ from clan_cli.vars.generate import generate_vars
|
|||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ClanError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class InstallOptions:
|
class InstallOptions:
|
||||||
# flake to install
|
# flake to install
|
||||||
@@ -85,9 +82,6 @@ def install_machine(opts: InstallOptions) -> None:
|
|||||||
if opts.no_reboot:
|
if opts.no_reboot:
|
||||||
cmd.append("--no-reboot")
|
cmd.append("--no-reboot")
|
||||||
|
|
||||||
if opts.build_on_remote:
|
|
||||||
cmd.append("--build-on-remote")
|
|
||||||
|
|
||||||
if opts.update_hardware_config is not HardwareConfig.NONE:
|
if opts.update_hardware_config is not HardwareConfig.NONE:
|
||||||
cmd.extend(
|
cmd.extend(
|
||||||
[
|
[
|
||||||
@@ -108,6 +102,10 @@ def install_machine(opts: InstallOptions) -> None:
|
|||||||
"IdentitiesOnly=yes",
|
"IdentitiesOnly=yes",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if not machine.can_build_locally or opts.build_on_remote:
|
||||||
|
log.info("Architecture mismatch. Building on remote machine")
|
||||||
|
cmd.append("--build-on-remote")
|
||||||
|
|
||||||
if machine.target_host.port:
|
if machine.target_host.port:
|
||||||
cmd += ["--ssh-port", str(machine.target_host.port)]
|
cmd += ["--ssh-port", str(machine.target_host.port)]
|
||||||
if opts.kexec:
|
if opts.kexec:
|
||||||
|
|||||||
@@ -46,6 +46,32 @@ class Machine:
|
|||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return str(self)
|
return str(self)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def system(self) -> str:
|
||||||
|
# We filter out function attributes because they are not serializable.
|
||||||
|
attr = f"""
|
||||||
|
(let
|
||||||
|
machine = ((builtins.getFlake "{self.flake}").nixosConfigurations.{self.name});
|
||||||
|
in
|
||||||
|
{{ x = machine.pkgs.stdenv.hostPlatform.system; }}).x
|
||||||
|
"""
|
||||||
|
if attr in self._eval_cache:
|
||||||
|
output = self._eval_cache[attr]
|
||||||
|
else:
|
||||||
|
output = run_no_stdout(
|
||||||
|
nix_eval(["--impure", "--expr", attr])
|
||||||
|
).stdout.strip()
|
||||||
|
self._eval_cache[attr] = output
|
||||||
|
value = json.loads(output)
|
||||||
|
return value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def can_build_locally(self) -> bool:
|
||||||
|
# TODO: We could also use the function pkgs.stdenv.hostPlatform.canExecute
|
||||||
|
# but this is good enough for now.
|
||||||
|
output = nix_config()
|
||||||
|
return self.system == output["system"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def deployment(self) -> dict:
|
def deployment(self) -> dict:
|
||||||
if self.cached_deployment is not None:
|
if self.cached_deployment is not None:
|
||||||
@@ -173,7 +199,6 @@ class Machine:
|
|||||||
method: Literal["eval", "build"],
|
method: Literal["eval", "build"],
|
||||||
attr: str,
|
attr: str,
|
||||||
extra_config: None | dict = None,
|
extra_config: None | dict = None,
|
||||||
impure: bool = False,
|
|
||||||
nix_options: list[str] | None = None,
|
nix_options: list[str] | None = None,
|
||||||
) -> str | Path:
|
) -> str | Path:
|
||||||
"""
|
"""
|
||||||
@@ -215,12 +240,6 @@ class Machine:
|
|||||||
"dirtyRevision" in metadata
|
"dirtyRevision" in metadata
|
||||||
or "dirtyRev" in metadata["locks"]["nodes"]["clan-core"]["locked"]
|
or "dirtyRev" in metadata["locks"]["nodes"]["clan-core"]["locked"]
|
||||||
):
|
):
|
||||||
# if not impure:
|
|
||||||
# raise ClanError(
|
|
||||||
# "The machine has a dirty revision, and impure mode is not allowed"
|
|
||||||
# )
|
|
||||||
# else:
|
|
||||||
# args += ["--impure"]
|
|
||||||
args += ["--impure"]
|
args += ["--impure"]
|
||||||
|
|
||||||
args += [
|
args += [
|
||||||
@@ -254,7 +273,6 @@ class Machine:
|
|||||||
attr: str,
|
attr: str,
|
||||||
refresh: bool = False,
|
refresh: bool = False,
|
||||||
extra_config: None | dict = None,
|
extra_config: None | dict = None,
|
||||||
impure: bool = False,
|
|
||||||
nix_options: list[str] | None = None,
|
nix_options: list[str] | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
@@ -266,7 +284,7 @@ class Machine:
|
|||||||
if attr in self._eval_cache and not refresh and extra_config is None:
|
if attr in self._eval_cache and not refresh and extra_config is None:
|
||||||
return self._eval_cache[attr]
|
return self._eval_cache[attr]
|
||||||
|
|
||||||
output = self.nix("eval", attr, extra_config, impure, nix_options)
|
output = self.nix("eval", attr, extra_config, nix_options)
|
||||||
if isinstance(output, str):
|
if isinstance(output, str):
|
||||||
self._eval_cache[attr] = output
|
self._eval_cache[attr] = output
|
||||||
return output
|
return output
|
||||||
@@ -278,7 +296,6 @@ class Machine:
|
|||||||
attr: str,
|
attr: str,
|
||||||
refresh: bool = False,
|
refresh: bool = False,
|
||||||
extra_config: None | dict = None,
|
extra_config: None | dict = None,
|
||||||
impure: bool = False,
|
|
||||||
nix_options: list[str] | None = None,
|
nix_options: list[str] | None = None,
|
||||||
) -> Path:
|
) -> Path:
|
||||||
"""
|
"""
|
||||||
@@ -291,7 +308,7 @@ class Machine:
|
|||||||
if attr in self._build_cache and not refresh and extra_config is None:
|
if attr in self._build_cache and not refresh and extra_config is None:
|
||||||
return self._build_cache[attr]
|
return self._build_cache[attr]
|
||||||
|
|
||||||
output = self.nix("build", attr, extra_config, impure, nix_options)
|
output = self.nix("build", attr, extra_config, nix_options)
|
||||||
if isinstance(output, Path):
|
if isinstance(output, Path):
|
||||||
self._build_cache[attr] = output
|
self._build_cache[attr] = output
|
||||||
return output
|
return output
|
||||||
|
|||||||
Reference in New Issue
Block a user