diff --git a/.github/workflows/diff-pr.yml b/.github/workflows/diff-pr.yml index 7ba4bd7..17b0abf 100644 --- a/.github/workflows/diff-pr.yml +++ b/.github/workflows/diff-pr.yml @@ -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 "" "$RUNNER_TEMP/comment.md" + run: nix run -L .#ci -- post-comment "" "$RUNNER_TEMP/comment.md" diff --git a/.github/workflows/diff-tag.yml b/.github/workflows/diff-tag.yml index 8224366..381814d 100644 --- a/.github/workflows/diff-tag.yml +++ b/.github/workflows/diff-tag.yml @@ -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" diff --git a/.github/workflows/flake-check.yml b/.github/workflows/flake-check.yml index 452cfe6..9e6642d 100644 --- a/.github/workflows/flake-check.yml +++ b/.github/workflows/flake-check.yml @@ -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 diff --git a/.github/workflows/flake-update.yml b/.github/workflows/flake-update.yml index 2e57a9e..27ec96d 100644 --- a/.github/workflows/flake-update.yml +++ b/.github/workflows/flake-update.yml @@ -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 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 89a6d6f..bb0b54c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,15 +15,10 @@ 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 @@ -33,9 +28,9 @@ jobs: 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" diff --git a/.github/workflows/vulnix.yml b/.github/workflows/vulnix.yml index aa7e347..13a5440 100644 --- a/.github/workflows/vulnix.yml +++ b/.github/workflows/vulnix.yml @@ -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 diff --git a/ci.py b/ci.py index e4a3d57..56512ac 100644 --- a/ci.py +++ b/ci.py @@ -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): diff --git a/containers/server-n0/git.nix b/containers/server-n0/git.nix index f4510d7..b09a7c4 100644 --- a/containers/server-n0/git.nix +++ b/containers/server-n0/git.nix @@ -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"; @@ -100,20 +105,24 @@ in let runnerInstanceName = "ci-runner"; + 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 = with pkgs; [ - bashInteractive - coreutils - gitMinimal - nixVersions.latest - nodejs - cacert - ]; + 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 +134,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 +155,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"; diff --git a/dsl.nix b/dsl.nix index 1c6dcf0..8eb4d81 100644 --- a/dsl.nix +++ b/dsl.nix @@ -571,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;