IT WORKS
This commit is contained in:
parent
da509d97c7
commit
3765e918d6
18 changed files with 348 additions and 226 deletions
|
|
@ -39,12 +39,17 @@
|
|||
enable = true;
|
||||
serviceConfig.Type = "oneshot";
|
||||
serviceConfig.RemainAfterExit = true;
|
||||
serviceConfig.RequisteOf = [ "multi-user.target" ];
|
||||
path = [ config.system.path ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
requiredBy = [ "multi-user.target" ];
|
||||
after = [ "default.target" ];
|
||||
script = ''
|
||||
nix profile install -vv "${dynix.modules}" # "
|
||||
if [[ -e /etc/nixos/hardware-configuration.nix ]]; then
|
||||
echo "install-dynix: configuration already copied; nothing to do"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
nix profile install -vv "${dynix.drvPath}^*" # "
|
||||
|
||||
mkdir -vp /etc/nixos
|
||||
nixos-generate-config
|
||||
|
|
@ -58,6 +63,8 @@
|
|||
|
||||
passthru = { inherit options; };
|
||||
|
||||
environment.systemPackages = [ config.passthru.configurationDotNix ];
|
||||
|
||||
# Just making something in this strict in `name`,
|
||||
# which is only present as an argument for nodes and I don't want to
|
||||
# confuse that with the test modules.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import functools
|
|||
#from pprint import pformat
|
||||
import shlex
|
||||
import textwrap
|
||||
from typing import cast, TYPE_CHECKING
|
||||
from typing import Any, cast, TYPE_CHECKING
|
||||
|
||||
from beartype import beartype
|
||||
|
||||
|
|
@ -68,6 +68,27 @@ def get_cli_args() -> argparse.Namespace:
|
|||
args, rest = parser.parse_known_args(cmdline_args)
|
||||
return args
|
||||
|
||||
@beartype
|
||||
def dynix_append(option: str, value: Any):
|
||||
machine.succeed(f'''
|
||||
dynix append {shlex.quote(option)} {shlex.quote(str(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")
|
||||
|
|
@ -89,17 +110,8 @@ args = get_cli_args()
|
|||
#assert int(args['max_connection_rate']) == 256, f"{args['max_connection_rate']=} != 256"
|
||||
#
|
||||
new_jobs = 4
|
||||
expr = textwrap.dedent(f"""
|
||||
let
|
||||
nixos = import <nixpkgs/nixos> {{ }};
|
||||
in nixos.config.dynamicism.doChange {{
|
||||
option = "services.distccd.maxJobs";
|
||||
value = {new_jobs};
|
||||
}}
|
||||
""").strip()
|
||||
machine.succeed(rf"""
|
||||
nix run --show-trace --log-format raw-with-logs --impure -E {shlex.quote(expr)}
|
||||
""".strip())
|
||||
dynix_append("services.distccd.maxJobs", new_jobs)
|
||||
do_apply()
|
||||
|
||||
args = get_cli_args()
|
||||
|
||||
|
|
@ -109,17 +121,8 @@ assert args.job_lifetime == 900, f'{args.job_lifetime} != 900'
|
|||
assert args.log_level == 'warning', f'{args.log_level=} != warning'
|
||||
|
||||
new_log_level = 'error'
|
||||
expr = textwrap.dedent(f"""
|
||||
let
|
||||
nixos = import <nixpkgs/nixos> {{ }};
|
||||
in nixos.config.dynamicism.doChange {{
|
||||
option = "services.distccd.logLevel";
|
||||
value = "{new_log_level}";
|
||||
}}
|
||||
""").strip()
|
||||
machine.succeed(rf"""
|
||||
nix run --show-trace --log-format raw-with-logs --impure -E {shlex.quote(expr)}
|
||||
""".strip())
|
||||
dynix_append("services.distccd.logLevel", f'"{new_log_level}"')
|
||||
do_apply()
|
||||
|
||||
args = get_cli_args()
|
||||
#assert args.jobs == new_jobs, f'{args.jobs=} != {new_jobs=}'
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{ mkDynixConfigurationDotNix, config, ... }:
|
||||
let
|
||||
testName = config.name;
|
||||
in
|
||||
{
|
||||
name = "nixos-test-dynamicism-distccd";
|
||||
|
||||
|
|
@ -6,17 +9,13 @@
|
|||
|
||||
extraPythonPackages = p: [ p.beartype ];
|
||||
|
||||
nodes.machine = { name, pkgs, ... }: {
|
||||
nodes.machine = { ... }: {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -55,6 +55,27 @@ def get_config_file() -> dict[str, Any]:
|
|||
config_file_path.unlink()
|
||||
return config_data
|
||||
|
||||
@beartype
|
||||
def dynix_append(option: str, value: Any):
|
||||
machine.succeed(f'''
|
||||
dynix append {shlex.quote(option)} {shlex.quote(str(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")
|
||||
|
|
@ -75,17 +96,8 @@ assert int(config_toml['workers']) == 4, f"{config_toml['workers']=} != 4"
|
|||
assert int(config_toml['max_connection_rate']) == 256, f"{config_toml['max_connection_rate']=} != 256"
|
||||
|
||||
new_workers = 20
|
||||
expr = textwrap.dedent(f"""
|
||||
let
|
||||
nixos = import <nixpkgs/nixos> {{ }};
|
||||
in nixos.config.dynamicism.doChange {{
|
||||
option = "services.harmonia.settings.workers";
|
||||
value = {new_workers};
|
||||
}}
|
||||
""").strip()
|
||||
machine.succeed(rf"""
|
||||
nix run --show-trace --log-format raw-with-logs --impure -E {shlex.quote(expr)}
|
||||
""".strip())
|
||||
dynix_append("services.harmonia.settings.workers", new_workers)
|
||||
do_apply()
|
||||
|
||||
# Workers, but not max connection rate, should have changed.
|
||||
config_toml = get_config_file()
|
||||
|
|
@ -94,17 +106,8 @@ assert int(config_toml['workers']) == new_workers, f"{config_toml['workers']=} !
|
|||
assert int(config_toml['max_connection_rate']) == 256, f"{config_toml['max_connection_rate']=} != 256"
|
||||
|
||||
new_max_connection_rate = 100
|
||||
expr = textwrap.dedent(f"""
|
||||
let
|
||||
nixos = import <nixpkgs/nixos> {{ }};
|
||||
in nixos.config.dynamicism.doChange {{
|
||||
option = [ "services" "harmonia" "settings" "max_connection_rate" ];
|
||||
value = {new_max_connection_rate};
|
||||
}}
|
||||
""").strip()
|
||||
machine.succeed(rf"""
|
||||
nix run --show-trace --log-format raw-with-logs --impure -E {shlex.quote(expr)}
|
||||
""".strip())
|
||||
dynix_append("services.harmonia.settings.max_connection_rate", new_max_connection_rate)
|
||||
do_apply()
|
||||
|
||||
# Max connection rate should have changed, but workers should have reverted.
|
||||
config_toml = get_config_file()
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
{ mkDynixConfigurationDotNix, config, ... }:
|
||||
let
|
||||
testName = config.name;
|
||||
in
|
||||
{
|
||||
name = "nixos-test-dynamicism-harmonia";
|
||||
|
||||
|
|
@ -6,21 +9,13 @@
|
|||
|
||||
extraPythonPackages = p: [ p.beartype ];
|
||||
|
||||
nodes.machine = { name, pkgs, ... }: {
|
||||
nodes.machine = { ... }: {
|
||||
imports = [ ./configuration.nix ];
|
||||
|
||||
environment.systemPackages = let
|
||||
#configFileTree = pkgs.runCommand "${name}-configuration-dot-nix" { } ''
|
||||
# set -euo pipefail
|
||||
# install -Dm a=r ${./configuration.nix} "$out/share/nixos/configuration.nix"
|
||||
#'';
|
||||
configFileTree = mkDynixConfigurationDotNix {
|
||||
inherit (config) name;
|
||||
configuration = ./configuration.nix;
|
||||
};
|
||||
in [
|
||||
configFileTree
|
||||
];
|
||||
passthru.configurationDotNix = mkDynixConfigurationDotNix {
|
||||
name = testName;
|
||||
configuration = ./configuration.nix;
|
||||
};
|
||||
};
|
||||
|
||||
testScript = builtins.readFile ./test-script.py;
|
||||
|
|
|
|||
|
|
@ -44,6 +44,15 @@
|
|||
echo " ];" >> "$modulesOut/configuration.nix"
|
||||
echo "}" >> "$modulesOut/configuration.nix"
|
||||
|
||||
echo "/** GENERATED BY mk-test-configuration-dot-nix! */" >> "$modulesOut/dynamic.nix"
|
||||
echo "{ lib, ... }:" >> "$modulesOut/dynamic.nix"
|
||||
echo >> "$modulesOut/dynamic.nix"
|
||||
echo >> "$modulesOut/dynamic.nix"
|
||||
echo "{" >> "$modulesOut/dynamic.nix"
|
||||
echo " imports = [ ./configuration.nix ];" >> "$modulesOut/dynamic.nix"
|
||||
echo " config = lib.mkMerge [" >> "$modulesOut/dynamic.nix"
|
||||
echo " ];" >> "$modulesOut/dynamic.nix"
|
||||
echo "}" >> "$modulesOut/dynamic.nix"
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@
|
|||
installBootLoader = true;
|
||||
|
||||
# With how much memory Nix eval uses, this is essentially required.
|
||||
memorySize = 4096;
|
||||
cores = 4;
|
||||
memorySize = 8192;
|
||||
cores = 8;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue