Files
nixos-router/tests/common.nix
T
nilsandClaude Sonnet 5.5 3fc54e678e Update from a git repository
router.update.repository names a public repository whose tags vX.Y.Z are
releases. router-update check (daily, and from the Updates page) looks for a
newer one and the Overview says so; router-update --git builds the router
from a tag like a bundle update: the settings are migrated, the new version
must be confirmed, the nixpkgs pin stays. The flake of such a router comes
from the release's config-flake.nix. The global flake registry is off.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 08:57:00 +01:00

95 lines
3.5 KiB
Nix

# Pieces shared by the VM tests.
{
# `fail` in a test script also passes on "command not found", so make sure
# the tools the scripts rely on are really there.
tools =
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [
dnsutils
netcat-openbsd
curl
tcpdump
wireguard-tools
jq
];
};
# channels.nixos.org as a test sees it: `<branch>/git-revision` is a redirect to
# /files/<branch>/git-revision, served from /srv/channels on port 8080.
channelServer =
pkgs:
pkgs.writeScript "channels.py" ''
#!${pkgs.python3}/bin/python3
import http.server
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory="/srv/channels", **kwargs)
def do_GET(self):
parts = self.path.strip("/").split("/")
if len(parts) == 2 and parts[1] == "git-revision":
self.send_response(302)
self.send_header("Location", "/files/" + self.path.strip("/"))
self.end_headers()
else:
super().do_GET()
http.server.ThreadingHTTPServer(("0.0.0.0", 8080), Handler).serve_forever()
'';
# A git server over (smart) HTTP: `git http-backend` for the repositories under
# the directory in argv[1], on the port in argv[2]. Enough for ls-remote and fetch.
gitServer =
pkgs:
pkgs.writeScript "git-server.py" ''
#!${pkgs.python3}/bin/python3
import http.server, os, subprocess, sys
root, port = sys.argv[1], int(sys.argv[2])
class Handler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
self.cgi()
def do_POST(self):
self.cgi()
def cgi(self):
path, _, query = self.path.partition("?")
body = self.rfile.read(int(self.headers.get("Content-Length") or 0))
env = dict(os.environ, GIT_PROJECT_ROOT=root, GIT_HTTP_EXPORT_ALL="1", PATH_INFO=path,
QUERY_STRING=query, REQUEST_METHOD=self.command, REMOTE_ADDR=self.client_address[0],
CONTENT_TYPE=self.headers.get("Content-Type", ""), CONTENT_LENGTH=str(len(body)),
HTTP_CONTENT_ENCODING=self.headers.get("Content-Encoding", ""))
done = subprocess.run(["${pkgs.git}/bin/git", "http-backend"], input=body, env=env, capture_output=True)
head, _, out = done.stdout.partition(b"\r\n\r\n")
status, headers = 200, []
for line in head.split(b"\r\n"):
name, _, value = line.decode().partition(": ")
if name.lower() == "status":
status = int(value.split()[0])
elif name:
headers.append((name, value))
self.send_response(status)
for name, value in headers:
self.send_header(name, value)
self.send_header("Content-Length", str(len(out)))
self.end_headers()
self.wfile.write(out)
def log_message(self, *args):
pass
http.server.ThreadingHTTPServer(("0.0.0.0", port), Handler).serve_forever()
'';
# `driverInteractive` uses the full QEMU, which would open a window per VM;
# `nix run .#lab` wants the consoles in the terminal instead.
interactiveDefaults.virtualisation.qemu.options = [
"-display"
"none"
];
}