Author SHA1 Message Date
Floweynt d00b1b3727 better cache management
diff-pr / dix (pull_request) Successful in 8m1s
flake-check / flake-check (pull_request) Successful in 51s
lint / lint (pull_request) Successful in 1m48s
2026-09-10 19:44:52 -05:00
Floweynt 0bda3d3712 ci: fix reviewdog
flake-check / flake-check (push) Successful in 17m3s
lint / lint (push) Canceled after 0s
diff-tag / dix (push) Successful in 8m9s
2026-09-10 19:30:46 -05:00
Floweynt cbfdc8c4f2 fix CI runs
diff-tag / dix (push) Successful in 6m11s
flake-check / flake-check (push) Successful in 52s
lint / lint (push) Successful in 1m49s
2026-09-10 18:30:14 -05:00
11 changed files with 254 additions and 221 deletions
+10 -10
View File
@@ -19,18 +19,18 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: pick reporter
run: |
if [ "${{ github.event_name }}" = pull_request ]; then
echo "REPORTER=gitea-pr-review" >> "$GITHUB_ENV"
else
echo "REPORTER=local" >> "$GITHUB_ENV"
fi
- name: run linters - name: run linters
run: nix run -L .#ci -- lint . "$RUNNER_TEMP/findings" run: nix run -L .#ci -- lint . "$RUNNER_TEMP/findings"
- name: report findings - name: report findings
if: always()
env: env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} REVIEWDOG_GITEA_API_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: nix run -L .#ci -- lint-report "$REPORTER" "$RUNNER_TEMP/findings" GITEA_ADDRESS: ${{ github.server_url }}
run: |
if [ "${{ github.event_name }}" = pull_request ]; then
nix run -L .#ci -- lint-report gitea-pr-review "$RUNNER_TEMP/findings"
else
nix run -L .#ci -- lint-summary "$RUNNER_TEMP/findings" \
| tee -a "$GITHUB_STEP_SUMMARY"
fi
+1
View File
@@ -3,6 +3,7 @@
# runner's own nix, not a pinned one). # runner's own nix, not a pinned one).
pkgs.writers.writePython3Bin "ci" { pkgs.writers.writePython3Bin "ci" {
flakeIgnore = [ "E501" ]; flakeIgnore = [ "E501" ];
libraries = [ pkgs.python3Packages.subprocess-tee ];
makeWrapperArgs = [ makeWrapperArgs = [
"--prefix" "--prefix"
"PATH" "PATH"
+57 -2
View File
@@ -6,6 +6,7 @@ import json
import os import os
import re import re
import subprocess import subprocess
import subprocess_tee
import sys import sys
import urllib.request import urllib.request
from collections import Counter from collections import Counter
@@ -17,7 +18,7 @@ def run(*args, **kw):
def nix(*args): def nix(*args):
return run("nix", "--extra-experimental-features", "nix-command flakes", "-L", *args, check=True, stdout=subprocess.PIPE).stdout return subprocess_tee.run(("nix", "--extra-experimental-features", "nix-command flakes", "-L", *args), check=True, text=True).stdout
def git(*args, check=True): def git(*args, check=True):
@@ -362,10 +363,63 @@ def lint_report(args):
codes = [reviewdog(f"{args.dir}/{name}", flags) codes = [reviewdog(f"{args.dir}/{name}", flags)
for name, flags in LINTERS for name, flags in LINTERS
if os.path.getsize(f"{args.dir}/{name}") > 0] if os.path.isfile(f"{args.dir}/{name}") and os.path.getsize(f"{args.dir}/{name}") > 0]
sys.exit(1 if any(codes) else 0) sys.exit(1 if any(codes) else 0)
def has_findings(path):
return os.path.isfile(path) and os.path.getsize(path) > 0
def fmt_rdjsonl(path):
lines = []
with open(path) as f:
for raw in f:
rec = json.loads(raw)
loc = rec["location"]
r = loc.get("range", {}).get("start")
pos = f"{loc['path']}:{r['line']}:{r['column']}" if r else loc["path"]
lines.append(f"- `{pos}`: {rec['message']}")
return "\n".join(lines)
def fmt_errfmt(path):
lines = []
with open(path) as f:
for raw in f:
parts = raw.strip().split(">", 1)
if len(parts) == 2:
lines.append(f"- `{parts[0]}:{parts[1].split(':', 3)[-1].strip()}`" if ":" in parts[1] else f"- `{raw.strip()}`")
elif raw.strip():
lines.append(f"- `{raw.strip()}`")
return "\n".join(lines)
def lint_summary(args):
sections = []
d = args.dir
if has_findings(f"{d}/nixfmt.diff"):
with open(f"{d}/nixfmt.diff") as f:
sections.append(f"## nixfmt\n\n```diff\n{f.read().rstrip()}\n```")
if has_findings(f"{d}/statix.errfmt"):
sections.append(f"## statix\n\n{fmt_errfmt(f'{d}/statix.errfmt')}")
if has_findings(f"{d}/deadnix.rdjsonl"):
sections.append(f"## deadnix\n\n{fmt_rdjsonl(f'{d}/deadnix.rdjsonl')}")
if has_findings(f"{d}/cycles.rdjsonl"):
sections.append(f"## systemd ordering cycles\n\n{fmt_rdjsonl(f'{d}/cycles.rdjsonl')}")
if sections:
print("\n\n".join(["# Lint findings"] + sections))
sys.exit(1)
else:
print("No lint findings.")
sys.exit(0)
def post_comment(args): def post_comment(args):
body = args.marker + "\n" + Path(args.body_file).read_text() body = args.marker + "\n" + Path(args.body_file).read_text()
pr = os.environ["PR"] pr = os.environ["PR"]
@@ -438,6 +492,7 @@ def main():
command("vulnix", vulnix, "ref", "body_out") command("vulnix", vulnix, "ref", "body_out")
command("lint", lint, "target", "out") command("lint", lint, "target", "out")
command("lint-report", lint_report, "reporter", "dir") command("lint-report", lint_report, "reporter", "dir")
command("lint-summary", lint_summary, "dir")
command("post-comment", post_comment, "marker", "body_file") command("post-comment", post_comment, "marker", "body_file")
command("upsert-issue", upsert_issue, "label", "title", "body_file") command("upsert-issue", upsert_issue, "label", "title", "body_file")
command("close-issue", close_issue, "label") command("close-issue", close_issue, "label")
+1 -1
View File
@@ -381,6 +381,6 @@ let
}; };
}; };
}; };
hostAddr = c.hostAddr; inherit (c) hostAddr;
in in
c c
+172 -144
View File
@@ -55,151 +55,179 @@ in
net.expose.tcp = [ 3000 ]; net.expose.tcp = [ 3000 ];
}; };
ci-runner = mkVm { ci-runner =
name = "ci-runner"; mkVm {
includedInTests = false; name = "ci-runner";
net.access = [ includedInTests = false;
{ net.access = [
to = "git"; {
tcp = [ 3000 ]; to = "git";
} tcp = [ 3000 ];
{ to = "@internet"; } }
]; { to = "@internet"; }
svc.autoStart = true; ];
resources.cpu = 4; svc.autoStart = true;
resources.mem = "32G"; resources.cpu = 4;
resources.fs = [ resources.mem = "32G";
{ resources.fs = [
proto = "virtiofs"; {
tag = "nix-rw-store"; proto = "virtiofs";
source = "${ciRunnerData}/nix-rw-store"; tag = "nix-rw-store";
mountPoint = "/nix/.rw-store"; source = "${ciRunnerData}/nix-rw-store";
} mountPoint = "/nix/.rw-store";
{ }
proto = "virtiofs"; {
tag = "docker-data"; proto = "virtiofs";
source = "${ciRunnerData}/docker"; tag = "nix-db";
mountPoint = "/var/lib/docker"; source = "${ciRunnerData}/nix-db";
} mountPoint = "/nix/var/nix/db";
{ }
proto = "virtiofs"; {
tag = "runner-state"; proto = "virtiofs";
source = "${ciRunnerData}/runner-state"; tag = "docker-data";
mountPoint = "/var/lib/private/gitea-runner"; source = "${ciRunnerData}/docker";
} mountPoint = "/var/lib/docker";
{ }
proto = "virtiofs"; {
tag = "runner-token"; proto = "virtiofs";
source = ciRunnerSecrets; tag = "runner-state";
mountPoint = "/run/ci-runner-secrets"; source = "${ciRunnerData}/runner-state";
readOnly = true; mountPoint = "/var/lib/private/gitea-runner";
} }
{ {
proto = "virtiofs"; proto = "virtiofs";
tag = "tmp"; tag = "runner-token";
source = "/tmp"; source = ciRunnerSecrets;
mountPoint = "/tmp"; mountPoint = "/run/ci-runner-secrets";
} readOnly = true;
]; }
guestConfig = {
{ proto = "virtiofs";
pkgs, tag = "tmp";
utils, source = "/tmp";
lib, mountPoint = "/tmp";
... }
}: ];
let guestConfig =
runnerInstanceName = "ci-runner"; {
pkgs,
utils,
lib,
...
}:
let
runnerInstanceName = "ci-runner";
ciJobContents = with pkgs; [ ciJobContents = with pkgs; [
bashInteractive bashInteractive
coreutils coreutils
gitMinimal gitMinimal
nixVersions.latest nixVersions.latest
nodejs nodejs
cacert cacert
(writeTextDir "etc/nix/nix.conf" "experimental-features = nix-command flakes\n") (writeTextDir "etc/nix/nix.conf" "experimental-features = nix-command flakes\n")
];
ciJobImage = pkgs.dockerTools.buildLayeredImage {
name = "ci-job-image";
tag = "latest";
contents = ciJobContents;
config = {
Cmd = [ "/bin/sh" ];
Env = [
"PATH=${lib.makeBinPath ciJobContents}"
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"NIX_SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"NIX_REMOTE=daemon"
];
};
};
in
{
boot.kernelModules = [ "kvm-intel" ];
boot.extraModprobeConfig = "options kvm_intel nested=1";
# volume-mounted into CI containers; must be in VM's store so
# image symlinks (/bin/node etc.) resolve through the mount
system.extraDependencies = ciJobContents;
microvm.writableStoreOverlay = "/nix/.rw-store";
nix.settings = {
experimental-features = [
"nix-command"
"flakes"
];
max-jobs = "auto";
substituters = [ "https://microvm.cachix.org" ];
trusted-public-keys = [ "microvm.cachix.org-1:oXnBc6hRE3eX5rSYdRyMYXnfzcCxC7yKPTbZXALsqys=" ];
};
nix.settings = {
min-free = 5 * 1024 * 1024 * 1024;
max-free = 10 * 1024 * 1024 * 1024;
};
# nix.optimise.automatic = true; - doesn't work with microvm.writableStoreOverlay
services.openssh = {
enable = true;
settings = {
PermitRootLogin = "yes";
PermitEmptyPasswords = "yes";
};
};
users.users.root.initialHashedPassword = "";
services.journald.extraConfig = "ForwardToConsole=yes";
virtualisation.containerd.enable = true;
virtualisation.containerd.settings.plugins."io.containerd.snapshotter.v1.overlayfs".mount_options =
[ "userxattr" ];
virtualisation.docker.enable = true;
virtualisation.docker.extraOptions = "--containerd /run/containerd/containerd.sock";
virtualisation.docker.daemon.settings.exec-opts = [ "native.cgroupdriver=cgroupfs" ];
systemd.services.docker.wants = [ "containerd.service" ];
systemd.services.docker.after = [ "containerd.service" ];
systemd.services.load-ci-job-image = {
description = "Load the CI job Docker image";
wantedBy = [ "multi-user.target" ];
after = [ "docker.service" ];
requires = [ "docker.service" ];
before = [ "gitea-runner-${utils.escapeSystemdPath runnerInstanceName}.service" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${lib.getExe' pkgs.docker "docker"} load -i ${ciJobImage}";
};
};
services.gitea-actions-runner.instances.${runnerInstanceName} = {
enable = true;
name = runnerInstanceName;
url = "http://git:3000/";
tokenFile = "/run/ci-runner-secrets/token";
labels = [
"nix:docker://ci-job-image:latest"
];
settings.container = {
options = "--device=/dev/kvm --volume=/nix/store:/nix/store:ro --volume=/nix/var/nix/daemon-socket:/nix/var/nix/daemon-socket";
valid_volumes = [
"/nix/store"
"/nix/var/nix/daemon-socket"
];
};
};
};
}
// {
hostConfig = {
systemd.tmpfiles.rules = [
"d ${ciRunnerData}/nix-rw-store 0755 server server -"
"d ${ciRunnerData}/nix-db 0755 server server -"
"d ${ciRunnerData}/docker 0755 server server -"
"d ${ciRunnerData}/runner-state 0755 server server -"
]; ];
ciJobImage = pkgs.dockerTools.buildLayeredImage {
name = "ci-job-image";
tag = "latest";
contents = ciJobContents;
config = {
Cmd = [ "/bin/sh" ];
Env = [
"PATH=${lib.makeBinPath ciJobContents}"
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"NIX_SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
"NIX_REMOTE=daemon"
];
};
};
in
{
boot.kernelModules = [ "kvm-intel" ];
boot.extraModprobeConfig = "options kvm_intel nested=1";
# volume-mounted into CI containers; must be in VM's store so
# image symlinks (/bin/node etc.) resolve through the mount
system.extraDependencies = ciJobContents;
microvm.writableStoreOverlay = "/nix/.rw-store";
nix.settings = {
experimental-features = [
"nix-command"
"flakes"
];
max-jobs = "auto";
};
nix.gc = {
automatic = true;
dates = "daily";
options = "--delete-older-than 14d";
};
# nix.optimise.automatic = true; - doesn't work with microvm.writableStoreOverlay
services.journald.extraConfig = "ForwardToConsole=yes";
virtualisation.containerd.enable = true;
virtualisation.containerd.settings.plugins."io.containerd.snapshotter.v1.overlayfs".mount_options = [ "userxattr" ];
virtualisation.docker.enable = true;
virtualisation.docker.extraOptions = "--containerd /run/containerd/containerd.sock";
systemd.services.docker.wants = [ "containerd.service" ];
systemd.services.docker.after = [ "containerd.service" ];
systemd.services.load-ci-job-image = {
description = "Load the CI job Docker image";
wantedBy = [ "multi-user.target" ];
after = [ "docker.service" ];
requires = [ "docker.service" ];
before = [ "gitea-runner-${utils.escapeSystemdPath runnerInstanceName}.service" ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
ExecStart = "${lib.getExe' pkgs.docker "docker"} load -i ${ciJobImage}";
};
};
services.gitea-actions-runner.instances.${runnerInstanceName} = {
enable = true;
name = runnerInstanceName;
url = "http://git:3000/";
tokenFile = "/run/ci-runner-secrets/token";
labels = [
"nix:docker://ci-job-image:latest"
];
settings.container = {
options = "--device=/dev/kvm --volume=/nix/store:/nix/store:ro --volume=/nix/var/nix/daemon-socket:/nix/var/nix/daemon-socket";
valid_volumes = [
"/nix/store"
"/nix/var/nix/daemon-socket"
];
};
};
}; };
}; };
} }
+1 -1
View File
@@ -210,6 +210,6 @@ let
}; };
inherit (setup) containerConfig; inherit (setup) containerConfig;
}; };
hostAddr = c.hostAddr; inherit (c) hostAddr;
in in
c c
+1 -31
View File
@@ -61,27 +61,16 @@ let
net ? { }, net ? { },
resources ? { }, resources ? { },
traits ? [ ], traits ? [ ],
isolation ? { },
}: }:
mkContainer { mkContainer {
inherit name; inherit name;
inherit net resources; inherit net resources;
svc.autoStart = true; svc.autoStart = true;
isolation = { nixDaemon = nixDaemon; } // isolation; isolation.nixDaemon = nixDaemon;
traits = [ sshTrait ] ++ traits; traits = [ sshTrait ] ++ traits;
packages = with pkgs; [ tmux ] ++ packages; packages = with pkgs; [ tmux ] ++ packages;
miscProperties = self._sshpiperRegister routingInfo; miscProperties = self._sshpiperRegister routingInfo;
}; };
kvmTrait = {
containerConfig =
{ pkgs, ... }:
{
users.users.runner.extraGroups = [ "wheel" ];
security.sudo.wheelNeedsPassword = false;
environment.systemPackages = [ pkgs.qemu_kvm ];
};
};
in in
{ {
ssh-admin = mkSsh { ssh-admin = mkSsh {
@@ -132,25 +121,6 @@ in
mem = "16G"; mem = "16G";
cpu = 65; cpu = 65;
}; };
traits = [ kvmTrait ];
isolation.allowedDevices = [
{
node = "/dev/kvm";
modifier = "rw";
}
{
node = "/dev/vhost-net";
modifier = "rw";
}
{
node = "/dev/net/tun";
modifier = "rwm";
}
];
isolation.additionalCapabilities = [
"CAP_NET_ADMIN"
"CAP_MKNOD"
];
routingInfo = [ routingInfo = [
{ {
username = "autumn"; username = "autumn";
+5 -20
View File
@@ -228,17 +228,6 @@ rec {
: systemd-nspawn user namespacing; see `--private-users=` in : systemd-nspawn user namespacing; see `--private-users=` in
systemd-nspawn(1). Bind mounts always go through idmapped `--bind`. systemd-nspawn(1). Bind mounts always go through idmapped `--bind`.
`isolation.allowedDevices`
: List of `{ node; modifier; }` host devices to grant the container's
cgroup access to; see `containers.<name>.allowedDevices` in the NixOS
manual. nspawn bind-mounts a handful of devices (`/dev/kvm`,
`/dev/net/tun`, ...) into the container itself once the cgroup allows it -
this doesn't need a matching `resources.fs` bind mount.
`isolation.additionalCapabilities`
: Extra Linux capabilities granted to the container; see
`containers.<name>.additionalCapabilities` in the NixOS manual.
`miscProperties` `miscProperties`
: Arbitrary data attached to the result. Used for cross-container discovery : Arbitrary data attached to the result. Used for cross-container discovery
via `collectContainers`. via `collectContainers`.
@@ -283,8 +272,6 @@ rec {
bindMounts = resources.fs or { }; bindMounts = resources.fs or { };
allowsNixDaemon = isolation.nixDaemon or false; allowsNixDaemon = isolation.nixDaemon or false;
privateUsers = isolation.privateUsers or "pick"; privateUsers = isolation.privateUsers or "pick";
allowedDevices = isolation.allowedDevices or [ ];
additionalCapabilities = isolation.additionalCapabilities or [ ];
allowInternet = hasInternetAccess access; allowInternet = hasInternetAccess access;
allBindMounts = builtins.foldl' (acc: t: acc // (t.resources.fs or { })) { } traits // bindMounts; allBindMounts = builtins.foldl' (acc: t: acc // (t.resources.fs or { })) { } traits // bindMounts;
@@ -381,12 +368,7 @@ rec {
kind = "nspawn"; kind = "nspawn";
miscProperties = flattenMiscProp self miscProperties; miscProperties = flattenMiscProp self miscProperties;
nixosContainer = { nixosContainer = {
inherit inherit autoStart privateUsers;
autoStart
privateUsers
allowedDevices
additionalCapabilities
;
bindMounts = { }; bindMounts = { };
extraFlags = bindMountExtraFlags; extraFlags = bindMountExtraFlags;
privateNetwork = true; privateNetwork = true;
@@ -572,7 +554,10 @@ rec {
Gateway = hostAddr; Gateway = hostAddr;
}; };
networkConfig.DNS = [ hostAddr ]; networkConfig.DNS = [ hostAddr ];
networkConfig.Domains = [ "~." "containers" ]; networkConfig.Domains = [
"~."
"containers"
];
linkConfig.RequiredForOnline = if allowInternet then "routable" else "degraded"; linkConfig.RequiredForOnline = if allowInternet then "routable" else "degraded";
}; };
networking.enableIPv6 = false; networking.enableIPv6 = false;
+4 -5
View File
@@ -129,11 +129,10 @@
{ {
nixosConfigurations = lib.mapAttrs (_: host: host.hostCfg) allHosts; nixosConfigurations = lib.mapAttrs (_: host: host.hostCfg) allHosts;
inspect = lib.mapAttrs inspect = lib.mapAttrs (
(name: host: name: host:
pkgs.writeText "inspect-${name}.json" pkgs.writeText "inspect-${name}.json" (builtins.toJSON (introspect.hostReport { inherit host; }))
(builtins.toJSON (introspect.hostReport { inherit host; }))) ) allHosts;
allHosts;
packages.${system} = customPkgs // { packages.${system} = customPkgs // {
inherit ci; inherit ci;
+1 -6
View File
@@ -205,12 +205,7 @@ with subtest("(isolation): edges are one-way"):
server.fail(ct_connect("git", ADDR["nginx"], 443, timeout=2)) server.fail(ct_connect("git", ADDR["nginx"], 443, timeout=2))
with subtest("(isolation): host access allowlist"): with subtest("(isolation): host access allowlist"):
server.succeed( server.succeed(ct_connect("overseer", HOST_ADDR["overseer"], HOST_EXPORTER_PORT))
net_cmd(
"overseer",
f"{CURL} -sf --max-time 5 http://{HOST_ADDR['overseer']}:{HOST_EXPORTER_PORT}/metrics >&2",
)
)
for port in (HOST_EXPORTER_PORT, HOST_CADVISOR_PORT): for port in (HOST_EXPORTER_PORT, HOST_CADVISOR_PORT):
server.fail(ct_connect("git", HOST_ADDR["git"], port, timeout=2)) server.fail(ct_connect("git", HOST_ADDR["git"], port, timeout=2))
server.fail(ct_connect("git", HOST_ADDR["overseer"], port, timeout=2)) server.fail(ct_connect("git", HOST_ADDR["overseer"], port, timeout=2))