From 96321123d711867a46350a5db449db3236ec139d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 24 Aug 2024 11:30:26 +0200 Subject: [PATCH 1/5] correct error message about allowed hostnames --- pkgs/clan-cli/clan_cli/machines/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/machines/types.py b/pkgs/clan-cli/clan_cli/machines/types.py index 5c9ce484c..0c7ebd67c 100644 --- a/pkgs/clan-cli/clan_cli/machines/types.py +++ b/pkgs/clan-cli/clan_cli/machines/types.py @@ -17,6 +17,6 @@ def machine_name_type(arg_value: str) -> str: ) if not VALID_HOSTNAME.match(arg_value): raise argparse.ArgumentTypeError( - "Invalid character in machine name. Allowed characters are a-z, 0-9, ., -, and _. Must not start with a number" + "Invalid character in machine name. Allowed characters are a-z, 0-9, ., and -. Must not start with a number" ) return arg_value From 7ba0966da349176716795c181e1b52beebc8cc16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 24 Aug 2024 11:30:35 +0200 Subject: [PATCH 2/5] hw-generate: fix args --- pkgs/clan-cli/clan_cli/machines/hardware.py | 28 +++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index c47d5a37c..e026be9d1 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -1,7 +1,7 @@ import argparse -import dataclasses import json import logging +from dataclasses import dataclass from pathlib import Path from typing import Literal @@ -19,7 +19,7 @@ from .types import machine_name_type log = logging.getLogger(__name__) -@dataclasses.dataclass +@dataclass class HardwareReport: file: Literal["nixos-generate-config", "nixos-facter"] @@ -202,15 +202,29 @@ def generate_machine_hardware_info( return HardwareReport("nixos-generate-config") +@dataclass +class HardwareGenerateOptions: + flake: FlakeId + machine: str + target_host: str | None + password: str | None + force: bool | None + + def hw_generate_command(args: argparse.Namespace) -> None: - hw_info = generate_machine_hardware_info( - args.flake, args.machine, args.hostname, args.password, args.force + opts = HardwareGenerateOptions( + flake=args.flake, + machine=args.machine, + target_host=args.target_host, + password=args.password, + force=args.force, + ) + hw_info = generate_machine_hardware_info( + opts.flake, opts.machine, opts.target_host, opts.password, opts.force ) - print("----") print("Successfully generated hardware information.") - print(f"Target: {args.machine} ({args.hostname})") + print(f"Target: {opts.machine} ({opts.target_host})") print(f"Type: {hw_info.file}") - print("----") def register_hw_generate(parser: argparse.ArgumentParser) -> None: From d365699991bfa24a45fad95ae701ac28530b21b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 24 Aug 2024 11:32:40 +0200 Subject: [PATCH 3/5] use compliant machine name in installation test --- checks/flash/flake-module.nix | 10 +++++----- checks/installation/flake-module.nix | 15 ++++++++------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/checks/flash/flake-module.nix b/checks/flash/flake-module.nix index 5d8a5ae2b..7887005cb 100644 --- a/checks/flash/flake-module.nix +++ b/checks/flash/flake-module.nix @@ -10,10 +10,10 @@ let dependencies = [ pkgs.disko - self.clanInternals.machines.${pkgs.hostPlatform.system}.test_install_machine.config.system.build.toplevel - self.clanInternals.machines.${pkgs.hostPlatform.system}.test_install_machine.config.system.build.diskoScript - self.clanInternals.machines.${pkgs.hostPlatform.system}.test_install_machine.config.system.build.diskoScript.drvPath - self.clanInternals.machines.${pkgs.hostPlatform.system}.test_install_machine.config.system.clan.deployment.file + self.clanInternals.machines.${pkgs.hostPlatform.system}.test-install-machine.config.system.build.toplevel + self.clanInternals.machines.${pkgs.hostPlatform.system}.test-install-machine.config.system.build.diskoScript + self.clanInternals.machines.${pkgs.hostPlatform.system}.test-install-machine.config.system.build.diskoScript.drvPath + self.clanInternals.machines.${pkgs.hostPlatform.system}.test-install-machine.config.system.clan.deployment.file ] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs); closureInfo = pkgs.closureInfo { rootPaths = dependencies; }; in @@ -42,7 +42,7 @@ testScript = '' start_all() - machine.succeed("clan flash --debug --flake ${../..} --yes --disk main /dev/vdb test_install_machine") + machine.succeed("clan flash --debug --flake ${../..} --yes --disk main /dev/vdb test-install-machine") ''; } { inherit pkgs self; }; }; diff --git a/checks/installation/flake-module.nix b/checks/installation/flake-module.nix index ac8ddf847..9cd096bfe 100644 --- a/checks/installation/flake-module.nix +++ b/checks/installation/flake-module.nix @@ -1,14 +1,14 @@ { self, lib, ... }: { - clan.machines.test_install_machine = { - clan.core.networking.targetHost = "test_install_machine"; + clan.machines.test-install-machine = { + clan.core.networking.targetHost = "test-install-machine"; fileSystems."/".device = lib.mkDefault "/dev/vdb"; boot.loader.grub.device = lib.mkDefault "/dev/vdb"; - imports = [ self.nixosModules.test_install_machine ]; + imports = [ self.nixosModules.test-install-machine ]; }; flake.nixosModules = { - test_install_machine = + test-install-machine = { lib, modulesPath, ... }: { imports = [ @@ -34,9 +34,9 @@ let dependencies = [ self - self.nixosConfigurations.test_install_machine.config.system.build.toplevel - self.nixosConfigurations.test_install_machine.config.system.build.diskoScript - self.nixosConfigurations.test_install_machine.config.system.clan.deployment.file + self.nixosConfigurations.test-install-machine.config.system.build.toplevel + self.nixosConfigurations.test-install-machine.config.system.build.diskoScript + self.nixosConfigurations.test-install-machine.config.system.clan.deployment.file pkgs.stdenv.drvPath pkgs.nixos-anywhere ] ++ builtins.map (i: i.outPath) (builtins.attrValues self.inputs); @@ -99,6 +99,7 @@ client.wait_until_succeeds("ssh -o StrictHostKeyChecking=accept-new -v root@target hostname") client.succeed("clan machines install --debug --flake ${../..} --yes test_install_machine root@target >&2") + client.succeed("clan machines install --debug --flake ${../..} --yes test-install-machine root@target >&2") try: target.shutdown() except BrokenPipeError: From a2471bf3ecda160410ed1020a80a52034144787c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 24 Aug 2024 11:32:50 +0200 Subject: [PATCH 4/5] hw-generate: add to nixos test --- checks/installation/flake-module.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/checks/installation/flake-module.nix b/checks/installation/flake-module.nix index 9cd096bfe..7fb1ee8bf 100644 --- a/checks/installation/flake-module.nix +++ b/checks/installation/flake-module.nix @@ -96,9 +96,11 @@ start_all() client.succeed("${pkgs.coreutils}/bin/install -Dm 600 ${../lib/ssh/privkey} /root/.ssh/id_ed25519") - client.wait_until_succeeds("ssh -o StrictHostKeyChecking=accept-new -v root@target hostname") - - client.succeed("clan machines install --debug --flake ${../..} --yes test_install_machine root@target >&2") + client.wait_until_succeeds("timeout 2 ssh -o StrictHostKeyChecking=accept-new -v root@target hostname") + client.succeed("cp -r ${../..} test-flake && chmod -R +w test-flake") + client.fail("test -f test-flake/machines/test-install-machine/hardware-configuration.nix") + client.succeed("clan machines hw-generate --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 install --debug --flake ${../..} --yes test-install-machine root@target >&2") try: target.shutdown() From de34e058f6e88d255920ed3164c0bb072a1d7582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sat, 24 Aug 2024 11:43:49 +0200 Subject: [PATCH 5/5] hw-generate: don't load nixos-install-tools on local machine We only need this on the target. Our installer have it already. --- pkgs/clan-cli/clan_cli/machines/hardware.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/machines/hardware.py b/pkgs/clan-cli/clan_cli/machines/hardware.py index e026be9d1..f7b28863c 100644 --- a/pkgs/clan-cli/clan_cli/machines/hardware.py +++ b/pkgs/clan-cli/clan_cli/machines/hardware.py @@ -120,8 +120,6 @@ def generate_machine_hardware_info( [ "nixpkgs#openssh", "nixpkgs#sshpass", - # Provides nixos-generate-config on non-NixOS systems - "nixpkgs#nixos-install-tools", ], [ *(["sshpass", "-p", f"{password}"] if password else []),