Compare commits
22
Commits
master
...
64486e43f7
| 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 |
@@ -13,26 +13,21 @@ concurrency:
|
||||
|
||||
jobs:
|
||||
dix:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: nix
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: cachix/install-nix-action@v31
|
||||
with:
|
||||
extra_nix_config: |
|
||||
experimental-features = nix-command flakes
|
||||
|
||||
- name: worktree base for diff
|
||||
run: git worktree add "$RUNNER_TEMP/base" "${{ github.event.pull_request.base.sha }}"
|
||||
|
||||
- name: build closures and render diff
|
||||
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 }}\`" \
|
||||
> "$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 }}\`" \
|
||||
>> "$RUNNER_TEMP/comment.md"
|
||||
|
||||
@@ -42,4 +37,4 @@ jobs:
|
||||
API: ${{ github.api_url }}
|
||||
REPO: ${{ github.repository }}
|
||||
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"
|
||||
|
||||
@@ -9,17 +9,12 @@ permissions:
|
||||
|
||||
jobs:
|
||||
dix:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: nix
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: cachix/install-nix-action@v31
|
||||
with:
|
||||
extra_nix_config: |
|
||||
experimental-features = nix-command flakes
|
||||
|
||||
- name: diff latest tag against HEAD
|
||||
run: |
|
||||
tag=$(git tag --sort=-creatordate | head -n1)
|
||||
@@ -30,8 +25,8 @@ jobs:
|
||||
git worktree add "$RUNNER_TEMP/old" "$tag"
|
||||
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\`"
|
||||
nix run .#ci -- inspect-diff "$RUNNER_TEMP/old" . \
|
||||
nix run -L .#ci -- inspect-diff "$RUNNER_TEMP/old" . \
|
||||
"# Inspection diff: \`$tag\` -> \`$head\`"
|
||||
} | tee -a "$GITHUB_STEP_SUMMARY"
|
||||
|
||||
@@ -14,13 +14,8 @@ concurrency:
|
||||
|
||||
jobs:
|
||||
flake-check:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: nix
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: cachix/install-nix-action@v31
|
||||
with:
|
||||
extra_nix_config: |
|
||||
experimental-features = nix-command flakes
|
||||
|
||||
- run: nix flake check -L
|
||||
|
||||
@@ -11,16 +11,11 @@ permissions:
|
||||
|
||||
jobs:
|
||||
update:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: nix
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: cachix/install-nix-action@v31
|
||||
with:
|
||||
extra_nix_config: |
|
||||
experimental-features = nix-command flakes
|
||||
|
||||
- run: nix flake update
|
||||
- run: nix flake update -L
|
||||
|
||||
- name: open/update PR
|
||||
env:
|
||||
@@ -29,5 +24,5 @@ jobs:
|
||||
REPO: ${{ github.repository }}
|
||||
run: |
|
||||
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
|
||||
|
||||
@@ -15,27 +15,22 @@ concurrency:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: nix
|
||||
steps:
|
||||
- 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"
|
||||
echo "REPORTER=gitea-pr-review" >> "$GITHUB_ENV"
|
||||
else
|
||||
echo "REPORTER=local" >> "$GITHUB_ENV"
|
||||
fi
|
||||
|
||||
- name: run linters
|
||||
run: nix run .#ci -- lint . "$RUNNER_TEMP/findings"
|
||||
run: nix run -L .#ci -- lint . "$RUNNER_TEMP/findings"
|
||||
|
||||
- name: report findings
|
||||
env:
|
||||
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: nix run .#ci -- lint-report "$REPORTER" "$RUNNER_TEMP/findings"
|
||||
run: nix run -L .#ci -- lint-report "$REPORTER" "$RUNNER_TEMP/findings"
|
||||
|
||||
@@ -11,18 +11,13 @@ permissions:
|
||||
|
||||
jobs:
|
||||
scan:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: nix
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: cachix/install-nix-action@v31
|
||||
with:
|
||||
extra_nix_config: |
|
||||
experimental-features = nix-command flakes
|
||||
|
||||
- name: scan host closures
|
||||
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
|
||||
if: steps.scan.outputs.count != '0'
|
||||
@@ -30,7 +25,7 @@ jobs:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
API: ${{ github.api_url }}
|
||||
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
|
||||
if: steps.scan.outputs.count == '0'
|
||||
@@ -38,4 +33,4 @@ jobs:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
API: ${{ github.api_url }}
|
||||
REPO: ${{ github.repository }}
|
||||
run: nix run .#ci -- close-issue vulnix
|
||||
run: nix run -L .#ci -- close-issue vulnix
|
||||
|
||||
@@ -17,7 +17,7 @@ def run(*args, **kw):
|
||||
|
||||
|
||||
def nix(*args):
|
||||
return run("nix", "--extra-experimental-features", "nix-command flakes", *args, check=True, capture_output=True).stdout
|
||||
return run("nix", "--extra-experimental-features", "nix-command flakes", "-L", *args, check=True, stdout=subprocess.PIPE).stdout
|
||||
|
||||
|
||||
def git(*args, check=True):
|
||||
|
||||
@@ -8,6 +8,9 @@ let
|
||||
inherit (dsl) mkContainer mkVm;
|
||||
inherit (hostInfo.paths) data secrets;
|
||||
|
||||
pubSshPort = 23;
|
||||
intSshPort = 23 + 8000;
|
||||
|
||||
ciRunnerData = "${data}/web/git-ci-runner";
|
||||
ciRunnerSecrets = "${secrets}/ci-runner";
|
||||
in
|
||||
@@ -17,8 +20,8 @@ in
|
||||
net.access = [ { to = "@internet"; } ];
|
||||
net.forward.tcp = [
|
||||
{
|
||||
host = 23;
|
||||
container = 8023;
|
||||
host = pubSshPort;
|
||||
container = intSshPort;
|
||||
}
|
||||
];
|
||||
svc.autoStart = true;
|
||||
@@ -38,7 +41,8 @@ in
|
||||
ROOT_URL = "https://git.floweytf.com/";
|
||||
START_SSH_SERVER = true;
|
||||
BUILTIN_SSH_SERVER_USER = "git";
|
||||
SSH_PORT = 8023;
|
||||
SSH_PORT = pubSshPort;
|
||||
SSH_LISTEN_PORT = intSshPort;
|
||||
};
|
||||
service.DISABLE_REGISTRATION = true;
|
||||
};
|
||||
@@ -53,6 +57,7 @@ in
|
||||
|
||||
ci-runner = mkVm {
|
||||
name = "ci-runner";
|
||||
includedInTests = false;
|
||||
net.access = [
|
||||
{
|
||||
to = "git";
|
||||
@@ -62,7 +67,7 @@ in
|
||||
];
|
||||
svc.autoStart = true;
|
||||
resources.cpu = 4;
|
||||
resources.mem = "8G";
|
||||
resources.mem = "32G";
|
||||
resources.fs = [
|
||||
{
|
||||
proto = "virtiofs";
|
||||
@@ -80,7 +85,7 @@ in
|
||||
proto = "virtiofs";
|
||||
tag = "runner-state";
|
||||
source = "${ciRunnerData}/runner-state";
|
||||
mountPoint = "/var/lib/gitea-runner";
|
||||
mountPoint = "/var/lib/private/gitea-runner";
|
||||
}
|
||||
{
|
||||
proto = "virtiofs";
|
||||
@@ -89,6 +94,12 @@ in
|
||||
mountPoint = "/run/ci-runner-secrets";
|
||||
readOnly = true;
|
||||
}
|
||||
{
|
||||
proto = "virtiofs";
|
||||
tag = "tmp";
|
||||
source = "/tmp";
|
||||
mountPoint = "/tmp";
|
||||
}
|
||||
];
|
||||
guestConfig =
|
||||
{
|
||||
@@ -100,20 +111,24 @@ in
|
||||
let
|
||||
runnerInstanceName = "ci-runner";
|
||||
|
||||
ciJobImage = pkgs.dockerTools.buildLayeredImage {
|
||||
name = "ci-job-image";
|
||||
tag = "latest";
|
||||
contents = with pkgs; [
|
||||
ciJobContents = with pkgs; [
|
||||
bashInteractive
|
||||
coreutils
|
||||
gitMinimal
|
||||
nixVersions.latest
|
||||
nodejs
|
||||
cacert
|
||||
(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"
|
||||
@@ -125,6 +140,10 @@ 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 = {
|
||||
@@ -142,7 +161,15 @@ in
|
||||
};
|
||||
# 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";
|
||||
|
||||
@@ -61,16 +61,27 @@ let
|
||||
net ? { },
|
||||
resources ? { },
|
||||
traits ? [ ],
|
||||
isolation ? { },
|
||||
}:
|
||||
mkContainer {
|
||||
inherit name;
|
||||
inherit net resources;
|
||||
svc.autoStart = true;
|
||||
isolation.nixDaemon = nixDaemon;
|
||||
isolation = { nixDaemon = nixDaemon; } // isolation;
|
||||
traits = [ sshTrait ] ++ traits;
|
||||
packages = with pkgs; [ tmux ] ++ packages;
|
||||
miscProperties = self._sshpiperRegister routingInfo;
|
||||
};
|
||||
|
||||
kvmTrait = {
|
||||
containerConfig =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
users.users.runner.extraGroups = [ "wheel" ];
|
||||
security.sudo.wheelNeedsPassword = false;
|
||||
environment.systemPackages = [ pkgs.qemu_kvm ];
|
||||
};
|
||||
};
|
||||
in
|
||||
{
|
||||
ssh-admin = mkSsh {
|
||||
@@ -121,6 +132,25 @@ in
|
||||
mem = "16G";
|
||||
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 = [
|
||||
{
|
||||
username = "autumn";
|
||||
|
||||
@@ -228,6 +228,17 @@ rec {
|
||||
: systemd-nspawn user namespacing; see `--private-users=` in
|
||||
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`
|
||||
: Arbitrary data attached to the result. Used for cross-container discovery
|
||||
via `collectContainers`.
|
||||
@@ -272,6 +283,8 @@ rec {
|
||||
bindMounts = resources.fs or { };
|
||||
allowsNixDaemon = isolation.nixDaemon or false;
|
||||
privateUsers = isolation.privateUsers or "pick";
|
||||
allowedDevices = isolation.allowedDevices or [ ];
|
||||
additionalCapabilities = isolation.additionalCapabilities or [ ];
|
||||
|
||||
allowInternet = hasInternetAccess access;
|
||||
allBindMounts = builtins.foldl' (acc: t: acc // (t.resources.fs or { })) { } traits // bindMounts;
|
||||
@@ -368,7 +381,12 @@ rec {
|
||||
kind = "nspawn";
|
||||
miscProperties = flattenMiscProp self miscProperties;
|
||||
nixosContainer = {
|
||||
inherit autoStart privateUsers;
|
||||
inherit
|
||||
autoStart
|
||||
privateUsers
|
||||
allowedDevices
|
||||
additionalCapabilities
|
||||
;
|
||||
bindMounts = { };
|
||||
extraFlags = bindMountExtraFlags;
|
||||
privateNetwork = true;
|
||||
@@ -553,6 +571,8 @@ rec {
|
||||
Destination = "0.0.0.0/0";
|
||||
Gateway = hostAddr;
|
||||
};
|
||||
networkConfig.DNS = [ hostAddr ];
|
||||
networkConfig.Domains = [ "~." "containers" ];
|
||||
linkConfig.RequiredForOnline = if allowInternet then "routable" else "degraded";
|
||||
};
|
||||
networking.enableIPv6 = false;
|
||||
|
||||
Reference in New Issue
Block a user