forked from fediversity/fediversity
Compare commits
No commits in common. "560098a9631218c7d13207c24583fa1de56a75bb" and "5cb6f03e4eb38df06caf3a9ebc9b9fdc8aafa283" have entirely different histories.
560098a963
...
5cb6f03e4e
3 changed files with 95 additions and 213 deletions
|
|
@ -12,7 +12,7 @@ jobs:
|
||||||
check-pre-commit:
|
check-pre-commit:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: nix
|
image: icewind1991/nix-runner
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: nix-build -A tests
|
- run: nix-build -A tests
|
||||||
|
|
@ -20,7 +20,7 @@ jobs:
|
||||||
check-data-model:
|
check-data-model:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: nix
|
image: icewind1991/nix-runner
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: nix-shell --run 'nix-unit ./deployment/data-model-test.nix'
|
- run: nix-shell --run 'nix-unit ./deployment/data-model-test.nix'
|
||||||
|
|
@ -28,7 +28,7 @@ jobs:
|
||||||
check-peertube:
|
check-peertube:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: nix
|
image: icewind1991/nix-runner
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: nix-build services -A tests.peertube
|
- run: nix-build services -A tests.peertube
|
||||||
|
|
@ -36,7 +36,7 @@ jobs:
|
||||||
check-panel:
|
check-panel:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: nix
|
image: icewind1991/nix-runner
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: nix-build panel -A tests
|
- run: nix-build panel -A tests
|
||||||
|
|
@ -44,7 +44,7 @@ jobs:
|
||||||
check-deployment-basic:
|
check-deployment-basic:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: nix
|
image: icewind1991/nix-runner
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: nix build .#checks.x86_64-linux.deployment-basic -L
|
- run: nix build .#checks.x86_64-linux.deployment-basic -L
|
||||||
|
|
@ -52,7 +52,7 @@ jobs:
|
||||||
check-deployment-cli:
|
check-deployment-cli:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: nix
|
image: icewind1991/nix-runner
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: nix build .#checks.x86_64-linux.deployment-cli -L
|
- run: nix build .#checks.x86_64-linux.deployment-cli -L
|
||||||
|
|
@ -60,7 +60,7 @@ jobs:
|
||||||
check-deployment-panel:
|
check-deployment-panel:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: nix
|
image: icewind1991/nix-runner
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: nix build .#checks.x86_64-linux.deployment-panel -L
|
- run: nix build .#checks.x86_64-linux.deployment-panel -L
|
||||||
|
|
|
||||||
|
|
@ -1,218 +1,104 @@
|
||||||
# source: https://git.clan.lol/clan/clan-infra/src/branch/main/modules/web01/gitea/actions-runner.nix
|
|
||||||
{
|
{
|
||||||
pkgs,
|
pkgs,
|
||||||
lib,
|
|
||||||
config,
|
config,
|
||||||
|
# sources,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
|
||||||
system = builtins.currentSystem;
|
|
||||||
packages =
|
|
||||||
let
|
let
|
||||||
sources = import ../../../npins;
|
sources = import ../../../npins;
|
||||||
inherit (import sources.flake-inputs) import-flake;
|
|
||||||
inherit ((import-flake { src = ../../..; }).inputs) nixops4;
|
|
||||||
in
|
|
||||||
[
|
|
||||||
pkgs.coreutils
|
|
||||||
pkgs.findutils
|
|
||||||
pkgs.gnugrep
|
|
||||||
pkgs.gawk
|
|
||||||
pkgs.git
|
|
||||||
pkgs.nix
|
|
||||||
pkgs.bash
|
|
||||||
pkgs.jq
|
|
||||||
pkgs.nodejs
|
|
||||||
pkgs.npins
|
|
||||||
nixops4.packages.${system}.default
|
|
||||||
];
|
|
||||||
storeDeps = pkgs.runCommand "store-deps" { } ''
|
|
||||||
mkdir -p $out/bin
|
|
||||||
for dir in ${toString packages}; do
|
|
||||||
for bin in "$dir"/bin/*; do
|
|
||||||
ln -s "$bin" "$out/bin/$(basename "$bin")"
|
|
||||||
done
|
|
||||||
done
|
|
||||||
# Add SSL CA certs
|
|
||||||
mkdir -p $out/etc/ssl/certs
|
|
||||||
cp -a "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" $out/etc/ssl/certs/ca-bundle.crt
|
|
||||||
'';
|
|
||||||
numInstances = 2;
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
users = {
|
_class = "nixos";
|
||||||
users.nixuser = {
|
|
||||||
group = "nixuser";
|
services.gitea-actions-runner = {
|
||||||
description = "Used for running nix ci jobs";
|
package = pkgs.forgejo-actions-runner;
|
||||||
home = "/var/empty";
|
|
||||||
isSystemUser = true;
|
instances.default = {
|
||||||
};
|
|
||||||
groups.nixuser = { };
|
|
||||||
};
|
|
||||||
virtualisation = {
|
|
||||||
podman.enable = true;
|
|
||||||
containers.containersConf.settings = {
|
|
||||||
# podman seems to not work with systemd-resolved
|
|
||||||
containers.dns_servers = [
|
|
||||||
"8.8.8.8"
|
|
||||||
"8.8.4.4"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
services.gitea-actions-runner.instances =
|
|
||||||
lib.genAttrs (builtins.genList (n: "nix${builtins.toString n}") numInstances)
|
|
||||||
(_: {
|
|
||||||
enable = true;
|
enable = true;
|
||||||
name = "nix-runner";
|
|
||||||
|
name = config.networking.fqdn;
|
||||||
url = "https://git.fediversity.eu";
|
url = "https://git.fediversity.eu";
|
||||||
tokenFile = config.age.secrets.forgejo-runner-token.path;
|
tokenFile = config.age.secrets.forgejo-runner-token.path;
|
||||||
labels = [ "nix:docker://gitea-runner-nix" ];
|
|
||||||
settings = {
|
settings = {
|
||||||
container.options = "-e NIX_BUILD_SHELL=/bin/bash -e PAGER=cat -e PATH=/bin -e SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt --device /dev/kvm -v /nix:/nix -v ${storeDeps}/bin:/bin -v ${storeDeps}/etc/ssl:/etc/ssl --user nixuser --device=/dev/kvm";
|
log.level = "info";
|
||||||
# the default network that also respects our dns server settings
|
runner = {
|
||||||
container.network = "host";
|
file = ".runner";
|
||||||
container.valid_volumes = [
|
# Take only 1 job at a time to avoid clashing NixOS tests, see #362
|
||||||
"/nix"
|
capacity = 1;
|
||||||
"${storeDeps}/bin"
|
timeout = "3h";
|
||||||
"${storeDeps}/etc/ssl"
|
insecure = false;
|
||||||
|
fetch_timeout = "5s";
|
||||||
|
fetch_interval = "2s";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
## This runner supports Docker (with a default Ubuntu image) and native
|
||||||
|
## modes. In native mode, it contains a few default packages.
|
||||||
|
labels = [
|
||||||
|
"docker:docker://node:16-bullseye"
|
||||||
|
"native:host"
|
||||||
|
];
|
||||||
|
|
||||||
|
hostPackages = with pkgs; [
|
||||||
|
bash
|
||||||
|
git
|
||||||
|
nix
|
||||||
|
nodejs
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
});
|
|
||||||
systemd.services =
|
|
||||||
{
|
|
||||||
gitea-runner-nix-image = {
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
after = [ "podman.service" ];
|
|
||||||
requires = [ "podman.service" ];
|
|
||||||
path = [
|
|
||||||
config.virtualisation.podman.package
|
|
||||||
pkgs.gnutar
|
|
||||||
pkgs.shadow
|
|
||||||
pkgs.getent
|
|
||||||
];
|
|
||||||
# we also include etc here because the cleanup job also wants the nixuser to be present
|
|
||||||
script = ''
|
|
||||||
set -eux -o pipefail
|
|
||||||
mkdir -p etc/nix
|
|
||||||
|
|
||||||
# Create an unpriveleged user that we can use also without the run-as-user.sh script
|
|
||||||
touch etc/passwd etc/group
|
|
||||||
groupid=$(cut -d: -f3 < <(getent group nixuser))
|
|
||||||
userid=$(cut -d: -f3 < <(getent passwd nixuser))
|
|
||||||
groupadd --prefix $(pwd) --gid "$groupid" nixuser
|
|
||||||
emptypassword='$6$1ero.LwbisiU.h3D$GGmnmECbPotJoPQ5eoSTD6tTjKnSWZcjHoVTkxFLZP17W9hRi/XkmCiAMOfWruUwy8gMjINrBMNODc7cYEo4K.'
|
|
||||||
useradd --prefix $(pwd) -p "$emptypassword" -m -d /tmp -u "$userid" -g "$groupid" -G nixuser nixuser
|
|
||||||
|
|
||||||
cat <<NIX_CONFIG > etc/nix/nix.conf
|
|
||||||
accept-flake-config = true
|
|
||||||
experimental-features = nix-command flakes
|
|
||||||
NIX_CONFIG
|
|
||||||
|
|
||||||
cat <<NSSWITCH > etc/nsswitch.conf
|
|
||||||
passwd: files mymachines systemd
|
|
||||||
group: files mymachines systemd
|
|
||||||
shadow: files
|
|
||||||
|
|
||||||
hosts: files mymachines dns myhostname
|
|
||||||
networks: files
|
|
||||||
|
|
||||||
ethers: files
|
|
||||||
services: files
|
|
||||||
protocols: files
|
|
||||||
rpc: files
|
|
||||||
NSSWITCH
|
|
||||||
|
|
||||||
# list the content as it will be imported into the container
|
|
||||||
tar -cv . | tar -tvf -
|
|
||||||
tar -cv . | podman import - gitea-runner-nix
|
|
||||||
'';
|
|
||||||
serviceConfig = {
|
|
||||||
RuntimeDirectory = "gitea-runner-nix-image";
|
|
||||||
WorkingDirectory = "/run/gitea-runner-nix-image";
|
|
||||||
Type = "oneshot";
|
|
||||||
RemainAfterExit = true;
|
|
||||||
};
|
};
|
||||||
};
|
|
||||||
}
|
## For the Docker mode of the runner.
|
||||||
// lib.genAttrs (builtins.genList (n: "gitea-runner-nix${builtins.toString n}") numInstances) (
|
virtualisation.docker.enable = true;
|
||||||
_:
|
virtualisation.oci-containers.containers."buildResult" =
|
||||||
let
|
let
|
||||||
requires = [ "gitea-runner-nix-image.service" ];
|
name = "nix-runner";
|
||||||
|
tag = "latest";
|
||||||
|
base = import (sources.nix + "/docker.nix") {
|
||||||
|
inherit pkgs;
|
||||||
|
name = "nix-ci-base";
|
||||||
|
maxLayers = 10;
|
||||||
|
extraPkgs = with pkgs; [
|
||||||
|
nodejs_20 # nodejs is needed for running most 3rdparty actions
|
||||||
|
# add any other pre-installed packages here
|
||||||
|
];
|
||||||
|
# change this is you want
|
||||||
|
channelURL = "https://nixos.org/channels/nixpkgs-23.05";
|
||||||
|
nixConf = {
|
||||||
|
substituters = [
|
||||||
|
"https://cache.nixos.org/"
|
||||||
|
"https://nix-community.cachix.org"
|
||||||
|
# insert any other binary caches here
|
||||||
|
];
|
||||||
|
trusted-public-keys = [
|
||||||
|
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
|
||||||
|
"nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
|
||||||
|
# insert the public keys for those binary caches here
|
||||||
|
];
|
||||||
|
# allow using the new flake commands in our workflows
|
||||||
|
experimental-features = [
|
||||||
|
"nix-command"
|
||||||
|
"flakes"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit requires;
|
devices = [ "/dev/kvm:/dev/kvm" ];
|
||||||
after = requires;
|
image = "${name}:${tag}";
|
||||||
# TODO: systemd confinement
|
# https://icewind.nl/entry/gitea-actions-nix/
|
||||||
serviceConfig = {
|
imageFile = pkgs.dockerTools.buildImage {
|
||||||
# Hardening (may overlap with DynamicUser=)
|
inherit name tag;
|
||||||
# The following options are only for optimizing output of systemd-analyze
|
fromImage = base;
|
||||||
AmbientCapabilities = "";
|
fromImageName = null;
|
||||||
CapabilityBoundingSet = "";
|
fromImageTag = "latest";
|
||||||
# ProtectClock= adds DeviceAllow=char-rtc r
|
copyToRoot = pkgs.buildEnv {
|
||||||
DeviceAllow = "";
|
name = "image-root";
|
||||||
NoNewPrivileges = true;
|
paths = [ pkgs.coreutils-full ];
|
||||||
PrivateDevices = true;
|
pathsToLink = [ "/bin" ]; # add coreutils (which includes sleep) to /bin
|
||||||
PrivateMounts = true;
|
};
|
||||||
PrivateTmp = true;
|
};
|
||||||
PrivateUsers = true;
|
|
||||||
ProtectClock = true;
|
|
||||||
ProtectControlGroups = true;
|
|
||||||
ProtectHome = true;
|
|
||||||
ProtectHostname = true;
|
|
||||||
ProtectKernelLogs = true;
|
|
||||||
ProtectKernelModules = true;
|
|
||||||
ProtectKernelTunables = true;
|
|
||||||
ProtectSystem = "strict";
|
|
||||||
RemoveIPC = true;
|
|
||||||
RestrictNamespaces = true;
|
|
||||||
RestrictRealtime = true;
|
|
||||||
RestrictSUIDSGID = true;
|
|
||||||
UMask = "0066";
|
|
||||||
ProtectProc = "invisible";
|
|
||||||
SystemCallFilter = [
|
|
||||||
"~@clock"
|
|
||||||
"~@cpu-emulation"
|
|
||||||
"~@module"
|
|
||||||
"~@mount"
|
|
||||||
"~@obsolete"
|
|
||||||
"~@raw-io"
|
|
||||||
"~@reboot"
|
|
||||||
"~@swap"
|
|
||||||
# needed by go?
|
|
||||||
#"~@resources"
|
|
||||||
"~@privileged"
|
|
||||||
"~capset"
|
|
||||||
"~setdomainname"
|
|
||||||
"~sethostname"
|
|
||||||
];
|
|
||||||
SupplementaryGroups = [ "podman" ];
|
|
||||||
RestrictAddressFamilies = [
|
|
||||||
"AF_INET"
|
|
||||||
"AF_INET6"
|
|
||||||
"AF_UNIX"
|
|
||||||
"AF_NETLINK"
|
|
||||||
];
|
|
||||||
|
|
||||||
# Needs network access
|
|
||||||
PrivateNetwork = false;
|
|
||||||
# Cannot be true due to Node
|
|
||||||
MemoryDenyWriteExecute = false;
|
|
||||||
|
|
||||||
# The more restrictive "pid" option makes `nix` commands in CI emit
|
|
||||||
# "GC Warning: Couldn't read /proc/stat"
|
|
||||||
# You may want to set this to "pid" if not using `nix` commands
|
|
||||||
ProcSubset = "all";
|
|
||||||
# Coverage programs for compiled code such as `cargo-tarpaulin` disable
|
|
||||||
# ASLR (address space layout randomization) which requires the
|
|
||||||
# `personality` syscall
|
|
||||||
# You may want to set this to `true` if not using coverage tooling on
|
|
||||||
# compiled code
|
|
||||||
LockPersonality = false;
|
|
||||||
|
|
||||||
# Note that this has some interactions with the User setting; so you may
|
|
||||||
# want to consult the systemd docs if using both.
|
|
||||||
DynamicUser = true;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -110,8 +110,4 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# needed to imperatively run forgejo commands e.g. to generate runner tokens.
|
|
||||||
# example: `sudo su - forgejo -c 'nix-shell -p forgejo --run "gitea actions generate-runner-token -C /var/lib/forgejo/custom"'`
|
|
||||||
users.users.forgejo.isNormalUser = true;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue