Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Asterinas NixOS

Asterinas NixOS 是 Asterinas 的第一個散布版。我們選擇 NixOS 作為基礎作業系統,是因為其無與倫比的可訂製性與豐富的軟體包生態系統。Asterinas NixOS 的目的在於提供與原生 NixOS 相似的外觀與使用體驗,唯一的區別在於它將內核從 Linux 替換為 Asterinas。關於選擇 NixOS 的更多理由,請參見 RFC

免責聲明:Asterinas 是一個獨立且由社群主導的專案。Asterinas NixOS 並非 NixOS 的官方專案,且與 NixOS 基金會 任何隸屬關係。此處 包含任何贊助或背書之意。

Asterinas NixOS 尚未準備好用於生產環境。我們提供 Asterinas NixOS 是為了降低 Asterinas 內核的使用門檻,讓早期採用者與愛好者能夠嘗試並提供反饋。此外,Asterinas 開發者將此散布版作為主要的開發工具,有助於在 Asterinas 內核上啟用並測試更多現實世界的應用程式。

開始使用

終端使用者

The following instructions describe how to install Asterinas NixOS in a VM using the Asterinas NixOS installer ISO.

  1. 啟動 x86-64 的 Ubuntu 容器:

    docker run -it --privileged --network=host ubuntu:latest bash
    
  2. 在容器內安裝 QEMU:

    apt update
    apt install -y qemu-system-x86 qemu-utils
    
  3. GitHub Releases 下載最新的 Asterinas NixOS 安裝程式 ISO。

  4. Create a file that will be used as the target disk to install Asterinas NixOS:

    # The capacity of the disk is 10GB; adjust it as you see fit
    dd if=/dev/zero of=aster_nixos_disk.img bs=1G count=10
    
  5. Start an x86-64 VM with two drives: one is the installer CD-ROM and the other is the target disk:

    export INSTALLER_ISO=/path/to/your/downloaded/installer.iso
    qemu-system-x86_64 \
    -cpu host -m 8G -enable-kvm \
    -drive file="$INSTALLER_ISO",media=cdrom -boot d \
    -drive if=virtio,format=raw,file=aster_nixos_disk.img \
    -chardev stdio,id=mux,mux=on,logfile=qemu.log \
    -device virtio-serial-pci -device virtconsole,chardev=mux \
    -serial chardev:mux -monitor chardev:mux \
    -nographic
    

    After the VM boots, you now have access to the installation environment.

  6. Edit the configuration.nix file in the home directory to customize the NixOS system to be installed:

    vim configuration.nix
    

    The complete syntax and guidance for the configuration.nix file can be found in the NixOS manual. If you are not familiar with NixOS, you can simply skip this step.

    Not all combinations of settings in configuration.nix are supported by Asterinas NixOS yet. The ones that have been tested are documented in the subsequent chapters.

  7. 開始安裝:

    install_aster_nixos.sh --config configuration.nix --disk /dev/vda --force-format-disk
    

    The installation process involves downloading packages and may take around 30 minutes to complete, depending on your network speed.

  8. After the installation is complete, you can shut down the VM:

    poweroff
    

    Now Asterinas NixOS is installed in aster_nixos_disk.img.

  9. Start a VM to boot the newly installed Asterinas NixOS:

    qemu-system-x86_64 \
    -cpu host -m 8G -enable-kvm \
    -bios /usr/share/qemu/OVMF.fd \
    -drive if=none,format=raw,id=x0,file=aster_nixos_disk.img \
    -device virtio-blk-pci,drive=x0,disable-legacy=on,disable-modern=off \
    -chardev stdio,id=mux,mux=on,logfile=qemu.log \
    -device virtio-serial-pci -device virtconsole,chardev=mux \
    -serial chardev:mux -monitor chardev:mux \
    -device virtio-net-pci,netdev=net0,disable-legacy=on,disable-modern=off \
    -netdev user,id=net0 \
    -device isa-debug-exit,iobase=0xf4,iosize=0x04 \
    -nographic -display vnc=127.0.0.1:21
    

    If a desktop environment is enabled in the configuration.nix file, you can view the graphical interface using a VNC client.

內核開發者

  1. Follow Steps 1 and 2 in the “Getting Started” section of the Asterinas Kernel to set up the development environment.

  2. 在 Docker 容器內,使用以下命令生成已安裝 Asterinas NixOS 的磁碟映像:

    make nixos
    

    or this command:

    make iso && make run_iso
    

    The difference between the two methods is that the first installs NixOS to a disk image entirely inside the container, whereas the second emulates the manual ISO installation steps (see the previous section) by running a VM. Using either method results in a disk image with an Asterinas NixOS installation.

  3. Start a VM to run the installed Asterinas NixOS:

    make run_nixos