From ddb667d3b35bbd6934d627304894a263e4292c41 Mon Sep 17 00:00:00 2001 From: Chen Chengjun Date: Tue, 9 Dec 2025 07:30:02 +0000 Subject: [PATCH] Default to systemd boot --- .github/workflows/test_nixos_full.yml | 4 ++-- .github/workflows/test_nixos_minimal.yml | 2 +- Makefile | 3 ++- distro/modules/core.nix | 9 +++++++++ tools/nixos/install_asterinas.sh | 1 + 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test_nixos_full.yml b/.github/workflows/test_nixos_full.yml index 479519dd5..9fec10fe9 100644 --- a/.github/workflows/test_nixos_full.yml +++ b/.github/workflows/test_nixos_full.yml @@ -33,12 +33,12 @@ jobs: - uses: actions/checkout@v4 - name: Use nix-env to install and run the hello package run: | - make run NIXOS=1 NIXOS_DISK_SIZE_IN_MB=4096 NIXOS_STAGE_2_INIT='/bin/sh -l -c "nix-env -iA nixos.hello && hello && sync"' || true + make run NIXOS=1 NIXOS_DISK_SIZE_IN_MB=4096 NIXOS_TEST_COMMAND='nix-env -iA nixos.hello && hello' || 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 run: | - make run NIXOS=1 NIXOS_DISK_SIZE_IN_MB=4096 NIXOS_STAGE_2_INIT='/bin/sh -l -c "nix-shell -p hello --command hello && sync"' || true + make run NIXOS=1 NIXOS_DISK_SIZE_IN_MB=4096 NIXOS_TEST_COMMAND='nix-shell -p hello --command hello' || true tail --lines 10 qemu.log | grep -q "^Hello, world!" || (echo "Test nix-shell failed" && exit 1) echo "Test nix-shell succeeds!" diff --git a/.github/workflows/test_nixos_minimal.yml b/.github/workflows/test_nixos_minimal.yml index e8a33bb1a..74fe5ab02 100644 --- a/.github/workflows/test_nixos_minimal.yml +++ b/.github/workflows/test_nixos_minimal.yml @@ -37,7 +37,7 @@ jobs: with: image: asterinas/asterinas:0.16.1-20251130 options: --privileged -v /dev:/dev -v ${{ github.workspace }}:/root/asterinas - run: make run NIXOS=1 NIXOS_DISK_SIZE_IN_MB=4096 NIXOS_STAGE_2_INIT='/bin/sh -l -c "hello-asterinas"' || true + run: make run NIXOS=1 NIXOS_DISK_SIZE_IN_MB=4096 NIXOS_TEST_COMMAND='hello-asterinas' || true - name: Check results run: | tail --lines 10 ${{ github.workspace }}/qemu.log | grep -q "^Hello Asterinas!" || (echo "Test NixOS failed" && exit 1) diff --git a/Makefile b/Makefile index 4c750e91b..dfcf7f4f0 100644 --- a/Makefile +++ b/Makefile @@ -57,7 +57,8 @@ DNS_SERVER ?= none # NixOS settings NIXOS ?= 0 NIXOS_DISK_SIZE_IN_MB ?= 8196 -NIXOS_DISABLE_SYSTEMD ?= true +NIXOS_DISABLE_SYSTEMD ?= false +NIXOS_TEST_COMMAND ?= # The following option is only effective when NIXOS_DISABLE_SYSTEMD is set to 'true'. # Use a login shell to ensure that environment variables are initialized correctly. NIXOS_STAGE_2_INIT ?= /bin/sh -l diff --git a/distro/modules/core.nix b/distro/modules/core.nix index 428068072..8611c322a 100644 --- a/distro/modules/core.nix +++ b/distro/modules/core.nix @@ -35,6 +35,15 @@ in { ${builtins.getEnv "NIXOS_STAGE_2_INIT"} fi ''; + # Execute test-command on hvc0 console after boot if the test-command is + # not empty (for CI testing). + environment.loginShellInit = + lib.mkIf ("${builtins.getEnv "NIXOS_TEST_COMMAND"}" != "") '' + if [ "$(tty)" = "/dev/hvc0" ]; then + ${builtins.getEnv "NIXOS_TEST_COMMAND"} + poweroff + fi + ''; system.systemBuilderCommands = '' echo "PATH=/bin:/nix/var/nix/profiles/system/sw/bin ostd.log_level=${ builtins.getEnv "LOG_LEVEL" diff --git a/tools/nixos/install_asterinas.sh b/tools/nixos/install_asterinas.sh index dfa08b081..f9ebc3a5a 100755 --- a/tools/nixos/install_asterinas.sh +++ b/tools/nixos/install_asterinas.sh @@ -31,6 +31,7 @@ echo "STAGE_1_INIT=${NIXOS_STAGE_1_INIT}" echo "STAGE_2_INIT=${NIXOS_STAGE_2_INIT}" echo "RESOLV_CONF=${NIXOS_RESOLV_CONF}" echo "DISABLE_SYSTEMD=${NIXOS_DISABLE_SYSTEMD}" +echo "TEST_COMMAND=${NIXOS_TEST_COMMAND}" echo "************END OF NIXOS SETTINGS************" if [ ! -e ${ASTER_IMAGE_PATH} ]; then