IT WORKS
This commit is contained in:
parent
da509d97c7
commit
3765e918d6
18 changed files with 348 additions and 226 deletions
|
|
@ -46,37 +46,75 @@ def get_config_file() -> str:
|
|||
|
||||
config_file_path = machine.out_dir / config_file.name
|
||||
with open(config_file_path, "r") as f:
|
||||
return f.read()
|
||||
data = f.read()
|
||||
|
||||
config_file_path.unlink()
|
||||
|
||||
return data
|
||||
|
||||
@beartype
|
||||
def dynix_append(option: str, value: str):
|
||||
machine.succeed(f'''
|
||||
dynix append {shlex.quote(option)} {shlex.quote(value)}
|
||||
'''.strip())
|
||||
|
||||
@beartype
|
||||
def do_apply():
|
||||
expr = textwrap.dedent("""
|
||||
let
|
||||
nixos = import <nixpkgs/nixos> { };
|
||||
in nixos.config.dynamicism.applyDynamicConfiguration {
|
||||
baseConfiguration = /etc/nixos/configuration.nix;
|
||||
newConfiguration = /etc/nixos/dynamic.nix;
|
||||
}
|
||||
""").strip()
|
||||
|
||||
machine.succeed(rf"""
|
||||
nix run --show-trace --log-format raw-with-logs --impure -E {shlex.quote(expr)}
|
||||
""".strip())
|
||||
|
||||
|
||||
machine.wait_for_unit("default.target")
|
||||
assert "lix" in machine.succeed("nix --version").lower()
|
||||
machine.log("INIT")
|
||||
machine.wait_for_unit("install-dynix.service")
|
||||
|
||||
dynix_out = machine.succeed("dynix --version")
|
||||
assert "dynix" in dynix_out, f"dynix not in {dynix_out=}"
|
||||
|
||||
machine.log("REBUILDING configuration inside VM")
|
||||
machine.succeed("env PAGER= nixos-rebuild switch --log-format raw-with-logs --fallback")
|
||||
machine.wait_for_unit("gotosocial.service")
|
||||
|
||||
# Make sure the config before any dynamic changes is what we expect.
|
||||
config_text = get_config_file()
|
||||
lines = config_text.splitlines()
|
||||
try:
|
||||
application_name = next(line for line in lines if line.startswith("application-name:"))
|
||||
except StopIteration:
|
||||
raise AssertionError(f"no 'application-name:' found in config file: {textwrap.indent(config_text, " ")}")
|
||||
assert "gotosocial-for-machine" in application_name, f"'gotosocial-for-machine' should be in {application_name=}"
|
||||
|
||||
new_app_name = "yay!"
|
||||
dynix_append("services.gotosocial.settings.application-name", f'"{new_app_name}"')
|
||||
do_apply()
|
||||
|
||||
config_text = get_config_file()
|
||||
lines = config_text.splitlines()
|
||||
try:
|
||||
application_name = next(line for line in lines if line.startswith("application-name:"))
|
||||
except StopIteration:
|
||||
raise AssertionError(f"no 'application-name:' found in config file: {textwrap.indent(config_text, " ")}")
|
||||
assert new_app_name in application_name, f"'{new_app_name}' should be in {application_name=}"
|
||||
|
||||
machine.log("REBUILDING configuration inside VM")
|
||||
machine.succeed("env PAGER= nixos-rebuild switch --log-format raw-with-logs --fallback")
|
||||
|
||||
machine.wait_for_unit("gotosocial.service")
|
||||
|
||||
config_text = get_config_file()
|
||||
lines = config_text.splitlines()
|
||||
application_name = next((line for line in lines if line.startswith("application-name:")), None)
|
||||
assert application_name is not None, f"no 'application-name:' found in config file: {textwrap.indent(config_text, "")}"
|
||||
try:
|
||||
application_name = next(line for line in lines if line.startswith("application-name:"))
|
||||
except StopIteration:
|
||||
raise AssertionError(f"no 'application-name:' found in config file: {textwrap.indent(config_text, " ")}")
|
||||
assert "gotosocial-for-machine" in application_name, f"'gotosocial-for-machine' should be in {application_name=}"
|
||||
|
||||
new_app_name = "yay!"
|
||||
expr = textwrap.dedent(f"""
|
||||
let
|
||||
nixos = import <nixpkgs/nixos> {{ }};
|
||||
in nixos.config.dynamicism.doChange {{
|
||||
option = "services.gotosocial.settings.application-name";
|
||||
value = "{new_app_name}";
|
||||
}}
|
||||
""").strip()
|
||||
machine.succeed(rf"""
|
||||
nix run --show-trace --log-format raw-with-logs --impure -E {shlex.quote(expr)}
|
||||
""".strip())
|
||||
|
||||
config_file_new = get_config_file()
|
||||
lines = config_file_new.splitlines()
|
||||
|
||||
application_name = next(line for line in lines if line.startswith("application-name:"))
|
||||
assert new_app_name in application_name, f"'{new_app_name}' should be in {application_name=}"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
{ mkDynixConfigurationDotNix, config, ... }:
|
||||
|
||||
let
|
||||
testName = config.name;
|
||||
in
|
||||
{
|
||||
name = "nixos-test-dynamicism-gotosocial";
|
||||
|
||||
|
|
@ -9,21 +11,17 @@
|
|||
p.beartype
|
||||
];
|
||||
|
||||
nodes.machine = { pkgs, ... }: {
|
||||
nodes.machine = { ... }: {
|
||||
# NOTE: Anything in this `nodes.machine = ` module will not be included
|
||||
# in the VM's NixOS configuration once it does `nixos-rebuild switch`,
|
||||
# except for `./configuration.nix` which will be copied to `/etc/nixos/`.
|
||||
# dynix will also be statefully installed to root's user profile.
|
||||
imports = [ ./configuration.nix ];
|
||||
|
||||
environment.systemPackages = let
|
||||
configFileTree = mkDynixConfigurationDotNix {
|
||||
inherit (config) name;
|
||||
configuration = ./configuration.nix;
|
||||
};
|
||||
in [
|
||||
configFileTree
|
||||
];
|
||||
passthru.configurationDotNix = mkDynixConfigurationDotNix {
|
||||
name = testName;
|
||||
configuration = ./configuration.nix;
|
||||
};
|
||||
};
|
||||
|
||||
testScript = builtins.readFile ./test-script.py;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue