-
-
Notifications
You must be signed in to change notification settings - Fork 97
meta: initial VM tests setup #551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| pkgs: { | ||
| # This key is used in integration tests | ||
| # This is NOT a security issue | ||
| # It uses the test key defined in RFC 9500 | ||
| # https://datatracker.ietf.org/doc/rfc9500/ | ||
| snakeOilPrivateKey = pkgs.writeText "privkey.snakeoil" '' | ||
| -----BEGIN EC PRIVATE KEY----- | ||
| MHcCAQEEIObLW92AqkWunJXowVR2Z5/+yVPBaFHnEedDk5WJxk/BoAoGCCqGSM49 | ||
| AwEHoUQDQgAEQiVI+I+3gv+17KN0RFLHKh5Vj71vc75eSOkyMsxFxbFsTNEMTLjV | ||
| uKFxOelIgsiZJXKZNCX0FBmrfpCkKklCcg== | ||
| -----END EC PRIVATE KEY----- | ||
| ''; | ||
|
|
||
| snakeOilPublicKey = pkgs.lib.concatStrings [ | ||
| "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHA" | ||
| "yNTYAAABBBEIlSPiPt4L/teyjdERSxyoeVY+9b3O+XkjpMjLMRcWxbEzRDEy41b" | ||
| "ihcTnpSILImSVymTQl9BQZq36QpCpJQnI= snakeoil" | ||
| ]; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,254 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lib, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pkgs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Inherited from flake.nix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nixpkgs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nh, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| modulesPath = "${nixpkgs}/nixos/modules"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| inherit (import ../ssh-keys.nix pkgs) snakeOilPrivateKey snakeOilPublicKey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sshConfig = builtins.toFile "ssh.conf" '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| UserKnownHostsFile=/dev/null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| StrictHostKeyChecking=no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Base configuration for target | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| targetBaseConfig = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| documentation.enable = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| services.openssh.enable = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| system.switch.enable = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Configuration file generator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkConfigFile = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hostname: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pkgs.writeText "configuration-${hostname}.nix" '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import <nixpkgs/nixos> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| configuration = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| imports = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ./hardware-configuration.nix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "${modulesPath}/profiles/installation-device.nix" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| boot.loader.grub = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| enable = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| device = "/dev/vda"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| forceInstall = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| documentation.enable = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| services.openssh.enable = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| system.switch.enable = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| networking.hostName = "${hostname}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| environment.systemPackages = with pkgs; [ hello ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pkgs.testers.nixosTest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name = "nh-remote-test"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| meta.maintainers = with lib.maintainers; [ NotAShelf ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nodes = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lib, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pkgs, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| imports = [ "${modulesPath}/profiles/installation-device.nix" ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nix.settings = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| substituters = lib.mkForce [ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hashed-mirrors = null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| connect-timeout = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| experimental-features = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "nix-command" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "flakes" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| virtualisation = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cores = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| memorySize = 3072; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| system = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| includeBuildDependencies = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| switch.enable = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| build.privateKey = snakeOilPrivateKey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| build.publicKey = snakeOilPublicKey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| services.openssh.enable = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| environment.systemPackages = [ nh ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| users.users.root.openssh.authorizedKeys.keys = [ snakeOilPublicKey ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nodes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lib, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| virtualisation = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cores = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| memorySize = 2048; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vlans = [ 1 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nix.settings = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| substituters = lib.mkForce [ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| experimental-features = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "nix-command" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "flakes" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| system.switch.enable = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| users.users.root.openssh.authorizedKeys.keys = [ nodes.deployer.system.build.publicKey ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| services.openssh.enable = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| environment.systemPackages = [ nh ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| networking.hostName = "target"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buildHost = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nodes, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lib, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| virtualisation = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cores = 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| memorySize = 2048; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vlans = [ 1 ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| nix.settings = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| substituters = lib.mkForce [ ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| experimental-features = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "nix-command" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "flakes" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| system.switch.enable = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| users.users.root.openssh.authorizedKeys.keys = [ nodes.deployer.system.build.publicKey ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| services.openssh.enable = true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| environment.systemPackages = [ nh ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| networking.hostName = "buildHost"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| testScript = '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| start_all() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Wait for all nodes to be ready | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.wait_for_unit("multi-user.target") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target.wait_for_unit("sshd.service") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| buildHost.wait_for_unit("sshd.service") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Setup SSH keys on deployer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed("mkdir -p /root/.ssh") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed("install -m 600 ${snakeOilPrivateKey} /root/.ssh/id_ecdsa") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed("install ${sshConfig} /root/.ssh/config") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Get IP addresses from VLAN interface (eth1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Yeesh. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_ip = target.succeed("ip -4 addr show eth1 | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'").strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| build_host_ip = buildHost.succeed("ip -4 addr show eth1 | grep -oP '(?<=inet\\s)\\d+(\\.\\d+){3}'").strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"Target IP: {target_ip}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"Build host IP: {build_host_ip}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Setup known_hosts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed(f"ssh-keyscan {target_ip} >> /root/.ssh/known_hosts") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed(f"ssh-keyscan {build_host_ip} >> /root/.ssh/known_hosts") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Test SSH connectivity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed(f"ssh root@{target_ip} 'echo SSH to target works'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed(f"ssh root@{build_host_ip} 'echo SSH to buildHost works'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Generate hardware configuration on target and verify it exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target.succeed("nixos-generate-config --dir /root") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target.succeed("ls -la /root/hardware-configuration.nix") # Debug: verify file exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed(f"scp root@{target_ip}:/root/hardware-configuration.nix /root/hardware-configuration.nix") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Copy test configurations to deployer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.copy_from_host("${mkConfigFile "config-1-deployed"}", "/root/configuration-1.nix") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.copy_from_host("${mkConfigFile "config-2-deployed"}", "/root/configuration-2.nix") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.copy_from_host("${mkConfigFile "config-3-deployed"}", "/root/configuration-3.nix") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with subtest("Local build and switch on target"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Copy config to target for local build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed(f"scp /root/configuration-1.nix root@{target_ip}:/root/configuration.nix") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed(f"scp /root/hardware-configuration.nix root@{target_ip}:/root/hardware-configuration.nix") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build locally on target using non-flake syntax | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target.succeed("nh os switch --bypass-root-check -f '<nixpkgs/nixos>'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verify hostname changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_hostname = target.succeed("cat /etc/hostname").strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert target_hostname == "config-1-deployed", f"Expected 'config-1-deployed', got '{target_hostname}'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verify hello package is available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target.succeed("hello --version") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build on deployer, activate on target | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with subtest("Remote build on deployer, deploy to target with --target-host"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed(f"nh os switch --bypass-root-check -f '<nixpkgs/nixos>' --target-host root@{target_ip}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verify hostname changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_hostname = target.succeed("cat /etc/hostname").strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert target_hostname == "config-2-deployed", f"Expected 'config-2-deployed', got '{target_hostname}'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build on buildHost, activate on target (both different from deployer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with subtest("Remote build on buildHost with --build-host, deploy to target with --target-host"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"nh os switch --bypass-root-check -f '<nixpkgs/nixos>' --build-host root@{build_host_ip} --target-host root@{target_ip}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verify hostname changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_hostname = target.succeed("cat /etc/hostname").strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert target_hostname == "config-3-deployed", f"Expected 'config-3-deployed', got '{target_hostname}'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+209
to
+224
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing configuration file setup for remote subtests. The remote build subtests (lines 209-248) run Each remote subtest should copy the appropriate configuration file to Proposed fix for the second subtest # Build on deployer, activate on target
with subtest("Remote build on deployer, deploy to target with --target-host"):
+ deployer.succeed("cp /root/configuration-2.nix /root/configuration.nix")
deployer.succeed(f"nh os switch --bypass-root-check -f '<nixpkgs/nixos>' --target-host root@{target_ip}")Similar changes needed for the other remote subtests with the appropriate configuration file. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with subtest("Remote build and deploy to same host (build-host == target-host)"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Reset target to config-1 first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed(f"nh os switch --bypass-root-check -f '<nixpkgs/nixos>' --target-host root@{target_ip}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build and deploy on target itself via deployer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"nh os switch --bypass-root-check -f '<nixpkgs/nixos>' --build-host root@{target_ip} --target-host root@{target_ip}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verify hostname changed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_hostname = target.succeed("cat /etc/hostname").strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert target_hostname == "config-2-deployed", f"Expected 'config-2-deployed', got '{target_hostname}'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with subtest("Build-only operation with --build-host (no activation)"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Just build, don't activate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed(f"nh os build --bypass-root-check -f '<nixpkgs/nixos>' --build-host root@{build_host_ip}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verify build succeeded by checking result link exists | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| deployer.succeed("test -L result") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Verify target hostname didn't change (still config-2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target_hostname = target.succeed("cat /etc/hostname").strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert target_hostname == "config-2-deployed", f"Hostname should not have changed, got '{target_hostname}'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with subtest("Fail when running as root without --bypass-root-check"): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Attempt to run as root without the bypass flag - should fail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| target.fail("nh os switch -f '<nixpkgs/nixos>'") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect attribute set merge overwrites checks for Linux systems.
The
//operator performs shallow merging at the top level (system keys), not a deep merge of the inner attributes. This means:self.packages.x86_64-linux(containingnh,default) gets overwritten by thegenAttrsresult{ nh-remote-test = ...; }nh-remote-test(correct) but the merge still has issuesTo properly merge nested attrsets, use
lib.recursiveUpdateor restructure:Proposed fix using recursiveUpdate
Alternatively, use
forAllSystemswith conditional logic for a cleaner approach.📝 Committable suggestion
🤖 Prompt for AI Agents