Compare commits
22
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64486e43f7 | ||
|
|
55208b17c4 | ||
|
|
9db09ba9d6 | ||
|
|
3e5e4cfc1d | ||
|
|
8c20c5850d | ||
|
|
df615ba3c1 | ||
|
|
b8d64efc11 | ||
|
|
7f3068f51c | ||
|
|
fded1cd233 | ||
|
|
b62ecdd957 | ||
|
|
0d08a1a521 | ||
|
|
ea4fa7c55c | ||
|
|
7df803484d | ||
|
|
83a84fd0f4 | ||
|
|
15cae9a40d | ||
|
|
780bdb7c13 | ||
|
|
6e4c303ade | ||
|
|
ed244dd9f3 | ||
|
|
8d61167757 | ||
|
|
73187bcc9b | ||
|
|
d3b1db7836 | ||
|
|
33ccab9ad4 |
@@ -17,18 +17,10 @@ jobs:
|
|||||||
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
|
||||||
|
|
||||||
- name: merge base branch
|
|
||||||
run: |
|
|
||||||
git config user.email "ci@localhost"
|
|
||||||
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" "origin/${{ github.event.pull_request.base.ref }}"
|
run: git worktree add "$RUNNER_TEMP/base" "${{ github.event.pull_request.base.sha }}"
|
||||||
|
|
||||||
- name: build closures and render diff
|
- name: build closures and render diff
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
@@ -5,19 +5,21 @@ on:
|
|||||||
- cron: "17 4 * * *"
|
- cron: "17 4 * * *"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
pull-requests: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update:
|
update:
|
||||||
runs-on: nix
|
runs-on: nix
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
|
||||||
persist-credentials: false
|
|
||||||
|
|
||||||
- run: nix flake update -L
|
- run: nix flake update -L
|
||||||
|
|
||||||
- name: open/update PR
|
- name: open/update PR
|
||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.BOT_TOKEN }}
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
API: ${{ github.api_url }}
|
API: ${{ github.api_url }}
|
||||||
REPO: ${{ github.repository }}
|
REPO: ${{ github.repository }}
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
+10
-10
@@ -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_GITEA_API_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
GITEA_ADDRESS: ${{ github.server_url }}
|
run: nix run -L .#ci -- lint-report "$REPORTER" "$RUNNER_TEMP/findings"
|
||||||
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
|
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ on:
|
|||||||
- cron: "0 6 * * 1"
|
- cron: "0 6 * * 1"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
issues: write
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
scan:
|
scan:
|
||||||
runs-on: nix
|
runs-on: nix
|
||||||
@@ -21,7 +25,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 -L .#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'
|
||||||
|
|||||||
@@ -1,17 +1,9 @@
|
|||||||
{ 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"
|
||||||
":"
|
":"
|
||||||
|
|||||||
@@ -6,9 +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.error
|
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -19,18 +17,13 @@ def run(*args, **kw):
|
|||||||
|
|
||||||
|
|
||||||
def nix(*args):
|
def nix(*args):
|
||||||
# tee to stderr - stdout leaks into GITHUB_OUTPUT $() captures
|
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=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
|
||||||
@@ -38,20 +31,13 @@ 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")
|
||||||
try:
|
with urllib.request.urlopen(req) as resp:
|
||||||
with urllib.request.urlopen(req) as resp:
|
raw = resp.read()
|
||||||
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&type=issues&labels={label}")
|
issues = gitea("GET", f"/issues?state=open&labels={label}")
|
||||||
return issues[0] if issues else None
|
return issues[0] if issues else None
|
||||||
|
|
||||||
|
|
||||||
@@ -248,7 +234,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, "").replace("\n", " ").replace("|", "∣")
|
desc = v.get("description", {}).get(cve, "")
|
||||||
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))
|
||||||
@@ -376,63 +362,10 @@ 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.isfile(f"{args.dir}/{name}") and os.path.getsize(f"{args.dir}/{name}") > 0]
|
if 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"]
|
||||||
@@ -475,24 +408,16 @@ 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()
|
||||||
push = git("-c", f"http.extraHeader=Authorization: Basic {auth}",
|
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}")
|
|
||||||
|
|
||||||
pulls = gitea("GET", f"/pulls?state=open&base_branch={args.base}")
|
owner = os.environ["REPO"].split("/")[0]
|
||||||
existing = next((pr for pr in pulls if pr["head"]["ref"] == args.branch), None)
|
if gitea("GET", f"/pulls?state=open&head={owner}:{args.branch}"):
|
||||||
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 []
|
||||||
pr = gitea("POST", "/pulls",
|
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():
|
||||||
@@ -513,7 +438,6 @@ 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")
|
||||||
|
|||||||
@@ -381,6 +381,6 @@ let
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
inherit (c) hostAddr;
|
hostAddr = c.hostAddr;
|
||||||
in
|
in
|
||||||
c
|
c
|
||||||
|
|||||||
+137
-165
@@ -55,179 +55,151 @@ in
|
|||||||
net.expose.tcp = [ 3000 ];
|
net.expose.tcp = [ 3000 ];
|
||||||
};
|
};
|
||||||
|
|
||||||
ci-runner =
|
ci-runner = mkVm {
|
||||||
mkVm {
|
name = "ci-runner";
|
||||||
name = "ci-runner";
|
includedInTests = false;
|
||||||
includedInTests = false;
|
net.access = [
|
||||||
net.access = [
|
{
|
||||||
{
|
to = "git";
|
||||||
to = "git";
|
tcp = [ 3000 ];
|
||||||
tcp = [ 3000 ];
|
}
|
||||||
}
|
{ to = "@internet"; }
|
||||||
{ to = "@internet"; }
|
];
|
||||||
];
|
svc.autoStart = true;
|
||||||
svc.autoStart = true;
|
resources.cpu = 4;
|
||||||
resources.cpu = 4;
|
resources.mem = "32G";
|
||||||
resources.mem = "32G";
|
resources.fs = [
|
||||||
resources.fs = [
|
{
|
||||||
{
|
proto = "virtiofs";
|
||||||
proto = "virtiofs";
|
tag = "nix-rw-store";
|
||||||
tag = "nix-rw-store";
|
source = "${ciRunnerData}/nix-rw-store";
|
||||||
source = "${ciRunnerData}/nix-rw-store";
|
mountPoint = "/nix/.rw-store";
|
||||||
mountPoint = "/nix/.rw-store";
|
}
|
||||||
}
|
{
|
||||||
{
|
proto = "virtiofs";
|
||||||
proto = "virtiofs";
|
tag = "docker-data";
|
||||||
tag = "nix-db";
|
source = "${ciRunnerData}/docker";
|
||||||
source = "${ciRunnerData}/nix-db";
|
mountPoint = "/var/lib/docker";
|
||||||
mountPoint = "/nix/var/nix/db";
|
}
|
||||||
}
|
{
|
||||||
{
|
proto = "virtiofs";
|
||||||
proto = "virtiofs";
|
tag = "runner-state";
|
||||||
tag = "docker-data";
|
source = "${ciRunnerData}/runner-state";
|
||||||
source = "${ciRunnerData}/docker";
|
mountPoint = "/var/lib/private/gitea-runner";
|
||||||
mountPoint = "/var/lib/docker";
|
}
|
||||||
}
|
{
|
||||||
{
|
proto = "virtiofs";
|
||||||
proto = "virtiofs";
|
tag = "runner-token";
|
||||||
tag = "runner-state";
|
source = ciRunnerSecrets;
|
||||||
source = "${ciRunnerData}/runner-state";
|
mountPoint = "/run/ci-runner-secrets";
|
||||||
mountPoint = "/var/lib/private/gitea-runner";
|
readOnly = true;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
proto = "virtiofs";
|
proto = "virtiofs";
|
||||||
tag = "runner-token";
|
tag = "tmp";
|
||||||
source = ciRunnerSecrets;
|
source = "/tmp";
|
||||||
mountPoint = "/run/ci-runner-secrets";
|
mountPoint = "/tmp";
|
||||||
readOnly = true;
|
}
|
||||||
}
|
];
|
||||||
{
|
guestConfig =
|
||||||
proto = "virtiofs";
|
{
|
||||||
tag = "tmp";
|
pkgs,
|
||||||
source = "/tmp";
|
utils,
|
||||||
mountPoint = "/tmp";
|
lib,
|
||||||
}
|
...
|
||||||
];
|
}:
|
||||||
guestConfig =
|
let
|
||||||
{
|
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 {
|
ciJobImage = pkgs.dockerTools.buildLayeredImage {
|
||||||
name = "ci-job-image";
|
name = "ci-job-image";
|
||||||
tag = "latest";
|
tag = "latest";
|
||||||
contents = ciJobContents;
|
contents = ciJobContents;
|
||||||
config = {
|
config = {
|
||||||
Cmd = [ "/bin/sh" ];
|
Cmd = [ "/bin/sh" ];
|
||||||
Env = [
|
Env = [
|
||||||
"PATH=${lib.makeBinPath ciJobContents}"
|
"PATH=${lib.makeBinPath ciJobContents}"
|
||||||
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
|
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
|
||||||
"NIX_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"
|
"NIX_REMOTE=daemon"
|
||||||
];
|
];
|
||||||
};
|
|
||||||
};
|
};
|
||||||
in
|
};
|
||||||
{
|
in
|
||||||
boot.kernelModules = [ "kvm-intel" ];
|
{
|
||||||
boot.extraModprobeConfig = "options kvm_intel nested=1";
|
boot.kernelModules = [ "kvm-intel" ];
|
||||||
|
boot.extraModprobeConfig = "options kvm_intel nested=1";
|
||||||
|
|
||||||
# volume-mounted into CI containers; must be in VM's store so
|
# volume-mounted into CI containers; must be in VM's store so
|
||||||
# image symlinks (/bin/node etc.) resolve through the mount
|
# image symlinks (/bin/node etc.) resolve through the mount
|
||||||
system.extraDependencies = ciJobContents;
|
system.extraDependencies = ciJobContents;
|
||||||
|
|
||||||
microvm.writableStoreOverlay = "/nix/.rw-store";
|
microvm.writableStoreOverlay = "/nix/.rw-store";
|
||||||
|
|
||||||
nix.settings = {
|
nix.settings = {
|
||||||
experimental-features = [
|
experimental-features = [
|
||||||
"nix-command"
|
"nix-command"
|
||||||
"flakes"
|
"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"
|
||||||
];
|
];
|
||||||
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 -"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,6 +210,6 @@ let
|
|||||||
};
|
};
|
||||||
inherit (setup) containerConfig;
|
inherit (setup) containerConfig;
|
||||||
};
|
};
|
||||||
inherit (c) hostAddr;
|
hostAddr = c.hostAddr;
|
||||||
in
|
in
|
||||||
c
|
c
|
||||||
|
|||||||
@@ -67,10 +67,7 @@ let
|
|||||||
inherit name;
|
inherit name;
|
||||||
inherit net resources;
|
inherit net resources;
|
||||||
svc.autoStart = true;
|
svc.autoStart = true;
|
||||||
isolation = {
|
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;
|
||||||
@@ -80,7 +77,8 @@ let
|
|||||||
containerConfig =
|
containerConfig =
|
||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
{
|
{
|
||||||
users.users.runner.extraGroups = [ "kvm" ];
|
users.users.runner.extraGroups = [ "wheel" ];
|
||||||
|
security.sudo.wheelNeedsPassword = false;
|
||||||
environment.systemPackages = [ pkgs.qemu_kvm ];
|
environment.systemPackages = [ pkgs.qemu_kvm ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -572,10 +572,7 @@ rec {
|
|||||||
Gateway = hostAddr;
|
Gateway = hostAddr;
|
||||||
};
|
};
|
||||||
networkConfig.DNS = [ hostAddr ];
|
networkConfig.DNS = [ hostAddr ];
|
||||||
networkConfig.Domains = [
|
networkConfig.Domains = [ "~." "containers" ];
|
||||||
"~."
|
|
||||||
"containers"
|
|
||||||
];
|
|
||||||
linkConfig.RequiredForOnline = if allowInternet then "routable" else "degraded";
|
linkConfig.RequiredForOnline = if allowInternet then "routable" else "degraded";
|
||||||
};
|
};
|
||||||
networking.enableIPv6 = false;
|
networking.enableIPv6 = false;
|
||||||
|
|||||||
@@ -129,10 +129,11 @@
|
|||||||
{
|
{
|
||||||
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" (builtins.toJSON (introspect.hostReport { inherit host; }))
|
pkgs.writeText "inspect-${name}.json"
|
||||||
) allHosts;
|
(builtins.toJSON (introspect.hostReport { inherit host; })))
|
||||||
|
allHosts;
|
||||||
|
|
||||||
packages.${system} = customPkgs // {
|
packages.${system} = customPkgs // {
|
||||||
inherit ci;
|
inherit ci;
|
||||||
|
|||||||
@@ -205,7 +205,12 @@ 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(ct_connect("overseer", HOST_ADDR["overseer"], HOST_EXPORTER_PORT))
|
server.succeed(
|
||||||
|
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))
|
||||||
|
|||||||
Reference in New Issue
Block a user