Author SHA1 Message Date
Floweynt ead537aef9 suppress mail errors
diff-pr / dix (pull_request) Successful in 6m32s
flake-check / flake-check (pull_request) Successful in 3m50s
lint / lint (pull_request) Successful in 1m49s
2026-09-13 20:32:26 -05:00
Floweynt 5f729053b2 suppress mail errors
diff-pr / dix (pull_request) Successful in 6m34s
flake-check / flake-check (pull_request) Failing after 3m17s
lint / lint (pull_request) Successful in 1m50s
2026-09-13 20:14:24 -05:00
Floweynt 84d4aa734a suppress mail errors
diff-pr / dix (pull_request) Successful in 6m30s
flake-check / flake-check (pull_request) Failing after 3m28s
lint / lint (pull_request) Successful in 1m46s
2026-09-13 20:00:39 -05:00
Floweynt d288689de3 fix failing passes
diff-pr / dix (pull_request) Successful in 6m42s
lint / lint (pull_request) Successful in 1m48s
flake-check / flake-check (pull_request) Failing after 3m21s
2026-09-13 14:33:29 -05:00
Floweynt 5888038c32 improve 2026-09-13 14:33:29 -05:00
Floweynt f1eb050ed6 format 2026-09-13 14:33:29 -05:00
Floweynt 6089103cba meow 2026-09-13 14:33:29 -05:00
6 changed files with 17 additions and 61 deletions
+1 -2
View File
@@ -19,10 +19,9 @@ in
giteaRepo = "server/server-config"; giteaRepo = "server/server-config";
tokenFile = "${hostInfo.paths.secrets}/gitea-autodeploy-token"; tokenFile = "${hostInfo.paths.secrets}/gitea-autodeploy-token";
allowedSigners = [ allowedSigners = [
"flowey@arch namespaces=\"git\" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPaGpTX3EzfezVc2nl3MgsKVamYYP2h2VJaRny8pZkvi" "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPaGpTX3EzfezVc2nl3MgsKVamYYP2h2VJaRny8pZkvi flowey@arch"
]; ];
stateDir = hostInfo.paths.config; stateDir = hostInfo.paths.config;
repoOwner = "server";
}; };
assertions = assertions =
+8 -14
View File
@@ -222,15 +222,13 @@ rec {
: Bind mounts, keyed by mount point. : Bind mounts, keyed by mount point.
`resources.devices` `resources.devices`
: Host device nodes to expose, as paths. Bound into the container at the : Host device nodes to expose, as paths, added to the unit's
same path and added to the unit's `DeviceAllow=` - the cgroup `DeviceAllow=`. nspawn populates a handful of privileged devices
permission alone doesn't get you a working node (nothing can `mknod` a (`/dev/kvm`, `/dev/net/tun`, ...) into the container's own `/dev` once
device inside a user namespace), and the bind alone leaves the cgroup the cgroup allows it, and silently skips ones the host doesn't have -
denying `open()`, so both are needed. The bind is unconditional, so no `resources.fs` bind mount needed. Nodes keep their host ownership,
the device must actually exist on whatever host runs the container. so a consumer inside needs `isolation.privateUsers = "identity"` for
Nodes keep their host ownership, so a consumer inside needs the owning gid to mean anything.
`isolation.privateUsers = "identity"` for the owning gid to mean
anything.
`isolation.nixDaemon` `isolation.nixDaemon`
: Whether the Nix daemon and CLI are available inside the container. : Whether the Nix daemon and CLI are available inside the container.
@@ -297,10 +295,6 @@ rec {
+ lib.optionalString useIdmap ":idmap" + lib.optionalString useIdmap ":idmap"
) allBindMounts; ) allBindMounts;
bindMountHostPaths = map (bm: bm.hostPath) (lib.attrValues allBindMounts); bindMountHostPaths = map (bm: bm.hostPath) (lib.attrValues allBindMounts);
# DeviceAllow= alone only grants cgroup permission - nspawn can't
# mknod a device node inside a user namespace, so the node still
# needs an explicit bind from the host.
deviceFlags = map (d: "--bind=${d}") devices;
inherit (deriveIdentity ifPrefix.nspawn name) inherit (deriveIdentity ifPrefix.nspawn name)
iface iface
mac mac
@@ -387,7 +381,7 @@ rec {
nixosContainer = { nixosContainer = {
inherit autoStart privateUsers; inherit autoStart privateUsers;
bindMounts = { }; bindMounts = { };
extraFlags = bindMountExtraFlags ++ deviceFlags; extraFlags = bindMountExtraFlags;
privateNetwork = true; privateNetwork = true;
extraVeths = linkVeths; extraVeths = linkVeths;
config = config =
-12
View File
@@ -38,20 +38,10 @@ in
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
default = [ ]; default = [ ];
}; };
repoOwner = lib.mkOption {
type = lib.types.str;
description = "User that owns the configuration checkout";
};
stateDir = lib.mkOption { stateDir = lib.mkOption {
type = lib.types.str; type = lib.types.str;
}; };
hostname = lib.mkOption {
type = lib.types.str;
default = config.networking.hostName;
};
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
@@ -68,8 +58,6 @@ in
DEPLOY_BRANCH = cfg.branch; DEPLOY_BRANCH = cfg.branch;
STATE_DIR = cfg.stateDir; STATE_DIR = cfg.stateDir;
REPO_DIR = "/persist/@configuration"; REPO_DIR = "/persist/@configuration";
REPO_OWNER = cfg.repoOwner;
HOSTNAME = cfg.hostname;
}; };
serviceConfig = { serviceConfig = {
-4
View File
@@ -3,8 +3,6 @@
git, git,
curl, curl,
jq, jq,
util-linux,
openssh,
}: }:
import ./mk-script.nix { inherit writeShellApplication; } { import ./mk-script.nix { inherit writeShellApplication; } {
name = "server-autodeploy"; name = "server-autodeploy";
@@ -12,7 +10,5 @@ import ./mk-script.nix { inherit writeShellApplication; } {
git git
curl curl
jq jq
util-linux
openssh
]; ];
} }
+8 -10
View File
@@ -6,15 +6,12 @@ mkdir -p "$STATE_DIR"
exec 9>"$STATE_DIR/lock" exec 9>"$STATE_DIR/lock"
flock -n 9 || { echo "another deploy running"; exit 0; } flock -n 9 || { echo "another deploy running"; exit 0; }
runas() { runuser -u "$REPO_OWNER" -- "$@"; }
report_status() { report_status() {
echo "updating status to: $1 - $2"
[[ -f "$TOKEN_FILE" ]] || return 0 [[ -f "$TOKEN_FILE" ]] || return 0
curl -sf -X POST \ curl -sf -X POST \
-H "Authorization: token $(<"$TOKEN_FILE")" \ -H "Authorization: token $(<"$TOKEN_FILE")" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d "$(jq -n --arg s "$1" --arg d "$2" --arg c "deploy/$HOSTNAME" \ -d "$(jq -n --arg s "$1" --arg d "$2" --arg c "deploy/$(hostname)" \
'{state:$s,description:$d,context:$c}')" \ '{state:$s,description:$d,context:$c}')" \
"$GITEA_URL/api/v1/repos/$GITEA_REPO/statuses/$3" >/dev/null "$GITEA_URL/api/v1/repos/$GITEA_REPO/statuses/$3" >/dev/null
} }
@@ -27,9 +24,9 @@ export GIT_CONFIG_VALUE_0=ssh
export GIT_CONFIG_KEY_1=gpg.ssh.allowedSignersFile export GIT_CONFIG_KEY_1=gpg.ssh.allowedSignersFile
export GIT_CONFIG_VALUE_1="$ALLOWED_SIGNERS" export GIT_CONFIG_VALUE_1="$ALLOWED_SIGNERS"
runas git fetch origin --tags --prune-tags git fetch origin --tags --prune-tags
latest=$(runas git describe --abbrev=0 "$BRANCH" 2>/dev/null) || { latest=$(git describe --abbrev=0 "$BRANCH" 2>/dev/null) || {
echo "no tags on $BRANCH" echo "no tags on $BRANCH"
exit 0 exit 0
} }
@@ -39,16 +36,17 @@ current=$(cat "$STATE_DIR/tag" 2>/dev/null) || true
echo "new tag: $latest (current: ${current:-none})" echo "new tag: $latest (current: ${current:-none})"
runas git tag -v "$latest" || { git tag -v "$latest" || {
sha=$(runas git rev-list -1 "$latest") sha=$(git rev-list -1 "$latest")
report_status "failure" "tag signature verification failed" "$sha" report_status "failure" "tag signature verification failed" "$sha"
exit 1 exit 1
} }
sha=$(runas git rev-list -1 "$latest") sha=$(git rev-list -1 "$latest")
report_status "pending" "deploying $latest" "$sha" report_status "pending" "deploying $latest" "$sha"
flake_url="git+${GITEA_URL}/${GITEA_REPO}?ref=refs/tags/${latest}&rev=${sha}#$HOSTNAME" # build from remote, pinned to the verified rev - no local checkout needed
flake_url="git+${GITEA_URL}/${GITEA_REPO}?ref=refs/tags/${latest}&rev=${sha}#$(hostname)"
if nixos-rebuild switch --flake "$flake_url"; then if nixos-rebuild switch --flake "$flake_url"; then
echo "$latest" > "$STATE_DIR/tag" echo "$latest" > "$STATE_DIR/tag"
-19
View File
@@ -336,28 +336,9 @@ with subtest("(functional): published ports follow the container's lifetime"):
with subtest("(functional): declared devices are usable in-container"): with subtest("(functional): declared devices are usable in-container"):
for name, devices in DEVICES.items(): for name, devices in DEVICES.items():
for dev in devices: for dev in devices:
# opened, not stat'd: without DeviceAllow= the node is still visible
server.succeed(ct_cmd(name, f"exec 3<> {dev}")) server.succeed(ct_cmd(name, f"exec 3<> {dev}"))
with subtest("(functional): /dev/kvm actually initializes, not just opens"):
# a wrong-gid or unmapped node still opens but fails the ioctls qemu
# needs, so boot with no disk (never completes) and kill it - the
# failure mode this catches is qemu refusing to start at all.
for name, devices in DEVICES.items():
if "/dev/kvm" not in devices:
continue
out = server.succeed(
ct_cmd(
name,
f"{TIMEOUT} 3 qemu-system-x86_64 -enable-kvm -m 256 -nographic -no-reboot "
">/tmp/qemu.out 2>&1; cat /tmp/qemu.out",
)
)
assert "Permission denied" not in out, f"{name}: qemu couldn't use /dev/kvm:\n{out}"
assert "Could not access KVM" not in out, f"{name}: qemu couldn't use /dev/kvm:\n{out}"
with subtest("(isolation): devices reach only the container that declared them"): with subtest("(isolation): devices reach only the container that declared them"):
for name in enterable: for name in enterable:
for dev in {d for ds in DEVICES.values() for d in ds} - set(DEVICES.get(name, [])): for dev in {d for ds in DEVICES.values() for d in ds} - set(DEVICES.get(name, [])):