lol

nixos tests: add test for declarative containers, that container config changes are applied on `nixos-rebuild switch` invocations.

danbst 63f8122c 65ff0d5f

+66
+66
nixos/tests/containers-reloadable.nix
··· 1 + import ./make-test.nix ({ pkgs, lib, ...} : 2 + let 3 + client_base = rec { 4 + 5 + containers.test1 = { 6 + autoStart = true; 7 + config = { 8 + environment.etc."check".text = "client_base"; 9 + }; 10 + }; 11 + 12 + # prevent make-test.nix to change IP 13 + networking.interfaces = { 14 + eth1.ip4 = lib.mkOverride 0 [ ]; 15 + }; 16 + }; 17 + in { 18 + name = "cotnainers-reloadable"; 19 + meta = with pkgs.stdenv.lib.maintainers; { 20 + maintainers = [ danbst ]; 21 + }; 22 + 23 + nodes = { 24 + client = { lib, pkgs, ... }: { 25 + imports = [ client_base ]; 26 + }; 27 + 28 + client_c1 = { lib, pkgs, ... }: { 29 + imports = [ client_base ]; 30 + 31 + containers.test1.config = { 32 + environment.etc."check".text = lib.mkForce "client_c1"; 33 + services.httpd.enable = true; 34 + services.httpd.adminAddr = "nixos@example.com"; 35 + }; 36 + }; 37 + client_c2 = { lib, pkgs, ... }: { 38 + imports = [ client_base ]; 39 + 40 + containers.test1.config = { 41 + environment.etc."check".text = lib.mkForce "client_c2"; 42 + services.nginx.enable = true; 43 + }; 44 + }; 45 + }; 46 + 47 + testScript = {nodes, ...}: let 48 + originalSystem = nodes.client.config.system.build.toplevel; 49 + c1System = nodes.client_c1.config.system.build.toplevel; 50 + c2System = nodes.client_c2.config.system.build.toplevel; 51 + in '' 52 + $client->start(); 53 + $client->waitForUnit("default.target"); 54 + $client->succeed("[[ \$(nixos-container run test1 cat /etc/check) == client_base ]] >&2"); 55 + 56 + $client->succeed("${c1System}/bin/switch-to-configuration test >&2"); 57 + $client->succeed("[[ \$(nixos-container run test1 cat /etc/check) == client_c1 ]] >&2"); 58 + $client->succeed("systemctl status httpd -M test1 >&2"); 59 + 60 + $client->succeed("${c2System}/bin/switch-to-configuration test >&2"); 61 + $client->succeed("[[ \$(nixos-container run test1 cat /etc/check) == client_c2 ]] >&2"); 62 + $client->fail("systemctl status httpd -M test1 >&2"); 63 + $client->succeed("systemctl status nginx -M test1 >&2"); 64 + ''; 65 + 66 + })