16 Commits
Author SHA1 Message Date
gitea-actions[bot] 974ec51042 flake.lock: update inputs
diff-pr / dix (pull_request) Failing after 6m16s
flake-check / flake-check (pull_request) Failing after 29s
lint / lint (pull_request) Failing after 1m1s
2026-09-17 00:53:22 +00:00
Floweynt d18e1b6c15 try fix again
diff-pr / dix (pull_request) Successful in 6m39s
flake-check / flake-check (pull_request) Successful in 53s
lint / lint (pull_request) Successful in 1m49s
2026-09-16 19:41:55 -05:00
Floweynt 86d78a4760 temp 2026-09-13 13:48:50 -05:00
Floweynt e692589fe9 meow
diff-pr / dix (pull_request) Successful in 6m20s
flake-check / flake-check (pull_request) Successful in 51s
lint / lint (pull_request) Successful in 1m47s
2026-09-13 13:16:31 -05:00
Floweynt 581f531bf4 meow
diff-pr / dix (pull_request) Successful in 6m23s
flake-check / flake-check (pull_request) Successful in 50s
lint / lint (pull_request) Successful in 1m47s
2026-09-13 12:57:16 -05:00
Floweynt bc6d66432a fix again
diff-pr / dix (pull_request) Successful in 6m24s
flake-check / flake-check (pull_request) Successful in 52s
lint / lint (pull_request) Successful in 1m48s
2026-09-13 12:32:55 -05:00
Floweynt 6ba18264ac fix again
flake-check / flake-check (pull_request) Successful in 51s
lint / lint (pull_request) Successful in 1m47s
diff-pr / dix (pull_request) Successful in 6m25s
2026-09-13 11:55:32 -05:00
Floweynt d81d948bae fix unrelated workflow
diff-pr / dix (pull_request) Successful in 6m20s
lint / lint (pull_request) Canceled after 0s
flake-check / flake-check (pull_request) Canceled after 54s
2026-09-13 11:48:20 -05:00
Floweynt b8e5b1c4c4 fix flake update
flake-check / flake-check (pull_request) Successful in 52s
lint / lint (pull_request) Successful in 1m48s
diff-pr / dix (pull_request) Successful in 6m16s
2026-09-12 01:40:54 -05:00
floweyandFloweynt af5d7493af ci: fix vulnix GITHUB_OUTPUT format error (#4)
diff-tag / dix (push) Successful in 6m4s
flake-check / flake-check (push) Successful in 52s
lint / lint (push) Successful in 1m48s
Co-authored-by: Floweynt <floweydev@gmail.com>
Reviewed-on: #4
2026-09-12 01:36:03 +00:00
1447febbaf frcc experiments (#1)
flake-check / flake-check (push) Successful in 57s
lint / lint (push) Successful in 2m13s
diff-tag / dix (push) Successful in 6m13s
Co-authored-by: Autumn Liu <al63244@my.utexas.edu>
Co-authored-by: Floweynt <50057682+Floweynt@users.noreply.github.com>
Reviewed-on: #1
Co-authored-by: autumn <aut.tea7@gmail.com>
2026-09-11 07:31:32 +00:00
Floweynt 6b21be0088 ci: try to fix vulnix v2
diff-tag / dix (push) Successful in 6m9s
flake-check / flake-check (push) Successful in 51s
lint / lint (push) Successful in 1m49s
2026-09-10 23:09:49 -05:00
floweyandFloweynt 0279df6b11 cI: improve cache management (#2)
diff-tag / dix (push) Successful in 6m10s
flake-check / flake-check (push) Successful in 51s
lint / lint (push) Successful in 1m49s
Co-authored-by: Floweynt <50057682+Floweynt@users.noreply.github.com>
Reviewed-on: #2
2026-09-11 02:06:39 +00:00
Floweynt 3a87891486 ci: try to fix vulnix
flake-check / flake-check (push) Canceled after 0s
lint / lint (push) Canceled after 0s
diff-tag / dix (push) Successful in 6m7s
2026-09-10 20:18:03 -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
17 changed files with 374 additions and 214 deletions
+12 -9
View File
@@ -13,26 +13,29 @@ concurrency:
jobs: jobs:
dix: dix:
runs-on: ubuntu-latest runs-on: nix
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0 fetch-depth: 0
- uses: cachix/install-nix-action@v31 - name: merge base branch
with: run: |
extra_nix_config: | git config user.email "ci@localhost"
experimental-features = nix-command flakes git config user.name "CI"
git fetch origin ${{ github.event.pull_request.base.ref }}
git merge --no-edit origin/${{ github.event.pull_request.base.ref }}
- name: worktree base for diff - name: worktree base for diff
run: git worktree add "$RUNNER_TEMP/base" "${{ github.event.pull_request.base.sha }}" run: git worktree add "$RUNNER_TEMP/base" "origin/${{ github.event.pull_request.base.ref }}"
- name: build closures and render diff - name: build closures and render diff
run: | run: |
nix run .#ci -- diff "$RUNNER_TEMP/base" . \ nix run -L .#ci -- diff "$RUNNER_TEMP/base" . \
"### System closure diff vs \`${{ github.event.pull_request.base.ref }}\`" \ "### System closure diff vs \`${{ github.event.pull_request.base.ref }}\`" \
> "$RUNNER_TEMP/comment.md" > "$RUNNER_TEMP/comment.md"
nix run .#ci -- inspect-diff "$RUNNER_TEMP/base" . \ nix run -L .#ci -- inspect-diff "$RUNNER_TEMP/base" . \
"### Inspection diff vs \`${{ github.event.pull_request.base.ref }}\`" \ "### Inspection diff vs \`${{ github.event.pull_request.base.ref }}\`" \
>> "$RUNNER_TEMP/comment.md" >> "$RUNNER_TEMP/comment.md"
@@ -42,4 +45,4 @@ jobs:
API: ${{ github.api_url }} API: ${{ github.api_url }}
REPO: ${{ github.repository }} REPO: ${{ github.repository }}
PR: ${{ github.event.pull_request.number }} PR: ${{ github.event.pull_request.number }}
run: nix run .#ci -- post-comment "<!-- dix-diff -->" "$RUNNER_TEMP/comment.md" run: nix run -L .#ci -- post-comment "<!-- dix-diff -->" "$RUNNER_TEMP/comment.md"
+3 -8
View File
@@ -9,17 +9,12 @@ permissions:
jobs: jobs:
dix: dix:
runs-on: ubuntu-latest runs-on: nix
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
fetch-depth: 0 fetch-depth: 0
- uses: cachix/install-nix-action@v31
with:
extra_nix_config: |
experimental-features = nix-command flakes
- name: diff latest tag against HEAD - name: diff latest tag against HEAD
run: | run: |
tag=$(git tag --sort=-creatordate | head -n1) tag=$(git tag --sort=-creatordate | head -n1)
@@ -30,8 +25,8 @@ jobs:
git worktree add "$RUNNER_TEMP/old" "$tag" git worktree add "$RUNNER_TEMP/old" "$tag"
head=$(git rev-parse --short HEAD) head=$(git rev-parse --short HEAD)
{ {
nix run .#ci -- diff "$RUNNER_TEMP/old" . \ nix run -L .#ci -- diff "$RUNNER_TEMP/old" . \
"# System closure diff: \`$tag\` -> \`$head\`" "# System closure diff: \`$tag\` -> \`$head\`"
nix run .#ci -- inspect-diff "$RUNNER_TEMP/old" . \ nix run -L .#ci -- inspect-diff "$RUNNER_TEMP/old" . \
"# Inspection diff: \`$tag\` -> \`$head\`" "# Inspection diff: \`$tag\` -> \`$head\`"
} | tee -a "$GITHUB_STEP_SUMMARY" } | tee -a "$GITHUB_STEP_SUMMARY"
+1 -6
View File
@@ -14,13 +14,8 @@ concurrency:
jobs: jobs:
flake-check: flake-check:
runs-on: ubuntu-latest runs-on: nix
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: cachix/install-nix-action@v31
with:
extra_nix_config: |
experimental-features = nix-command flakes
- run: nix flake check -L - run: nix flake check -L
+5 -12
View File
@@ -5,29 +5,22 @@ on:
- cron: "17 4 * * *" - cron: "17 4 * * *"
workflow_dispatch: workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs: jobs:
update: update:
runs-on: ubuntu-latest runs-on: nix
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: cachix/install-nix-action@v31
with: with:
extra_nix_config: | persist-credentials: false
experimental-features = nix-command flakes
- run: nix flake update - run: nix flake update -L
- name: open/update PR - name: open/update PR
env: env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.BOT_TOKEN }}
API: ${{ github.api_url }} API: ${{ github.api_url }}
REPO: ${{ github.repository }} REPO: ${{ github.repository }}
run: | run: |
printf 'Automated `nix flake update`.\n' > "$RUNNER_TEMP/body.md" printf 'Automated `nix flake update`.\n' > "$RUNNER_TEMP/body.md"
nix run .#ci -- open-pr \ nix run -L .#ci -- open-pr \
flake-update "$GITHUB_REF_NAME" "flake.lock: update inputs" "$RUNNER_TEMP/body.md" automated flake-update "$GITHUB_REF_NAME" "flake.lock: update inputs" "$RUNNER_TEMP/body.md" automated
+12 -17
View File
@@ -15,27 +15,22 @@ concurrency:
jobs: jobs:
lint: lint:
runs-on: ubuntu-latest runs-on: nix
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: cachix/install-nix-action@v31
with:
extra_nix_config: |
experimental-features = nix-command flakes
- name: pick reporter
run: |
if [ "${{ github.event_name }}" = pull_request ]; then
echo "REPORTER=github-pr-review" >> "$GITHUB_ENV"
else
echo "REPORTER=local" >> "$GITHUB_ENV"
fi
- name: run linters - name: run linters
run: nix run .#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 .#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
+4 -13
View File
@@ -5,24 +5,15 @@ on:
- cron: "0 6 * * 1" - cron: "0 6 * * 1"
workflow_dispatch: workflow_dispatch:
permissions:
contents: read
issues: write
jobs: jobs:
scan: scan:
runs-on: ubuntu-latest runs-on: nix
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: cachix/install-nix-action@v31
with:
extra_nix_config: |
experimental-features = nix-command flakes
- name: scan host closures - name: scan host closures
id: scan id: scan
run: echo "count=$(nix run .#ci -- vulnix . "$RUNNER_TEMP/issue.md")" >> "$GITHUB_OUTPUT" run: echo "count=$(nix run -L .#ci -- vulnix . "$RUNNER_TEMP/issue.md")" >> "$GITHUB_OUTPUT"
- name: file/update issue - name: file/update issue
if: steps.scan.outputs.count != '0' if: steps.scan.outputs.count != '0'
@@ -30,7 +21,7 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
API: ${{ github.api_url }} API: ${{ github.api_url }}
REPO: ${{ github.repository }} REPO: ${{ github.repository }}
run: nix run .#ci -- upsert-issue vulnix "vulnix: known vulnerabilities in system closure" "$RUNNER_TEMP/issue.md" run: 'nix run -L .#ci -- upsert-issue vulnix "vulnix: known vulnerabilities in system closure" "$RUNNER_TEMP/issue.md"'
- name: close resolved issue - name: close resolved issue
if: steps.scan.outputs.count == '0' if: steps.scan.outputs.count == '0'
@@ -38,4 +29,4 @@ jobs:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
API: ${{ github.api_url }} API: ${{ github.api_url }}
REPO: ${{ github.repository }} REPO: ${{ github.repository }}
run: nix run .#ci -- close-issue vulnix run: nix run -L .#ci -- close-issue vulnix
+8
View File
@@ -1,9 +1,17 @@
{ lib, pkgs }: { lib, pkgs }:
let
# vulnix's bundled nix-2.34 broke its own --experimental-features detection
nixConf = pkgs.writeText "ci-nix.conf" "experimental-features = nix-command flakes";
in
# tools must track ci.py's subprocess calls; nix stays ambient (uses the # tools must track ci.py's subprocess calls; nix stays ambient (uses the
# 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 = [
"--set-default"
"NIX_USER_CONF_FILES"
(toString nixConf)
"--prefix" "--prefix"
"PATH" "PATH"
":" ":"
+89 -13
View File
@@ -6,7 +6,9 @@ import json
import os import os
import re import re
import subprocess import subprocess
import subprocess_tee
import sys import sys
import urllib.error
import urllib.request import urllib.request
from collections import Counter from collections import Counter
from pathlib import Path from pathlib import Path
@@ -17,13 +19,18 @@ def run(*args, **kw):
def nix(*args): def nix(*args):
return run("nix", "--extra-experimental-features", "nix-command flakes", *args, check=True, capture_output=True).stdout # tee to stderr - stdout leaks into GITHUB_OUTPUT $() captures
return subprocess_tee.run(("nix", "--extra-experimental-features", "nix-command flakes", "-L", *args), check=True, text=True, stdout=sys.stderr).stdout
def git(*args, check=True): def git(*args, check=True):
return run("git", *args, check=check, capture_output=True) return run("git", *args, check=check, capture_output=True)
class GiteaError(Exception):
pass
def gitea(method, path, body=None): def gitea(method, path, body=None):
url = f'{os.environ["API"]}/repos/{os.environ["REPO"]}{path}' url = f'{os.environ["API"]}/repos/{os.environ["REPO"]}{path}'
data = json.dumps(body).encode() if body is not None else None data = json.dumps(body).encode() if body is not None else None
@@ -31,13 +38,20 @@ def gitea(method, path, body=None):
req.add_header("Authorization", f'token {os.environ["GH_TOKEN"]}') req.add_header("Authorization", f'token {os.environ["GH_TOKEN"]}')
if data is not None: if data is not None:
req.add_header("Content-Type", "application/json") req.add_header("Content-Type", "application/json")
with urllib.request.urlopen(req) as resp: try:
raw = resp.read() with urllib.request.urlopen(req) as resp:
raw = resp.read()
except urllib.error.HTTPError as e:
try:
detail = json.loads(e.read()).get("message", e.reason)
except (json.JSONDecodeError, UnicodeDecodeError):
detail = e.reason
raise GiteaError(f"{method} {path}: {e.code} {detail}") from None
return json.loads(raw) if raw else None return json.loads(raw) if raw else None
def find_open_issue(label): def find_open_issue(label):
issues = gitea("GET", f"/issues?state=open&labels={label}") issues = gitea("GET", f"/issues?state=open&type=issues&labels={label}")
return issues[0] if issues else None return issues[0] if issues else None
@@ -234,7 +248,7 @@ def format_vulnix(vulns):
for v in vulns: for v in vulns:
for cve in v["affected_by"]: for cve in v["affected_by"]:
score = v.get("cvssv3_basescore", {}).get(cve) score = v.get("cvssv3_basescore", {}).get(cve)
desc = v.get("description", {}).get(cve, "") desc = v.get("description", {}).get(cve, "").replace("\n", " ").replace("|", "∣")
if len(desc) > 120: if len(desc) > 120:
desc = desc[:117] + "..." desc = desc[:117] + "..."
rows.append((v["pname"], v["version"], cve, score, desc)) rows.append((v["pname"], v["version"], cve, score, desc))
@@ -362,10 +376,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"]
@@ -408,16 +475,24 @@ def open_pr(args):
host = os.environ["API"].removesuffix("/api/v1") host = os.environ["API"].removesuffix("/api/v1")
auth = base64.b64encode(f'token:{os.environ["GH_TOKEN"]}'.encode()).decode() auth = base64.b64encode(f'token:{os.environ["GH_TOKEN"]}'.encode()).decode()
git("-c", f"http.extraHeader=Authorization: Basic {auth}", push = git("-c", f"http.extraHeader=Authorization: Basic {auth}",
"push", "-f", f'{host}/{os.environ["REPO"]}.git', f"HEAD:{args.branch}") "push", "-f", f'{host}/{os.environ["REPO"]}.git', f"HEAD:{args.branch}",
check=False)
if push.returncode != 0:
raise RuntimeError(f"git push failed:\n{push.stderr}")
owner = os.environ["REPO"].split("/")[0] pulls = gitea("GET", f"/pulls?state=open&base_branch={args.base}")
if gitea("GET", f"/pulls?state=open&head={owner}:{args.branch}"): existing = next((pr for pr in pulls if pr["head"]["ref"] == args.branch), None)
if existing:
print(f"PR #{existing['number']} already open, pushed update")
return return
labels = [label_id(args.label)] if args.label else [] labels = [label_id(args.label)] if args.label else []
gitea("POST", "/pulls", pr = gitea("POST", "/pulls",
{"title": args.title, "head": args.branch, "base": args.base, {"title": args.title, "head": args.branch, "base": args.base,
"body": Path(args.body_file).read_text(), "labels": labels}) "body": Path(args.body_file).read_text(), "labels": labels})
if not pr or "number" not in pr:
raise GiteaError(f"POST /pulls: unexpected response: {json.dumps(pr)}")
print(f"opened PR #{pr['number']}")
def main(): def main():
@@ -438,6 +513,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
+165 -110
View File
@@ -8,6 +8,9 @@ let
inherit (dsl) mkContainer mkVm; inherit (dsl) mkContainer mkVm;
inherit (hostInfo.paths) data secrets; inherit (hostInfo.paths) data secrets;
pubSshPort = 23;
intSshPort = 23 + 8000;
ciRunnerData = "${data}/web/git-ci-runner"; ciRunnerData = "${data}/web/git-ci-runner";
ciRunnerSecrets = "${secrets}/ci-runner"; ciRunnerSecrets = "${secrets}/ci-runner";
in in
@@ -17,8 +20,8 @@ in
net.access = [ { to = "@internet"; } ]; net.access = [ { to = "@internet"; } ];
net.forward.tcp = [ net.forward.tcp = [
{ {
host = 23; host = pubSshPort;
container = 8023; container = intSshPort;
} }
]; ];
svc.autoStart = true; svc.autoStart = true;
@@ -38,7 +41,8 @@ in
ROOT_URL = "https://git.floweytf.com/"; ROOT_URL = "https://git.floweytf.com/";
START_SSH_SERVER = true; START_SSH_SERVER = true;
BUILTIN_SSH_SERVER_USER = "git"; BUILTIN_SSH_SERVER_USER = "git";
SSH_PORT = 8023; SSH_PORT = pubSshPort;
SSH_LISTEN_PORT = intSshPort;
}; };
service.DISABLE_REGISTRATION = true; service.DISABLE_REGISTRATION = true;
}; };
@@ -51,128 +55,179 @@ in
net.expose.tcp = [ 3000 ]; net.expose.tcp = [ 3000 ];
}; };
ci-runner = mkVm { ci-runner =
name = "ci-runner"; mkVm {
net.access = [ name = "ci-runner";
{ includedInTests = false;
to = "git"; net.access = [
tcp = [ 3000 ]; {
} to = "git";
{ to = "@internet"; } tcp = [ 3000 ];
]; }
svc.autoStart = true; { to = "@internet"; }
resources.cpu = 4; ];
resources.mem = "8G"; svc.autoStart = true;
resources.fs = [ resources.cpu = 4;
{ resources.mem = "32G";
proto = "virtiofs"; resources.fs = [
tag = "nix-rw-store"; {
source = "${ciRunnerData}/nix-rw-store"; proto = "virtiofs";
mountPoint = "/nix/.rw-store"; tag = "nix-rw-store";
} source = "${ciRunnerData}/nix-rw-store";
{ mountPoint = "/nix/.rw-store";
proto = "virtiofs"; }
tag = "docker-data"; {
source = "${ciRunnerData}/docker"; proto = "virtiofs";
mountPoint = "/var/lib/docker"; tag = "nix-db";
} source = "${ciRunnerData}/nix-db";
{ mountPoint = "/nix/var/nix/db";
proto = "virtiofs"; }
tag = "runner-state"; {
source = "${ciRunnerData}/runner-state"; proto = "virtiofs";
mountPoint = "/var/lib/gitea-runner"; tag = "docker-data";
} source = "${ciRunnerData}/docker";
{ mountPoint = "/var/lib/docker";
proto = "virtiofs"; }
tag = "runner-token"; {
source = ciRunnerSecrets; proto = "virtiofs";
mountPoint = "/run/ci-runner-secrets"; tag = "runner-state";
readOnly = true; source = "${ciRunnerData}/runner-state";
} mountPoint = "/var/lib/private/gitea-runner";
]; }
guestConfig = {
{ proto = "virtiofs";
pkgs, tag = "runner-token";
utils, source = ciRunnerSecrets;
lib, mountPoint = "/run/ci-runner-secrets";
... readOnly = true;
}: }
let {
runnerInstanceName = "ci-runner"; proto = "virtiofs";
tag = "tmp";
source = "/tmp";
mountPoint = "/tmp";
}
];
guestConfig =
{
pkgs,
utils,
lib,
...
}:
let
runnerInstanceName = "ci-runner";
ciJobImage = pkgs.dockerTools.buildLayeredImage { ciJobContents = with pkgs; [
name = "ci-job-image";
tag = "latest";
contents = 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")
]; ];
config = {
Cmd = [ "/bin/sh" ]; ciJobImage = pkgs.dockerTools.buildLayeredImage {
Env = [ name = "ci-job-image";
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" tag = "latest";
"NIX_SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" contents = ciJobContents;
"NIX_REMOTE=daemon" 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=" ];
}; };
};
in
{
boot.kernelModules = [ "kvm-intel" ];
boot.extraModprobeConfig = "options kvm_intel nested=1";
microvm.writableStoreOverlay = "/nix/.rw-store"; nix.settings = {
min-free = 5 * 1024 * 1024 * 1024;
nix.settings = { max-free = 10 * 1024 * 1024 * 1024;
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
virtualisation.docker.enable = true;
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}";
}; };
}; # nix.optimise.automatic = true; - doesn't work with microvm.writableStoreOverlay
services.gitea-actions-runner.instances.${runnerInstanceName} = { services.openssh = {
enable = true; enable = true;
name = runnerInstanceName; settings = {
url = "http://git:3000/"; PermitRootLogin = "yes";
tokenFile = "/run/ci-runner-secrets/token"; PermitEmptyPasswords = "yes";
labels = [ };
"nix:docker://ci-job-image:latest" };
]; users.users.root.initialHashedPassword = "";
settings.container = { services.journald.extraConfig = "ForwardToConsole=yes";
options = "--device=/dev/kvm --volume=/nix/store:/nix/store:ro --volume=/nix/var/nix/daemon-socket:/nix/var/nix/daemon-socket";
valid_volumes = [ virtualisation.containerd.enable = true;
"/nix/store" virtualisation.containerd.settings.plugins."io.containerd.snapshotter.v1.overlayfs".mount_options =
"/nix/var/nix/daemon-socket" [ "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 -"
];
}; };
}; };
} }
+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
+33 -1
View File
@@ -61,16 +61,29 @@ 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 = {
inherit nixDaemon;
}
// isolation;
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 = [ "kvm" ];
environment.systemPackages = [ pkgs.qemu_kvm ];
};
};
in in
{ {
ssh-admin = mkSsh { ssh-admin = mkSsh {
@@ -121,6 +134,25 @@ 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";
+24 -1
View File
@@ -228,6 +228,17 @@ 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`.
@@ -272,6 +283,8 @@ 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;
@@ -368,7 +381,12 @@ rec {
kind = "nspawn"; kind = "nspawn";
miscProperties = flattenMiscProp self miscProperties; miscProperties = flattenMiscProp self miscProperties;
nixosContainer = { nixosContainer = {
inherit autoStart privateUsers; inherit
autoStart
privateUsers
allowedDevices
additionalCapabilities
;
bindMounts = { }; bindMounts = { };
extraFlags = bindMountExtraFlags; extraFlags = bindMountExtraFlags;
privateNetwork = true; privateNetwork = true;
@@ -553,6 +571,11 @@ rec {
Destination = "0.0.0.0/0"; Destination = "0.0.0.0/0";
Gateway = hostAddr; Gateway = hostAddr;
}; };
networkConfig.DNS = [ hostAddr ];
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;
Generated
+10 -10
View File
@@ -26,11 +26,11 @@
"spectrum": "spectrum" "spectrum": "spectrum"
}, },
"locked": { "locked": {
"lastModified": 1786300091, "lastModified": 1789506833,
"narHash": "sha256-4UFJOVGpaYtHW5yasSv80MaJxTBYdk2zyf3jhKtt0wA=", "narHash": "sha256-4L8SOCF84de1irB72Ka9VHcu9wrAJ9Amuey4lU9oh4Y=",
"owner": "microvm-nix", "owner": "microvm-nix",
"repo": "microvm.nix", "repo": "microvm.nix",
"rev": "71beea0076cd46dafcee97a5a2e7d00cbba5bd2f", "rev": "187b0a390ee054028106a674e7b01b1cb940cbba",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -63,11 +63,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1786384358, "lastModified": 1789546076,
"narHash": "sha256-RzPPiWeUtuvymnpuEWsdtzli5w4kjZs49FqEs3/1u+I=", "narHash": "sha256-zVxLZiSnmaaPLwnhj7pwmqe3axBg/C6nG5JZsJMh2g4=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "2fcb964de67fcf60b43471c55d5d99e61a9ccb5a", "rev": "b1b875982b17dabde9b4a37f3e229e74913e6db3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -87,11 +87,11 @@
"spectrum": { "spectrum": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1785761586, "lastModified": 1786032750,
"narHash": "sha256-MWOMVqJJERwjQGgRIv8d6rlEBqbLM3VZWxHkNKIIZNw=", "narHash": "sha256-+Ba/kIn5BjvV7PN8bWOo7RoqgTY/Yv2M7qeMf3wS2Ag=",
"ref": "refs/heads/main", "ref": "refs/heads/main",
"rev": "a7762d6f54b40560dd5255ce902e6e6a5d980fe9", "rev": "77d2389874bb092b8dbf05ecc5b1030372e80e98",
"revCount": 1416, "revCount": 1417,
"type": "git", "type": "git",
"url": "https://spectrum-os.org/git/spectrum" "url": "https://spectrum-os.org/git/spectrum"
}, },
+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 -1
View File
@@ -1,7 +1,7 @@
_: { _: {
# New host: copy this file to hosts/<name>.nix. Replace fileSystems/boot # New host: copy this file to hosts/<name>.nix. Replace fileSystems/boot
# below with the real hardware (see hosts/server-n0.nix for a bigger # below with the real hardware (see hosts/server-n0.nix for a bigger
# example). Add a containers/<name>/ directory for its containers. # example). Add a containers/<name>/ directory for its containers.
module = module =
{ lib, hostInfo, ... }: { lib, hostInfo, ... }:
+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))