From 07e031f256464483f26f6a574a4734f2aec8f0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 25 Sep 2024 18:17:25 +0200 Subject: [PATCH 01/11] expose nixos-facter in cli --- pkgs/clan-cli/clan_cli/machines/hardware.py | 25 +++++++++++-------- .../app/src/routes/machines/details.tsx | 4 +-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index 62728f0d5..088377a99 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -21,7 +21,7 @@ log = logging.getLogger(__name__) @dataclass class HardwareReport: - file: Literal["nixos-generate-config", "nixos-facter"] + backend: Literal["nixos-generate-config", "nixos-facter"] hw_nix_file = "hardware-configuration.nix" @@ -104,9 +104,7 @@ def generate_machine_hardware_info( password: str | None = None, keyfile: str | None = None, force: bool | None = False, - report_type: Literal[ - "nixos-generate-config", "nixos-facter" - ] = "nixos-generate-config", + backend: Literal["nixos-generate-config", "nixos-facter"] = "nixos-generate-config", ) -> HardwareReport: """ Generate hardware information for a machine @@ -119,7 +117,7 @@ def generate_machine_hardware_info( config_command = ( ["nixos-facter"] - if report_type == "nixos-facter" + if backend == "nixos-facter" else [ "nixos-generate-config", # Filesystems are managed by disko @@ -162,7 +160,7 @@ def generate_machine_hardware_info( raise ClanError(msg) hw_file = Path( - f"{clan_dir}/machines/{machine_name}/{hw_nix_file if report_type == 'nixos-generate-config' else facter_file}" + f"{clan_dir}/machines/{machine_name}/{hw_nix_file if backend == 'nixos-generate-config' else facter_file}" ) hw_file.parent.mkdir(parents=True, exist_ok=True) @@ -213,7 +211,7 @@ def generate_machine_hardware_info( location=f"{__name__} {hw_file}", ) from e - return HardwareReport(report_type) + return HardwareReport(backend) @dataclass @@ -223,6 +221,7 @@ class HardwareGenerateOptions: target_host: str | None password: str | None force: bool | None + backend: Literal["nixos-generate-config", "nixos-facter"] def update_hardware_config_command(args: argparse.Namespace) -> None: @@ -232,13 +231,13 @@ def update_hardware_config_command(args: argparse.Namespace) -> None: target_host=args.target_host, password=args.password, force=args.force, + backend=args.backend, ) - hw_info = generate_machine_hardware_info( - opts.flake, opts.machine, opts.target_host, opts.password + generate_machine_hardware_info( + opts.flake, opts.machine, opts.target_host, opts.password, opts.backend ) print("Successfully generated hardware information.") print(f"Target: {opts.machine} ({opts.target_host})") - print(f"Type: {hw_info.file}") def register_update_hardware_config(parser: argparse.ArgumentParser) -> None: @@ -260,6 +259,12 @@ def register_update_hardware_config(parser: argparse.ArgumentParser) -> None: type=str, required=False, ) + machine_parser = parser.add_argument( + "--backend", + help="The type of hardware report to generate.", + choices=["nixos-generate-config", "nixos-facter"], + default="nixos-generate-config", + ) machine_parser = parser.add_argument( "--force", help="Will overwrite the hardware-configuration.nix file.", diff --git a/pkgs/webview-ui/app/src/routes/machines/details.tsx b/pkgs/webview-ui/app/src/routes/machines/details.tsx index c9af7b02a..7ce800a44 100644 --- a/pkgs/webview-ui/app/src/routes/machines/details.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/details.tsx @@ -81,7 +81,7 @@ const InstallMachine = (props: InstallMachineProps) => { machine_name: props.name, }); if (result.status === "error") throw new Error("Failed to fetch data"); - return result.data?.file === "nixos-facter" || null; + return result.data?.backend === "nixos-facter" || null; } return null; }, @@ -157,7 +157,7 @@ const InstallMachine = (props: InstallMachineProps) => { machine_name: props.name, keyfile: props.sshKey?.name, hostname: props.targetHost, - report_type: "nixos-facter", + backend: "nixos-facter", }); toast.dismiss(loading_toast); hwInfoQuery.refetch(); From 84383a4a485e708295881e4dbb0b124b8c3a537a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 25 Sep 2024 18:40:28 +0200 Subject: [PATCH 02/11] if command fails, print command and exit code, regardless if error message is set --- pkgs/clan-cli/clan_cli/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/__init__.py b/pkgs/clan-cli/clan_cli/__init__.py index fa4463de8..622b7d813 100644 --- a/pkgs/clan-cli/clan_cli/__init__.py +++ b/pkgs/clan-cli/clan_cli/__init__.py @@ -414,9 +414,12 @@ def main() -> None: args.func(args) except ClanError as e: if isinstance(e, ClanCmdError): + msg = "" if e.cmd.msg: - log.fatal(e.cmd.msg) - sys.exit(1) + msg += f"{e.cmd.msg}: " + msg += f"command exited with code {e.cmd.returncode}: {e.cmd.command}" + log.error(msg) # noqa: TRY400 + sys.exit(1) log.fatal(e.msg) if e.description: From 1e11cd79c4accc3af783bbc25313bbf964a3d048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 25 Sep 2024 18:40:43 +0200 Subject: [PATCH 03/11] if error doesn't have a message set, print a stack trace --- pkgs/clan-cli/clan_cli/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/__init__.py b/pkgs/clan-cli/clan_cli/__init__.py index 622b7d813..07e48cc40 100644 --- a/pkgs/clan-cli/clan_cli/__init__.py +++ b/pkgs/clan-cli/clan_cli/__init__.py @@ -421,7 +421,9 @@ def main() -> None: log.error(msg) # noqa: TRY400 sys.exit(1) - log.fatal(e.msg) + if not e.msg: # should not be empty, print stack trace + raise + msg = e.msg if e.description: print(f"========> {e.description}", file=sys.stderr) sys.exit(1) From 1940880dcbb669770c558395df6f15a221ff5322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 29 Sep 2024 16:06:02 +0200 Subject: [PATCH 04/11] put error description in same line as error for cli --- pkgs/clan-cli/clan_cli/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/__init__.py b/pkgs/clan-cli/clan_cli/__init__.py index 07e48cc40..ef0bab226 100644 --- a/pkgs/clan-cli/clan_cli/__init__.py +++ b/pkgs/clan-cli/clan_cli/__init__.py @@ -425,7 +425,8 @@ def main() -> None: raise msg = e.msg if e.description: - print(f"========> {e.description}", file=sys.stderr) + msg += f": {e.description}" + log.error(msg) # noqa: TRY400 sys.exit(1) except KeyboardInterrupt: log.warning("Interrupted by user") From 372a5f390721aa3be6201f8e50cb5d8e51481ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 29 Sep 2024 16:06:27 +0200 Subject: [PATCH 05/11] remove unused location from ClanError --- pkgs/clan-cli/clan_cli/machines/hardware.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index 088377a99..5ef3fccfa 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -168,11 +168,10 @@ def generate_machine_hardware_info( is_template = hw_file.exists() and "throw" in hw_file.read_text() if hw_file.exists() and not force and not is_template: - msg = "File exists." + msg = "File exists" raise ClanError( msg, - description="Hardware file already exists. To force overwrite the existing configuration use '--force'.", - location=f"{__name__} {hw_file}", + description=f"'{hw_file}' already exists. To force overwrite the existing configuration use '--force'.", ) backup_file = None @@ -207,8 +206,7 @@ def generate_machine_hardware_info( msg = "Invalid hardware-configuration.nix file" raise ClanError( msg, - description="The hardware-configuration.nix file is invalid. Please check the file and try again.", - location=f"{__name__} {hw_file}", + description=f"Configuration at '{hw_file}' is invalid. Please check the file and try again.", ) from e return HardwareReport(backend) From 7816a3e6397f83388a8752980bc746352be19c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 29 Sep 2024 16:14:34 +0200 Subject: [PATCH 06/11] don't expose polymorphic api --- pkgs/clan-cli/clan_cli/machines/hardware.py | 22 ++++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index 5ef3fccfa..b53371b4a 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -30,13 +30,13 @@ facter_file = "facter.json" @API.register def show_machine_hardware_info( - clan_dir: str | Path, machine_name: str + clan_dir: Path, machine_name: str ) -> HardwareReport | None: """ Show hardware information for a machine returns None if none exist. """ - hw_file = Path(f"{clan_dir}/machines/{machine_name}/{hw_nix_file}") + hw_file = Path(clan_dir) / "machines" / machine_name / hw_nix_file is_template = hw_file.exists() and "throw" in hw_file.read_text() if hw_file.exists() and not is_template: @@ -49,9 +49,7 @@ def show_machine_hardware_info( @API.register -def show_machine_deployment_target( - clan_dir: str | Path, machine_name: str -) -> str | None: +def show_machine_deployment_target(clan_dir: Path, machine_name: str) -> str | None: """ Show deployment target for a machine returns None if none exist. """ @@ -73,9 +71,7 @@ def show_machine_deployment_target( @API.register -def show_machine_hardware_platform( - clan_dir: str | Path, machine_name: str -) -> str | None: +def show_machine_hardware_platform(clan_dir: Path, machine_name: str) -> str | None: """ Show hardware information for a machine returns None if none exist. """ @@ -159,13 +155,15 @@ def generate_machine_hardware_info( msg = f"Failed to inspect {machine_name}. Address: {hostname}" raise ClanError(msg) - hw_file = Path( - f"{clan_dir}/machines/{machine_name}/{hw_nix_file if backend == 'nixos-generate-config' else facter_file}" - ) + hw_file = clan_dir.path / "machines" / machine_name + if backend == "nixos-generate-config": + hw_file /= hw_nix_file + else: + hw_file /= facter_file hw_file.parent.mkdir(parents=True, exist_ok=True) # Check if the hardware-configuration.nix file is a template - is_template = hw_file.exists() and "throw" in hw_file.read_text() + is_template = hw_file.exists() and "throw ''" in hw_file.read_text() if hw_file.exists() and not force and not is_template: msg = "File exists" From b4652539a53d4174f9967a098627f2c57bbd929a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 29 Sep 2024 16:39:33 +0200 Subject: [PATCH 07/11] wrap hardware generate arguments into an object --- pkgs/clan-cli/clan_cli/machines/hardware.py | 101 ++++++++---------- .../app/src/routes/machines/details.tsx | 12 ++- 2 files changed, 52 insertions(+), 61 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index b53371b4a..0406010c2 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -92,35 +92,54 @@ def show_machine_hardware_platform(clan_dir: Path, machine_name: str) -> str | N return host_platform.get("system", None) +@dataclass +class HardwareGenerateOptions: + flake: FlakeId + machine: str + backend: Literal["nixos-generate-config", "nixos-facter"] + force: bool = False + target_host: str | None = None + keyfile: str | None = None + password: str | None = None + + @API.register -def generate_machine_hardware_info( - clan_dir: FlakeId, - machine_name: str, - hostname: str | None = None, - password: str | None = None, - keyfile: str | None = None, - force: bool | None = False, - backend: Literal["nixos-generate-config", "nixos-facter"] = "nixos-generate-config", -) -> HardwareReport: +def generate_machine_hardware_info(opts: HardwareGenerateOptions) -> HardwareReport: """ Generate hardware information for a machine and place the resulting *.nix file in the machine's directory. """ - machine = Machine(machine_name, flake=clan_dir) - if hostname is not None: - machine.target_host_address = hostname + machine = Machine(opts.machine, flake=opts.flake) + if opts.target_host is not None: + machine.target_host_address = opts.target_host - config_command = ( - ["nixos-facter"] - if backend == "nixos-facter" - else [ + hw_file = opts.flake.path / "machines" / opts.machine + if opts.backend == "nixos-generate-config": + hw_file /= hw_nix_file + else: + hw_file /= facter_file + + # Check if the hardware-configuration.nix file is a template + is_template = hw_file.exists() and "throw ''" in hw_file.read_text() + + if hw_file.exists() and not opts.force and not is_template: + msg = "File exists" + raise ClanError( + msg, + description=f"'{hw_file}' already exists. To force overwrite the existing configuration use '--force'.", + ) + hw_file.parent.mkdir(parents=True, exist_ok=True) + + if opts.backend == "nixos-facter": + config_command = ["nixos-facter"] + else: + config_command = [ "nixos-generate-config", # Filesystems are managed by disko "--no-filesystems", "--show-hardware-config", ] - ) host = machine.target_host target_host = f"{host.user or 'root'}@{host.host}" @@ -130,9 +149,9 @@ def generate_machine_hardware_info( "nixpkgs#sshpass", ], [ - *(["sshpass", "-p", f"{password}"] if password else []), + *(["sshpass", "-p", opts.password] if opts.password else []), "ssh", - *(["-i", f"{keyfile}"] if keyfile else []), + *(["-i", f"{opts.keyfile}"] if opts.keyfile else []), # Disable known hosts file "-o", "UserKnownHostsFile=/dev/null", @@ -150,30 +169,12 @@ def generate_machine_hardware_info( ) out = run(cmd) if out.returncode != 0: - log.error(f"Failed to inspect {machine_name}. Address: {hostname}") log.error(out) - msg = f"Failed to inspect {machine_name}. Address: {hostname}" + msg = f"Failed to inspect {opts.machine}. Address: {opts.target_host}" raise ClanError(msg) - hw_file = clan_dir.path / "machines" / machine_name - if backend == "nixos-generate-config": - hw_file /= hw_nix_file - else: - hw_file /= facter_file - hw_file.parent.mkdir(parents=True, exist_ok=True) - - # Check if the hardware-configuration.nix file is a template - is_template = hw_file.exists() and "throw ''" in hw_file.read_text() - - if hw_file.exists() and not force and not is_template: - msg = "File exists" - raise ClanError( - msg, - description=f"'{hw_file}' already exists. To force overwrite the existing configuration use '--force'.", - ) - backup_file = None - if hw_file.exists() and force: + if hw_file.exists() and opts.force: # Backup the existing file backup_file = hw_file.with_suffix(".bak") hw_file.replace(backup_file) @@ -188,11 +189,11 @@ def generate_machine_hardware_info( commit_file( hw_file, - clan_dir.path, - f"HW/report: Hardware configuration for {machine_name}", + opts.flake.path, + f"HW/report: Hardware configuration for {opts.machine}", ) try: - show_machine_hardware_platform(clan_dir.path, machine_name) + show_machine_hardware_platform(opts.flake.path, opts.machine) except ClanCmdError as e: log.exception("Failed to evaluate hardware-configuration.nix") # Restore the backup file @@ -207,17 +208,7 @@ def generate_machine_hardware_info( description=f"Configuration at '{hw_file}' is invalid. Please check the file and try again.", ) from e - return HardwareReport(backend) - - -@dataclass -class HardwareGenerateOptions: - flake: FlakeId - machine: str - target_host: str | None - password: str | None - force: bool | None - backend: Literal["nixos-generate-config", "nixos-facter"] + return HardwareReport(opts.backend) def update_hardware_config_command(args: argparse.Namespace) -> None: @@ -229,9 +220,7 @@ def update_hardware_config_command(args: argparse.Namespace) -> None: force=args.force, backend=args.backend, ) - generate_machine_hardware_info( - opts.flake, opts.machine, opts.target_host, opts.password, opts.backend - ) + generate_machine_hardware_info(opts) print("Successfully generated hardware information.") print(f"Target: {opts.machine} ({opts.target_host})") diff --git a/pkgs/webview-ui/app/src/routes/machines/details.tsx b/pkgs/webview-ui/app/src/routes/machines/details.tsx index 7ce800a44..3eb690f9c 100644 --- a/pkgs/webview-ui/app/src/routes/machines/details.tsx +++ b/pkgs/webview-ui/app/src/routes/machines/details.tsx @@ -153,11 +153,13 @@ const InstallMachine = (props: InstallMachineProps) => { const loading_toast = toast.loading("Generating hardware report..."); const r = await callApi("generate_machine_hardware_info", { - clan_dir: { loc: curr_uri }, - machine_name: props.name, - keyfile: props.sshKey?.name, - hostname: props.targetHost, - backend: "nixos-facter", + opts: { + flake: { loc: curr_uri }, + machine: props.name, + keyfile: props.sshKey?.name, + target_host: props.targetHost, + backend: "nixos-facter", + }, }); toast.dismiss(loading_toast); hwInfoQuery.refetch(); From bf7246104d0bf78e6abb978a171f8ef98eb5ba89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 29 Sep 2024 16:45:14 +0200 Subject: [PATCH 08/11] allow to overwrite hardware configuration now that we call it "update" hardware configurration and we are heading towards facter anyway, we don't need all the force overide logic. Just allow this to be overwritten by default. --- pkgs/clan-cli/clan_cli/machines/hardware.py | 22 --------------------- 1 file changed, 22 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index 0406010c2..a725a2506 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -97,7 +97,6 @@ class HardwareGenerateOptions: flake: FlakeId machine: str backend: Literal["nixos-generate-config", "nixos-facter"] - force: bool = False target_host: str | None = None keyfile: str | None = None password: str | None = None @@ -120,15 +119,6 @@ def generate_machine_hardware_info(opts: HardwareGenerateOptions) -> HardwareRep else: hw_file /= facter_file - # Check if the hardware-configuration.nix file is a template - is_template = hw_file.exists() and "throw ''" in hw_file.read_text() - - if hw_file.exists() and not opts.force and not is_template: - msg = "File exists" - raise ClanError( - msg, - description=f"'{hw_file}' already exists. To force overwrite the existing configuration use '--force'.", - ) hw_file.parent.mkdir(parents=True, exist_ok=True) if opts.backend == "nixos-facter": @@ -174,12 +164,6 @@ def generate_machine_hardware_info(opts: HardwareGenerateOptions) -> HardwareRep raise ClanError(msg) backup_file = None - if hw_file.exists() and opts.force: - # Backup the existing file - backup_file = hw_file.with_suffix(".bak") - hw_file.replace(backup_file) - print(f"Backed up existing {hw_file} to {backup_file}") - with hw_file.open("w") as f: f.write(out.stdout) print(f"Successfully generated: {hw_file}") @@ -217,7 +201,6 @@ def update_hardware_config_command(args: argparse.Namespace) -> None: machine=args.machine, target_host=args.target_host, password=args.password, - force=args.force, backend=args.backend, ) generate_machine_hardware_info(opts) @@ -250,9 +233,4 @@ def register_update_hardware_config(parser: argparse.ArgumentParser) -> None: choices=["nixos-generate-config", "nixos-facter"], default="nixos-generate-config", ) - machine_parser = parser.add_argument( - "--force", - help="Will overwrite the hardware-configuration.nix file.", - action="store_true", - ) add_dynamic_completer(machine_parser, complete_machines) From 9cf2bd4f6ea4a484cc5b933f23ea0c37dd2160fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 29 Sep 2024 16:47:51 +0200 Subject: [PATCH 09/11] make default hardware report commit message nicer --- pkgs/clan-cli/clan_cli/machines/hardware.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index a725a2506..270485437 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -174,7 +174,7 @@ def generate_machine_hardware_info(opts: HardwareGenerateOptions) -> HardwareRep commit_file( hw_file, opts.flake.path, - f"HW/report: Hardware configuration for {opts.machine}", + f"machines/{opts.machine}/{hw_file.name}: update hardware configuration", ) try: show_machine_hardware_platform(opts.flake.path, opts.machine) From 62af2bab55a265fd6399e1cfc9714601d2d14b23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 29 Sep 2024 16:54:49 +0200 Subject: [PATCH 10/11] fix broken eval check when nixpkgs.pkgs nixos option is used --- pkgs/clan-cli/clan_cli/machines/hardware.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index 270485437..d506e188b 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -81,7 +81,7 @@ def show_machine_hardware_platform(clan_dir: Path, machine_name: str) -> str | N [ f"{clan_dir}#clanInternals.machines.{system}.{machine_name}", "--apply", - "machine: { inherit (machine.config.nixpkgs.hostPlatform) system; }", + "machine: { inherit (machine.pkgs) system; }", "--json", ] ) @@ -164,9 +164,11 @@ def generate_machine_hardware_info(opts: HardwareGenerateOptions) -> HardwareRep raise ClanError(msg) backup_file = None - with hw_file.open("w") as f: - f.write(out.stdout) - print(f"Successfully generated: {hw_file}") + if hw_file.exists(): + backup_file = hw_file.with_suffix(".bak") + hw_file.replace(backup_file) + hw_file.write_text(out.stdout) + print(f"Successfully generated: {hw_file}") # try to evaluate the machine # If it fails, the hardware-configuration.nix file is invalid @@ -204,8 +206,6 @@ def update_hardware_config_command(args: argparse.Namespace) -> None: backend=args.backend, ) generate_machine_hardware_info(opts) - print("Successfully generated hardware information.") - print(f"Target: {opts.machine} ({opts.target_host})") def register_update_hardware_config(parser: argparse.ArgumentParser) -> None: From 5f4bf819dff9a79ffe1469736a71e6f5f7f141a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 29 Sep 2024 16:55:38 +0200 Subject: [PATCH 11/11] add nixos-facter to nixos installation test --- checks/installation/flake-module.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/checks/installation/flake-module.nix b/checks/installation/flake-module.nix index 485298e21..3ab30c8be 100644 --- a/checks/installation/flake-module.nix +++ b/checks/installation/flake-module.nix @@ -50,6 +50,7 @@ services.openssh.enable = true; users.users.root.openssh.authorizedKeys.keyFiles = [ ../lib/ssh/pubkey ]; system.nixos.variant_id = "installer"; + environment.systemPackages = [ pkgs.nixos-facter ]; virtualisation.emptyDiskImages = [ 4096 ]; nix.settings = { substituters = lib.mkForce [ ]; @@ -101,6 +102,8 @@ client.fail("test -f test-flake/machines/test-install-machine/hardware-configuration.nix") client.succeed("clan machines update-hardware-config --flake test-flake test-install-machine root@target>&2") client.succeed("test -f test-flake/machines/test-install-machine/hardware-configuration.nix") + client.succeed("clan machines update-hardware-config --backend nixos-facter --flake test-flake test-install-machine root@target>&2") + client.succeed("test -f test-flake/machines/test-install-machine/facter.json") client.succeed("clan machines install --debug --flake ${../..} --yes test-install-machine root@target >&2") try: target.shutdown()