Skip to content

Commit 196ce3d

Browse files
committed
NixOS tests
1 parent 6dbdce8 commit 196ce3d

5 files changed

Lines changed: 100 additions & 32 deletions

File tree

.github/actions/setup-nix/action.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ runs:
1919
- name: Install Nix
2020
uses: nixbuild/nix-quick-install-action@master
2121
with:
22+
# TODO: When ready to migrate from nix-csi to nixkube module naming:
23+
# - Update trusted-public-keys: nix-csi.cachix.org-1 → nixkube.cachix.org-1
24+
# - Update substituters: https://nix-csi.cachix.org → https://nixkube.cachix.org
25+
# - Recreate/migrate Cachix cache from nix-csi to nixkube
2226
nix_conf: |
23-
experimental-features = nix-command flakes
24-
access-tokens = github.com=${{ inputs.github_token }}
25-
# TODO: When ready to migrate from nix-csi to nixkube module naming:
26-
# - Update trusted-public-keys: nix-csi.cachix.org-1 → nixkube.cachix.org-1
27-
# - Update substituters: https://nix-csi.cachix.org → https://nixkube.cachix.org
28-
# - Recreate/migrate Cachix cache from nix-csi to nixkube
2927
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o= nixbuild.net/CHEAKK-1:IvfuR1Ldmkef8pMcSuCl9N2jppEb8KpBzdoB8uKQdxE= nix-csi.cachix.org-1:i4w33gR4efO67jpz8U7g/MdvRQ6mQ3LEF9fB8tES60g=
28+
extra-platforms = aarch64-linux qemu-user
3029
builders = ssh-ng://eu.nixbuild.net aarch64-linux ; ssh-ng://eu.nixbuild.net x86_64-linux
3130
substituters = https://cache.nixos.org?priority=1 https://nix-csi.cachix.org?priority=2 https://cache.lix.systems?priority=3 ssh-ng://eu.nixbuild.net?priority=4
3231
keep-env-derivations = true

.github/workflows/ci.yaml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -254,32 +254,6 @@ jobs:
254254
limit-access-to-actor: true
255255
wait-timeout-minutes: 5
256256

257-
test-nixos:
258-
needs: build
259-
runs-on: ubuntu-latest
260-
continue-on-error: true
261-
steps:
262-
- name: Checkout
263-
uses: actions/checkout@main
264-
265-
- name: Setup Nix environment
266-
uses: ./.github/actions/setup-nix
267-
with:
268-
nixbuild_key: ${{ secrets.NIXBUILD_KEY }}
269-
github_token: ${{ secrets.GITHUB_TOKEN }}
270-
cache_key: test-nixos
271-
272-
- name: Ensure KVM is available
273-
run: |
274-
if [ ! -e /dev/kvm ]; then
275-
echo "::warning::KVM not available, test will likely fail"
276-
fi
277-
sudo chmod 666 /dev/kvm || true
278-
279-
- name: Run NixOS integration test
280-
run: |
281-
nix build --show-trace --file . nixosTests.containerd --print-build-logs
282-
283257
release:
284258
needs: [build, test-kind-cache, test-kind-nocache]
285259
runs-on: ubuntu-latest

.github/workflows/test-nixos.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-License-Identifier: MIT
2+
3+
on:
4+
push:
5+
branches:
6+
- '*'
7+
pull_request:
8+
workflow_dispatch:
9+
10+
env:
11+
REPO_USERNAME: ${{ github.actor }}
12+
REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
14+
permissions:
15+
contents: read
16+
17+
jobs:
18+
test-nixos:
19+
runs-on: ubuntu-latest
20+
continue-on-error: true
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@main
24+
25+
- name: Install Nix
26+
uses: nixbuild/nix-quick-install-action@master
27+
with:
28+
nix_conf: |
29+
experimental-features = nix-command flakes
30+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
31+
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= cache.lix.systems:aBnZUw8zA7H35Cz2RyKFVs3H4PlGTLawyY5KRbvJR8o= nixbuild.net/CHEAKK-1:IvfuR1Ldmkef8pMcSuCl9N2jppEb8KpBzdoB8uKQdxE= nix-csi.cachix.org-1:i4w33gR4efO67jpz8U7g/MdvRQ6mQ3LEF9fB8tES60g=
32+
extra-platforms = aarch64-linux
33+
builders = ssh-ng://eu.nixbuild.net aarch64-linux ; ssh-ng://eu.nixbuild.net x86_64-linux
34+
substituters = https://cache.nixos.org?priority=1 https://nix-csi.cachix.org?priority=2 https://cache.lix.systems?priority=3 ssh-ng://eu.nixbuild.net?priority=4
35+
36+
- name: Configure SSH Keys
37+
shell: bash
38+
run: |
39+
echo "${{ secrets.NIXBUILD_KEY }}" | install -D -m 600 /dev/stdin ~/.ssh/nixbuild_key
40+
install -m 644 "${{ github.workspace }}/.github/assets/ssh-config" ~/.ssh/config
41+
42+
- name: Setup upterm session
43+
uses: owenthereal/action-upterm@v1

