Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM dragonos/dragonos-dev:v1.21
FROM dragonos/dragonos-dev:v1.22

# 设置环境变量
ENV TZ=Asia/Shanghai
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/devcontainers/spec/refs/heads/main/schemas/devContainer.schema.json",
"name": "DragonOS Dev Container",
"image": "docker.cnb.cool/dragonos-community/dragonos/dragonos-devcontainer:v1.19",
"image": "docker.cnb.cool/dragonos-community/dragonos/dragonos-devcontainer:v1.22",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "false",
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
name: Format check ${{ matrix.arch }}
runs-on: ubuntu-latest
continue-on-error: true
container: dragonos/dragonos-dev:v1.21
container: dragonos/dragonos-dev:v1.22

strategy:
matrix:
arch: [x86_64, riscv64, loongarch64]

steps:
- run: echo "Running in dragonos/dragonos-dev:v1.21"
- run: echo "Running in dragonos/dragonos-dev:v1.22"
- uses: actions/checkout@v3

- name: Change source
Expand All @@ -39,14 +39,14 @@ jobs:
name: Kernel static test ${{ matrix.arch }}
runs-on: ubuntu-latest
continue-on-error: true
container: dragonos/dragonos-dev:v1.21
container: dragonos/dragonos-dev:v1.22

strategy:
matrix:
arch: [x86_64, riscv64, loongarch64]

steps:
- run: echo "Running in dragonos/dragonos-dev:v1.21"
- run: echo "Running in dragonos/dragonos-dev:v1.22"

- uses: actions/checkout@v3

Expand All @@ -64,7 +64,7 @@ jobs:
build:
name: Build ${{ matrix.arch }}
runs-on: ubuntu-latest
container: dragonos/dragonos-dev:v1.21
container: dragonos/dragonos-dev:v1.22
continue-on-error: true
strategy:
matrix:
Expand All @@ -81,7 +81,7 @@ jobs:
checkout_params: {}

steps:
- run: echo "Running in dragonos/dragonos-dev:v1.21"
- run: echo "Running in dragonos/dragonos-dev:v1.22"

