Add CI for nix commands

This commit is contained in:
vvsv 2025-12-12 02:59:07 +00:00 committed by Tate, Hongliang Tian
parent 95e9718700
commit cc227b8d08
5 changed files with 86 additions and 25 deletions

View File

@ -31,19 +31,28 @@ jobs:
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: Use nix-env to install and run the hello package
- name: Modify configuration.nix to include test-asterinas
run: |
make nixos NIXOS_DISK_SIZE_IN_MB=6144 NIXOS_TEST_COMMAND='nix-env -iA nixos.hello && hello' || true
make run_nixos || true
tail --lines 10 qemu.log | grep -q "^Hello, world!" || (echo "Test nix-env failed" && exit 1)
echo "Test nix-env succeeds!"
- name: Use nix-shell to install and run the hello package
sed -i "s/environment.systemPackages = with pkgs; \[ hello-asterinas \];/environment.systemPackages = with pkgs; \[ test-asterinas \];/" \
distro/etc_nixos/configuration.nix
- name: Test nix commands
run: |
make nixos NIXOS_DISK_SIZE_IN_MB=6144 NIXOS_TEST_COMMAND='nix-shell -p hello --command hello' || true
make nixos NIXOS_DISK_SIZE_IN_MB=6144 NIXOS_TEST_COMMAND='test-nix-commands' || true
make run_nixos || true
tail --lines 10 qemu.log | grep -q "^Hello, world!" || (echo "Test nix-shell failed" && exit 1)
echo "Test nix-shell succeeds!"
- name: Check results
run: |
tail --lines 50 qemu.log | awk '
BEGIN { hello_count=0 } {
if ($0 ~ /^Hello, world!/) hello_count++
}
END {
if (hello_count == 4) exit 0
else exit 1
}' || (echo "Test nix commands failed" && exit 1)
echo "Test nix commands succeeds!"
podman-test:
runs-on: ubuntu-4-cores-150GB-ssd
container:
@ -52,13 +61,19 @@ jobs:
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
- name: Modify configuration.nix to include podman
- name: Modify configuration.nix to include test-asterinas and podman
run: |
sed -i "s/environment.systemPackages = with pkgs; \[ hello-asterinas \];/environment.systemPackages = with pkgs; \[ test-asterinas \];/" \
distro/etc_nixos/configuration.nix
sed -i 's/^[[:space:]]*# virtualisation\.podman\.enable = true;/ virtualisation.podman.enable = true;/' \
distro/etc_nixos/configuration.nix
distro/etc_nixos/configuration.nix
- name: Run podman commands
run: |
make nixos NIXOS_DISK_SIZE_IN_MB=8192 NIXOS_TEST_COMMAND='podman run docker.io/library/alpine:latest ls /etc' || true
make nixos NIXOS_DISK_SIZE_IN_MB=8192 NIXOS_TEST_COMMAND='test-podman' || true
make run_nixos || true
- name: Check results
run: |
tail --lines 50 qemu.log | grep -q "alpine-release" || (echo "Test podman failed" && exit 1)
echo "Test podman succeeds!"

View File

@ -3,18 +3,18 @@
{ config, lib, pkgs, ... }: {
# Imports all Nix files located under the 'modules' directory.
#
# Each Nix file within the 'modules' directory contributes a specific part to the overall 'configuration.nix'.
# For instance, 'core.nix' typically handles configurations
# Each Nix file within the 'modules' directory contributes a specific part to the overall 'configuration.nix'.
# For instance, 'core.nix' typically handles configurations
# related to the system's core functionalities and boot process.
#
# To maintain modularity,
# distinct aspects of the system's configuration
# should be organized into separate Nix files under the 'modules' directory and subsequently imported here.
#
# If a module's content is optional,
#
# To maintain modularity,
# distinct aspects of the system's configuration
# should be organized into separate Nix files under the 'modules' directory and subsequently imported here.
#
# If a module's content is optional,
# its activation should be controlled by an enable/disable switch defined in the top-level 'configuration.nix'.
#
# The content defined in these module files must adhere to the options permissible within 'configuration.nix'.
# The content defined in these module files must adhere to the options permissible within 'configuration.nix'.
# For a comprehensive list of available options,
# please refer to https://search.nixos.org/options.
imports = [
@ -25,14 +25,15 @@
];
# Overlays provide patches to 'nixpkgs' that enable these packages to run effectively on AsterNixOS.
# For details on the overlay file definition format,
# For details on the overlay file definition format,
# please refer to https://nixos.org/manual/nixpkgs/stable/#sec-overlays-definition.
config.nixpkgs.overlays = [
(import ./overlays/hello-asterinas/default.nix)
(import ./overlays/desktop/default.nix)
(import ./overlays/hello-asterinas/default.nix)
(import ./overlays/podman/default.nix)
(import ./overlays/systemd/default.nix)
(import ./overlays/switch-to-configuration-ng/default.nix)
(import ./overlays/systemd/default.nix)
(import ./overlays/test-asterinas/default.nix)
];
# The Asterinas NixOS special options.

View File

@ -0,0 +1,13 @@
final: prev: {
test-asterinas = prev.stdenv.mkDerivation {
name = "test-asterinas";
version = "0.1.0";
src = ./.;
installPhase = ''
install -m755 -D $src/test-nix-commands.sh $out/bin/test-nix-commands
install -m755 -D $src/test-podman.sh $out/bin/test-podman
'';
};
}

View File

@ -0,0 +1,25 @@
#!/bin/sh
# SPDX-License-Identifier: MPL-2.0
set -e
# Test nix-env
nix-env -iA nixos.hello
hello
nix-env -e hello
# Test nix-shell
nix-shell -p hello --command hello
# Test nix-build
nix-build "<nixpkgs>" -A hello
./result/bin/hello
# Test nixos-rebuild
sed -i "s/environment.systemPackages = with pkgs; \[ test-asterinas \];/environment.systemPackages = with pkgs; \[ test-asterinas hello \];/" \
/etc/nixos/configuration.nix
nixos-rebuild test
# Clean the hash cache to use the hello installed by nixos-rebuild
hash -r
hello

View File

@ -0,0 +1,7 @@
#!/bin/sh
# SPDX-License-Identifier: MPL-2.0
set -e
podman run docker.io/library/alpine:latest ls /etc