default.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,38 @@ rec {
169169
};
170170
};
171171

172+
# Register binfmt handlers for cross-architecture builds (e.g., aarch64-linux on x86_64).
173+
#
174+
# The kernel binfmt P flag (preserveArgvZero) inserts the original argv[0] as an
175+
# extra argument: interpreter <original-argv0> <binary-path> [args...]. A raw
176+
# qemu-aarch64 binary doesn't understand this calling convention and will crash.
177+
# wrapQemuBinfmtP builds a statically-linked C wrapper (TARGET_QEMU baked in at
178+
# compile time) that translates the P-flag calling convention into proper qemu -0
179+
# invocation and strips LD_* vars so they can't affect qemu inside Nix sandboxes.
180+
#
181+
# The kernel registration always points to /run/binfmt/<name> (not the store path
182+
# directly) to stay under the kernel's interpreter path length limit and to allow
183+
# the symlink to be updated without re-registering.
184+
register-binfmt =
185+
let
186+
qemuBin = lib.getExe' pkgs.qemu-user "qemu-aarch64";
187+
wrapper = pkgs.wrapQemuBinfmtP "qemu-aarch64-binfmt-P" qemuBin;
188+
wrapperBin = "${wrapper}/bin/qemu-aarch64-binfmt-P";
189+
in
190+
pkgs.writeShellScriptBin "register-binfmt" ''
191+
set -euo pipefail
192+
echo "Setting up /run/binfmt/aarch64-linux -> ${wrapperBin}"
193+
sudo mkdir -p /run/binfmt
194+
sudo ln -sf ${wrapperBin} /run/binfmt/aarch64-linux
195+
196+
echo "Registering binfmt handler for aarch64-linux..."
197+
# Remove any existing registration first (ignore errors if not registered)
198+
echo -1 | sudo tee /proc/sys/fs/binfmt_misc/aarch64-linux > /dev/null 2>&1 || true
199+
printf ':aarch64-linux:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff:/run/binfmt/aarch64-linux:P\n' | \
200+
sudo tee /proc/sys/fs/binfmt_misc/register > /dev/null
201+
echo "Done!"
202+
'';
203+
172204
lixImage = pkgs.callPackage ./liximage.nix { };
173205
scratchImage = pkgs.callPackage ./scratchimage.nix { };
174206
}

tests/nixos/cluster-module.nix

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
environment.systemPackages = [
1616
pkgs.kubernetes # kubectl, kubeadm, kubelet
1717
pkgs.cri-tools # crictl
18+
pkgs.helix # editor
1819
];
1920

21+
environment.variables.EDITOR = "hx";
22+
2023
# -- Containerd CRI --
2124
virtualisation.containerd = {
2225
enable = true;
@@ -130,6 +133,16 @@
130133
cores = 4;
131134
};
132135

136+
# -- Interactive debug user --
137+
users.users.nixkube = {
138+
isNormalUser = true;
139+
initialPassword = "nixkube";
140+
extraGroups = [ "wheel" ];
141+
};
142+
143+
# Allow nixkube to use sudo without password
144+
security.sudo.wheelNeedsPassword = false;
145+
133146
# Disable COW on etcd data dir (etcd doesn't tolerate COW filesystems)
134147
system.activationScripts.noCOWs.text = ''
135148
${lib.getExe' pkgs.coreutils "mkdir"} --parents /var/lib/etcd
@@ -140,4 +153,11 @@
140153
systemd.tmpfiles.rules = [
141154
"d /var/run/nri 0755 root root -"
142155
];
156+
157+
# Enable external networking for image pulls and nix binary cache access
158+
networking = {
159+
useDHCP = true;
160+
firewall.enable = false;
161+
};
162+
systemd.services.systemd-resolved.enable = true;
143163
}

0 commit comments

Comments
 (0)