- uses: actions/checkout@v3
with: ${{ matrix.checkout_params }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
env:
HOME: /root
container:
image: dragonos/dragonos-dev:v1.21
image: dragonos/dragonos-dev:v1.22
options: --privileged -v /dev:/dev
steps:
- name: Checkout DragonOS code
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-mm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
name: Build slab_stress (host)
runs-on: ubuntu-latest
container:
image: dragonos/dragonos-dev:v1.21
image: dragonos/dragonos-dev:v1.22
options: --privileged -v /dev:/dev
steps:
- name: Checkout DragonOS code
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
size: [64, 128, 255, 256]
seed: [1, 2, 3]
container:
image: dragonos/dragonos-dev:v1.21
image: dragonos/dragonos-dev:v1.22
options: --privileged -v /dev:/dev
steps:
- name: Checkout DragonOS code
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-x86.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 60
container:
image: dragonos/dragonos-dev:v1.21
image: dragonos/dragonos-dev:v1.22
options: --privileged -v /dev:/dev
steps:
- name: Checkout DragonOS code
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ cppcheck.xml
compile_commands.json
/logs/
*.log
.nix-gc-root
dadk-manifest.generated.toml
config/rootfs.generated.toml

Expand Down
17 changes: 16 additions & 1 deletion docs/introduction/develop_nix.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ nix 的引入使得 DragonOS 的开发环境不再依赖手动维护的 `bootstr
- 如果你想体验 nix 带来的声明式管理,又不想更改发行版,尝试 home-manager 并在其上配置启用 flakes、direnv
- 否则可以直接以 nix standalone 的方式安装 flakes,或者每次输入命令时添加 `--experimental-features 'nix-command flakes'`

## 国内镜像加速(推荐)

如果你在国内且没有全局代理,首次拉取依赖可能很慢甚至失败。本仓库已在 `flake.nix` 内置国内镜像配置,使用 `nix develop / nix run` 时会自动生效。

若仍然不生效,建议在用户级配置中追加以下内容(不会覆盖你已有配置):

```shell
mkdir -p ~/.config/nix
cat >> ~/.config/nix/nix.conf <<'EOF'
# DragonOS Nix mirror (CN)
extra-substituters = https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store https://mirrors.ustc.edu.cn/nix-channels/store
extra-trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=
EOF
```

## 克隆仓库

DragonOS 现在在多个托管平台上都有仓库镜像
Expand All @@ -26,7 +41,7 @@ cd DragonOS
## 激活内核编译环境

```shell
nix develop ./tools/nix-dev-shell
nix develop
```

如果你配置了 `direnv`,首次进入仓库目录会提示需要执行 `direnv allow`,相当于自动进入了 `nix develop` 环境。
Expand Down
76 changes: 74 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{
description = "RootFS";

nixConfig = {
# 国内镜像优先,保留官方缓存作为回退
extra-substituters = [
"https://mirrors.tuna.tsinghua.edu.cn/nix-channels/store"
"https://mirrors.ustc.edu.cn/nix-channels/store"
];
extra-trusted-public-keys = [
"cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
];
};

inputs = {
fenix = {
url = "github:nix-community/fenix";
Expand Down Expand Up @@ -45,10 +56,37 @@
rootfsType = "ext4";
buildDir = "./bin"; # Specifying temp file location

rust-toolchain = fenix.packages.${system}.fromToolchainFile {
file = ./kernel/rust-toolchain.toml;
rust-toolchain-toml = builtins.fromTOML (builtins.readFile ./kernel/rust-toolchain.toml);
rust-channel-raw = rust-toolchain-toml.toolchain.channel;
rust-channel-match = builtins.match "^(stable|beta|nightly)(-([0-9]{4}-[0-9]{2}-[0-9]{2}))?$" rust-channel-raw;
rust-channel =
if rust-channel-match == null then rust-channel-raw else builtins.elemAt rust-channel-match 0;
rust-date =
if rust-channel-match == null || builtins.elemAt rust-channel-match 2 == null then
null
else
builtins.elemAt rust-channel-match 2;
rust-components = rust-toolchain-toml.toolchain.components or [ ];
rust-dist-root = "https://rsproxy.cn/dist";
rust-toolchain-base = fenix.packages.${system}.toolchainOf {
root = rust-dist-root;
channel = rust-channel;
date = rust-date;
sha256 = "sha256-3JA9u08FrvsLdi5dGIsUeQZq3Tpn9RvWdkLus2+5cHs=";
};
rust-toolchain-raw = rust-toolchain-base.withComponents rust-components;
rust-toolchain = pkgs.symlinkJoin {
name = "rust-toolchain-wrapped";
paths = [ rust-toolchain-raw ];
nativeBuildInputs = [ pkgs.makeWrapper ];
postBuild = ''
for bin in "$out/bin/"*; do
if [ -x "$bin" ]; then
wrapProgram "$bin" --prefix LD_LIBRARY_PATH : ${pkgs.zlib}/lib
fi
done
'';
};

testOpt = {
# 自动测试项目,指定内核启动环境变量参数 AUTO_TEST
Expand Down Expand Up @@ -79,8 +117,26 @@
# 启用 VM 状态管理,与 make qemu 行为保持一致
vmstateDir = "${buildDir}/vmstate";
};
qemuScriptsSystem = import ./tools/qemu/default.nix {
inherit
lib
pkgs
testOpt
diskPath
;
# QEMU 相关参数:
# 内核位置
kernel = "${buildDir}/kernel/kernel.elf"; # TODO: make it a drv 用nix构建内核,避免指定相对目录
# -s -S
debug = false;
# 启用 VM 状态管理,与 make qemu 行为保持一致
vmstateDir = "${buildDir}/vmstate";
# 优先使用系统 QEMU,避免 Nix 下载 QEMU 依赖
preferSystemQemu = true;
};

startPkg = qemuScripts.${target};
startSystemPkg = qemuScriptsSystem.${target};
rootfsPkg = pkgs.callPackage ./user/default.nix {
inherit
lib
Expand Down Expand Up @@ -126,6 +182,11 @@
program = "${startPkg}/bin/dragonos-run";
meta.description = "以 ${target} 启动DragonOS";
};
"start-system-${target}" = {
type = "app";
program = "${startSystemPkg}/bin/dragonos-run";
meta.description = "以系统 QEMU 启动DragonOS (${target})";
};
# rootfs 中涉及到基于docker镜像的rootfs构建,修改了 user/ 下软件包相关内容后,
# rootfs 的docker镜像会重复构建,并且由于nix特性,副本会全部保留
# 因此可能会占很多空间,如果要清理空间请执行 nix store gc
Expand All @@ -138,6 +199,7 @@
packages = {
"yolo-${target}" = runApp;
"start-${target}" = startPkg;
"start-system-${target}" = startSystemPkg;
"rootfs-${target}" = rootfsPkg;
};
};
Expand Down Expand Up @@ -184,8 +246,11 @@
libclang
gcc
rust-toolchain
zlib
gnumake
qemu_kvm
meson
ninja
];

env = {
Expand All @@ -195,6 +260,13 @@

# Shell启动脚本
shellHook = ''
# 自动创建 GC root,避免 nix store gc 清理开发环境
if [ -z "''${DRAGONOS_NIX_GC_ROOT:-}" ]; then
if [ ! -e ".nix-gc-root" ]; then
echo "创建 Nix GC root: .nix-gc-root"
${pkgs.nix}/bin/nix build .#devShells.${system}.default -o ./.nix-gc-root >/dev/null 2>&1 || true
fi
fi
echo "欢迎进入 DragonOS Nix 开发环境!"
echo ""
echo "要运行 DragonOS,请构建内核、rootfs,再QEMU运行"
Expand Down
Loading
Loading