add distccd
This commit is contained in:
parent
af46de5628
commit
3ed2f2e1a8
7 changed files with 227 additions and 11 deletions
50
modules/dynamicism/distccd.nix
Normal file
50
modules/dynamicism/distccd.nix
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
{ pkgs, lib, config, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.services.distccd;
|
||||||
|
|
||||||
|
cliArgs = lib.cli.toCommandLineShellGNU { explicitBool = false; } {
|
||||||
|
no-detach = true;
|
||||||
|
daemon = true;
|
||||||
|
enable-tcp-insecure = true;
|
||||||
|
port = cfg.port;
|
||||||
|
|
||||||
|
# Nulls are handled automatically.
|
||||||
|
job-lifetime = cfg.jobTimeout;
|
||||||
|
log-level = cfg.logLevel;
|
||||||
|
jobs = cfg.maxJobs;
|
||||||
|
nice = cfg.nice;
|
||||||
|
stats = cfg.stats.enable;
|
||||||
|
stats-port = if cfg.stats.enable then cfg.stats.port else null;
|
||||||
|
zeroconf = cfg.zeroconf;
|
||||||
|
allow = cfg.allowedClients;
|
||||||
|
};
|
||||||
|
|
||||||
|
startDistccd = pkgs.writeShellApplication {
|
||||||
|
name = "start-distccd";
|
||||||
|
runtimeInputs = [ pkgs.distccMasquerade ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
${lib.getExe' cfg.package "distccd"} \
|
||||||
|
${cliArgs}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
dynamicism.for.distccd = {
|
||||||
|
source-options = [
|
||||||
|
"services.distccd.jobTimeout"
|
||||||
|
"services.distccd.logLevel"
|
||||||
|
"services.distccd.maxJobs"
|
||||||
|
"services.distccd.nice"
|
||||||
|
];
|
||||||
|
unitDropins."distccd.service" = pkgs.writeTextFile {
|
||||||
|
name = "distccd-override.conf";
|
||||||
|
text = ''
|
||||||
|
[Service]
|
||||||
|
ExecStart=
|
||||||
|
ExecStart=${lib.getExe startDistccd}
|
||||||
|
'';
|
||||||
|
passthru.startScript = startDistccd;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -138,6 +138,6 @@ in
|
||||||
imports = [
|
imports = [
|
||||||
./gotosocial.nix
|
./gotosocial.nix
|
||||||
./harmonia.nix
|
./harmonia.nix
|
||||||
#./tzupdate.nix
|
./distccd.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,16 +83,18 @@ in
|
||||||
doEdits = config.unitDropins
|
doEdits = config.unitDropins
|
||||||
|> lib.mapAttrsToList (service: dropin: ''
|
|> lib.mapAttrsToList (service: dropin: ''
|
||||||
cat "${dropin}" | systemctl edit "${service}" --runtime --drop=dynix-${dropin.name} --stdin
|
cat "${dropin}" | systemctl edit "${service}" --runtime --drop=dynix-${dropin.name} --stdin
|
||||||
'');
|
'')
|
||||||
|
|> lib.concatStringsSep "\n";
|
||||||
doReloads = config.unitDropins
|
doReloads = config.unitDropins
|
||||||
|> lib.mapAttrsToList (service: _: ''
|
|> lib.mapAttrsToList (service: _: ''
|
||||||
systemctl reload-or-restart "${service}"
|
systemctl reload-or-restart "${service}"
|
||||||
'');
|
'')
|
||||||
in [
|
|> lib.concatStringsSep "\n";
|
||||||
doEdits
|
in ''
|
||||||
doReloads
|
${doEdits}
|
||||||
] |> lib.concatLists
|
|
||||||
|> lib.concatStringsSep "\n";
|
${doReloads}
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,5 +68,5 @@
|
||||||
in lib.makeScope lib.callPackageWith (self: {
|
in lib.makeScope lib.callPackageWith (self: {
|
||||||
gotosocial = runDynixTest ./gotosocial/test.nix;
|
gotosocial = runDynixTest ./gotosocial/test.nix;
|
||||||
harmonia = runDynixTest ./harmonia/test.nix;
|
harmonia = runDynixTest ./harmonia/test.nix;
|
||||||
#tzupdate = runDynixTest ./tzupdate/test.nix;
|
distccd = runDynixTest ./distccd/test.nix;
|
||||||
})
|
})
|
||||||
|
|
|
||||||
14
tests/distccd/configuration.nix
Normal file
14
tests/distccd/configuration.nix
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
services.distccd = {
|
||||||
|
enable = true;
|
||||||
|
jobTimeout = 900;
|
||||||
|
maxJobs = 12;
|
||||||
|
nice = -10;
|
||||||
|
};
|
||||||
|
|
||||||
|
dynamicism.for.distccd.enable = true;
|
||||||
|
|
||||||
|
networking.hostName = "distccd-machine";
|
||||||
|
}
|
||||||
|
|
||||||
127
tests/distccd/test-script.py
Normal file
127
tests/distccd/test-script.py
Normal file
|
|
@ -0,0 +1,127 @@
|
||||||
|
import argparse
|
||||||
|
import functools
|
||||||
|
#from pathlib import Path
|
||||||
|
#from pprint import pformat
|
||||||
|
import shlex
|
||||||
|
import textwrap
|
||||||
|
from typing import cast, TYPE_CHECKING
|
||||||
|
|
||||||
|
from beartype import beartype
|
||||||
|
|
||||||
|
from test_driver.machine import Machine
|
||||||
|
from test_driver.errors import RequestedAssertionFailed
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
global machine
|
||||||
|
machine = cast(Machine, ...)
|
||||||
|
assert machine.shell is not None
|
||||||
|
|
||||||
|
ls = "eza -lah --color=always --group-directories-first"
|
||||||
|
|
||||||
|
indent = functools.partial(textwrap.indent, prefix=' ')
|
||||||
|
|
||||||
|
@beartype
|
||||||
|
def run_log(machine: Machine, *commands: str, timeout: int | None = 60) -> str:
|
||||||
|
output = ""
|
||||||
|
for command in commands:
|
||||||
|
with machine.nested(f"must succeed: {command}"):
|
||||||
|
(status, out) = machine.execute(f"{command} | tee /dev/stderr", timeout=timeout)
|
||||||
|
if status != 0:
|
||||||
|
machine.log(f"output: {out}")
|
||||||
|
raise RequestedAssertionFailed(
|
||||||
|
f"command `{command}` failed (exit code {status})",
|
||||||
|
)
|
||||||
|
output += out
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
#parser.add_argument("--no-detach", action="store_true")
|
||||||
|
#parser.add_argument("--daemon", action="store_true")
|
||||||
|
#parser.add_argument("--enable-tcp-insecure", action="store_true")
|
||||||
|
#parser.add_argument("--port", type=int)
|
||||||
|
parser.add_argument("--jobs", type=int)
|
||||||
|
parser.add_argument("--job-lifetime", type=int)
|
||||||
|
parser.add_argument("--log-level", type=str)
|
||||||
|
#parser.add_argument("--nice", type=int)
|
||||||
|
#parser.add_argument("--stats", action="store_true")
|
||||||
|
#parser.add_argument("--stats-port", type=int)
|
||||||
|
|
||||||
|
@beartype
|
||||||
|
def get_cli_args() -> argparse.Namespace:
|
||||||
|
machine.wait_for_unit("distccd.service")
|
||||||
|
mainpid = int(machine.get_unit_property("distccd.service", "MainPID"))
|
||||||
|
machine.log(f"{mainpid=}")
|
||||||
|
pidtext = machine.succeed(f"pgrep -P {mainpid}")
|
||||||
|
machine.log(f"{pidtext=}")
|
||||||
|
pid = int(pidtext.splitlines()[0])
|
||||||
|
machine.log(f"{pid=}")
|
||||||
|
execstart = machine.get_unit_property("distccd.service", "ExecStart")
|
||||||
|
print(f"{execstart=}")
|
||||||
|
|
||||||
|
cmdline = machine.succeed(f"cat /proc/{pid}/cmdline")
|
||||||
|
cmdline_args = cmdline.split("\0")
|
||||||
|
machine.log(f"{cmdline_args=}")
|
||||||
|
print(f"{cmdline_args=}")
|
||||||
|
|
||||||
|
#return shlex.join(cmdline_args[1:])
|
||||||
|
args, rest = parser.parse_known_args(cmdline_args)
|
||||||
|
return args
|
||||||
|
|
||||||
|
machine.wait_for_unit("default.target")
|
||||||
|
assert "lix" in machine.succeed("nix --version").lower()
|
||||||
|
machine.log("INIT")
|
||||||
|
|
||||||
|
# Config should have our initial values.
|
||||||
|
args = get_cli_args()
|
||||||
|
#assert '--jobs 12' in args, f'--jobs 12 not in {args=}'
|
||||||
|
assert args.jobs == 12, f'{args.jobs=} != 12'
|
||||||
|
assert args.job_lifetime == 900, f'{args.job_lifetime} != 900'
|
||||||
|
assert args.log_level == 'warning', f'{args.log_level=} != warning'
|
||||||
|
|
||||||
|
with machine.nested("must succeed: initial nixos-rebuild switch"):
|
||||||
|
machine.succeed("env PAGER= nixos-rebuild switch --log-format raw-with-logs --fallback")
|
||||||
|
|
||||||
|
# Config should not have changed.
|
||||||
|
args = get_cli_args()
|
||||||
|
#machine.log(f"config.toml after first rebuild: {indent(pformat(args))}")
|
||||||
|
#assert int(args['workers']) == 4, f"{args['workers']=} != 4"
|
||||||
|
#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())
|
||||||
|
|
||||||
|
args = get_cli_args()
|
||||||
|
|
||||||
|
# Only jobs should have changed. The others should still be default.
|
||||||
|
assert args.jobs == new_jobs, f'{args.jobs=} != {new_jobs=}'
|
||||||
|
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())
|
||||||
|
|
||||||
|
args = get_cli_args()
|
||||||
|
#assert args.jobs == new_jobs, f'{args.jobs=} != {new_jobs=}'
|
||||||
|
#assert args.job_lifetime == 900, f'{args.job_lifetime} != 900'
|
||||||
|
assert args.log_level == new_log_level, f'{args.log_level=} != {new_log_level=}'
|
||||||
23
tests/distccd/test.nix
Normal file
23
tests/distccd/test.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
{ mkDynixConfigurationDotNix, config, ... }:
|
||||||
|
{
|
||||||
|
name = "nixos-test-dynamicism-distccd";
|
||||||
|
|
||||||
|
defaults = { ... }: { };
|
||||||
|
|
||||||
|
extraPythonPackages = p: [ p.beartype ];
|
||||||
|
|
||||||
|
nodes.machine = { name, pkgs, ... }: {
|
||||||
|
imports = [ ./configuration.nix ];
|
||||||
|
|
||||||
|
environment.systemPackages = let
|
||||||
|
configFileTree = mkDynixConfigurationDotNix {
|
||||||
|
inherit (config) name;
|
||||||
|
configuration = ./configuration.nix;
|
||||||
|
};
|
||||||
|
in [
|
||||||
|
configFileTree
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript = builtins.readFile ./test-script.py;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue