Default to systemd boot

This commit is contained in:
Chen Chengjun 2025-12-09 07:30:02 +00:00 committed by Tate, Hongliang Tian
parent 8106d08b0f
commit ddb667d3b3
5 changed files with 15 additions and 4 deletions

View File

@ -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!"

View File

@ -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)

View File

@ -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

View File

@ -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"

View File

@ -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