-
-
Notifications
You must be signed in to change notification settings - Fork 168
feat(build): replace rootfs and user space app creation with nix base scripts #1505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Samuka007
wants to merge
16
commits into
master
Choose a base branch
from
build/nix-qemu
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,103
−20
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e1859f7
nix base qemu start script
Samuka007 3bd7dc2
userspace rootfs app creation
Samuka007 50b5258
successfully build ext4 rootfs
Samuka007 889d1b1
Add configurable rootfs and partition types in build script
Samuka007 d8e829b
Update flake.lock and flake.nix for nixpkgs version and enhance rootf…
Samuka007 402109e
Add QEMU firmware package and update run script to use it
Samuka007 ed5521b
fixed nix environment for less frequent source fetching
Samuka007 3d507f2
feat(nix): add gcc for kernel build in
Samuka007 3c0d5e0
refactor: gVisor tests nix build and fakeroot image pack up
Samuka007 60c5e53
feat: boot from ext4, dynamic disk size
Samuka007 02b61b9
feat: use autoPatchHook for syscall tests
Samuka007 7d28785
Add multi-target support and unify diskPath
Samuka007 29172cc
Add Nix-based docs flake and documentation
Samuka007 6cdbb82
Make QEMU GDB stub optional and disable autotest
Samuka007 4cb602b
Refactor syscall test configuration, update gvisor syscall test version
Samuka007 f4b6d08
Refactor: Use correct executable names in flake.nix
Samuka007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| use flake ./tools/nix-dev-shell |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| _build/ | ||
| result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,6 +88,7 @@ | |
| "strikethrough", | ||
| "substitution", | ||
| "tasklist", | ||
| "linkify" | ||
| ] | ||
|
|
||
| # sphinx-multiversion 指定哪个分支为 lastest 版本 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Nix 技巧 | ||
|
|
||
| ## 同一终端内避免反复指定 `nix run .#start-x86_64` | ||
|
|
||
| 需要注意的是,仅推荐重复使用 qemu 启动脚本 `dragonos-run`,因为 rootfs 在 `nix shell` eval 完毕后生成的仅仅是最终 `rootfs.tar` 拷贝到磁盘文件的过程,而 `rootfs.tar` 需要重新调用 nix build/shell/run 命令来生成。你的所有对 nix 的修改都需要通过重新执行 nix 命令来进行 eval 与构建,因此 `nix shell .#rootfs-x86_64` 意义不大。 | ||
|
|
||
| ```shell | ||
| ❯ nix shell .#start-x86_64 .#rootfs-x86_64 | ||
| ❯ which dragonos-rootfs | ||
| /nix/store/rpsb6f76hxzcfblghfgch2jl8413w6m4-dragonos-rootfs/bin/dragonos-rootfs | ||
| ❯ which dragonos-run | ||
| /nix/store/1sdnhsjihj2h3mkdx7x0v8zy9ldfijml-dragonos-run/bin/dragonos-run | ||
| ❯ dragonos-run | ||
| # DragonOS QEMU Start | ||
| ❯ make kernel # 重新构建内核 | ||
| ❯ dragonos-run # 不涉及启动脚本和rootfs的更改,直接qemu启动 | ||
| ``` | ||
|
|
||
| ## 查看可用构建产物 | ||
|
|
||
| ```shell | ||
| ❯ nix flake show | ||
| warning: Git tree '/workspace' is dirty | ||
| git+file:///workspace | ||
| ├───apps | ||
| │ └───x86_64-linux | ||
| │ ├───rootfs-riscv64: app: 构建 riscv64 rootfs 镜像 | ||
| │ ├───rootfs-x86_64: app: 构建 x86_64 rootfs 镜像 | ||
| │ ├───start-riscv64: app: 以 riscv64 启动DragonOS | ||
| │ └───start-x86_64: app: 以 x86_64 启动DragonOS | ||
| └───packages | ||
| └───x86_64-linux | ||
| ├───rootfs-riscv64: package 'build-rootfs-image' | ||
| ├───rootfs-x86_64: package 'build-rootfs-image' | ||
| ├───start-riscv64: package 'run-dragonos' | ||
| └───start-x86_64: package 'run-dragonos' | ||
|
|
||
| user/apps/about ❯ nix flake show | ||
| git+file:///workspace?dir=user/apps/about | ||
| └───packages | ||
| ├───aarch64-darwin | ||
| │ └───default omitted (use '--all-systems' to show) | ||
| ├───aarch64-linux | ||
| │ └───default omitted (use '--all-systems' to show) | ||
| ├───x86_64-darwin | ||
| │ └───default omitted (use '--all-systems' to show) | ||
| └───x86_64-linux | ||
| └───default: package 'about-static-x86_64-unknown-linux-musl-0.1.0' | ||
|
|
||
| tests/syscall/gvisor ❯ nix flake show | ||
| git+file:///workspace?dir=user/apps/tests/syscall/gvisor | ||
| └───packages | ||
| └───x86_64-linux | ||
| └───default: package 'gvisor-tests' | ||
| ``` | ||
|
|
||
| ## 回收 nix 构建历史缓存 | ||
|
|
||
| ```shell | ||
| ❯ nix store gc | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # 贡献文档 | ||
|
|
||
| ## 使用 nix | ||
|
|
||
| ### 实时构建预览文档 | ||
|
|
||
| sphinx-autobuild 作为默认 nix run 目标,写文档只需要 | ||
|
|
||
| ```shell | ||
| cd docs | ||
| nix run | ||
| ``` | ||
|
|
||
| 然后访问 8000 端口即可。 | ||
|
|
||
| ### 构建文档为 drv (sphinx-build) | ||
|
|
||
| ```shell | ||
| cd docs | ||
| nix build | ||
| ``` | ||
|
|
||
| ### 预览构建好的文档 (python http-server) | ||
|
|
||
| ```shell | ||
| cd docs | ||
| nix run .#release | ||
| ``` | ||
|
|
||
| ## 使用 pip Makefile 构建文档 | ||
|
|
||
| TODO |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| { | ||
| description = "Reproducible Sphinx Documentation Build"; | ||
|
|
||
| inputs = { | ||
| nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; | ||
| flake-utils.url = "github:numtide/flake-utils"; | ||
| }; | ||
|
|
||
| outputs = { self, nixpkgs, flake-utils }: | ||
| flake-utils.lib.eachDefaultSystem (system: | ||
| let | ||
| pkgs = nixpkgs.legacyPackages.${system}; | ||
| lib = pkgs.lib; | ||
|
|
||
| # ---------------------------------------------------------------- | ||
| # 1. 定义精确的 Python 环境 | ||
| # ---------------------------------------------------------------- | ||
| # 这里显式列出依赖,确保无论在哪台机器,Sphinx 版本一致 | ||
| pythonEnv = pkgs.python3.withPackages (ps: with ps; [ | ||
| sphinx | ||
| sphinx-multiversion | ||
| sphinx-autobuild | ||
| # 在这里添加你的 theme 或 extension,例如: | ||
| sphinx-rtd-theme | ||
| myst-parser | ||
| sphinxcontrib-mermaid | ||
| linkify-it-py | ||
| ]); | ||
|
|
||
| # ---------------------------------------------------------------- | ||
| # 2. 从 Flake 输入中提取 Git 信息 (Pure 方式) | ||
| # ---------------------------------------------------------------- | ||
| # Nix 在求值时知道当前的 revision,不需要在 build 时运行 git 命令 | ||
| gitHash = if (self ? rev) then self.rev else "dirty-dev"; | ||
| isDirty = if (self ? rev) then "0" else "1"; | ||
|
|
||
| buildDir = "./_build"; | ||
| port = 8000; | ||
|
|
||
| in | ||
| { | ||
| # ---------------------------------------------------------------- | ||
| # Packages: 纯净构建 (nix build) | ||
| # ---------------------------------------------------------------- | ||
| # 这种方式构建的是"当前代码的快照",完全不依赖 .git 目录 | ||
| packages.default = pkgs.stdenv.mkDerivation { | ||
| name = "sphinx-docs"; | ||
| src = ./.; | ||
|
|
||
| buildInputs = [ pythonEnv ]; | ||
|
|
||
| # 将 Nix 提取的 Git 信息注入环境变量 | ||
| # 这完全替代了 Makefile 中 $(shell git rev-parse) 的逻辑 | ||
| env = { | ||
| LANGUAGE = "zh_CN"; | ||
| CURRENT_GIT_COMMIT_HASH = gitHash; | ||
| CURRENT_GIT_COMMIT_DIRTY = isDirty; | ||
| SPHINXBUILD = "sphinx-build"; | ||
| }; | ||
|
|
||
| # 直接定义构建逻辑,不再依赖 Makefile | ||
| buildPhase = '' | ||
| echo "Building documentation for commit: $CURRENT_GIT_COMMIT_HASH" | ||
|
|
||
| # 使用 -W 将警告视为错误,确保构建质量 | ||
| sphinx-build -M html . ${buildDir} \ | ||
| -D language=$LANGUAGE \ | ||
| -w _build/warnings.log | ||
| ''; | ||
|
|
||
| installPhase = '' | ||
| mkdir -p $out | ||
| cp -r ${buildDir}/* $out/ | ||
| ''; | ||
| }; | ||
|
|
||
| # ---------------------------------------------------------------- | ||
| # Apps: 快速运行工具 (nix run) | ||
| # ---------------------------------------------------------------- | ||
| # 提供一个脚本来预览构建结果 | ||
| apps.release = flake-utils.lib.mkApp { | ||
| drv = let targetDir = self.packages.${system}.default; | ||
| in pkgs.writeShellApplication { | ||
| name = "preview-docs"; | ||
| runtimeInputs = [ pythonEnv ]; | ||
| text = '' | ||
| echo "Open at http://localhost:${toString port}/index.html" | ||
| python3 -m http.server --directory "${targetDir}/html" ${toString port} | ||
| ''; | ||
| }; | ||
| }; | ||
| app.develop = flake-utils.lib.mkApp { | ||
| drv = pkgs.writeShellApplication { | ||
| name = "sphinx-autobuild"; | ||
| runtimeInputs = [ pythonEnv ]; | ||
| text = '' | ||
| sphinx-autobuild . ${buildDir} --host 0.0.0.0 --port ${toString port} | ||
| ''; | ||
| }; | ||
| }; | ||
| # 设置默认 run 行为 | ||
| apps.default = self.app.${system}.develop; | ||
|
|
||
| # ---------------------------------------------------------------- | ||
| # DevShell: 开发环境 (nix develop) | ||
| # ---------------------------------------------------------------- | ||
| # 用于开发和需要访问 .git 的操作(如 sphinx-multiversion) | ||
| devShells.default = pkgs.mkShell { | ||
| packages = [ pythonEnv pkgs.git pkgs.gnumake ]; | ||
|
|
||
| shellHook = '' | ||
| export LANGUAGE="zh_CN" | ||
| export SPHINXBUILD="sphinx-build" | ||
|
|
||
| # 在开发环境中,我们可以动态获取 git 状态 | ||
| export CURRENT_GIT_COMMIT_HASH=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown") | ||
|
|
||
| echo "🚀 Sphinx Dev Environment Loaded" | ||
| echo "-----------------------------------" | ||
| echo "Run 'make html' for standard build" | ||
| echo "Run 'make html-multiversion' for versioned build (Requires .git)" | ||
| echo "Run 'nix build' for clean production build" | ||
| ''; | ||
| }; | ||
| } | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # 使用 devcontainer 开发 DragonOS | ||
|
|
||
| 本教程以 VSCode 为例,需要装有 Docker 的 Linux。 | ||
|
|
||
| ## 克隆仓库 | ||
|
|
||
| ```shell | ||
| git clone https://github.com/DragonOS-Community/DragonOS.git | ||
| code DragonOS | ||
| ``` | ||
|
|
||
| ## 进入 devcontainer 环境 | ||
|
|
||
| 在 VSCode 右下角会有弹窗,选择 `Reopen in Container`。如果不可见,请根据下列步骤来进入: | ||
| - 下载 devcontainer 插件 | ||
| - `ctrl+shift+p` 打开 VSCode 命令面板 | ||
| - 输入 `devcontainer` 字样,会有 `Reopen in Container` 的选项,点击即会构建 devcontainer 环境 | ||
|
|
||
| 构建可能需要一些时间,尤其 msr 的插件在网络环境不好的情况下容易安装失败。 | ||
|
|
||
| ## 构建 DragonOS! | ||
|
|
||
| 直接输入 | ||
|
|
||
| ```shell | ||
| make run-nographic | ||
| ``` | ||
|
|
||
| 等待构建,最后会自动进入 DragonOS qemu 环境。 | ||
|
|
||
| 需要退出qemu环境,请输入 `ctrl+a` 然后按 `x`。 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个不应该这样,因为ai翻译的文档很可能会有warning,比如reST的标题下方的
===的长度不够宽之类的。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok这个我调一下。实际上我也不是很清楚现在DragonOS文档的 doc build 和 multiversion doc build 在部署上是怎么实现的,后续需要再补充一下。
此外英文那里 Device 标题被混元翻译为了中文 “设备”,xs