:::{note}
**AI Translation Notice**

This document was automatically translated by `hunyuan-turbos-latest` model, for reference only.

- Source document: dev-skills/nix-skills.md

- Translation time: 2025-12-26 10:51:55

- Translation model: `hunyuan-turbos-latest`

Please report issues via [Community Channel](https://github.com/DragonOS-Community/DragonOS/issues)

:::

# Nix Tips

## Avoid Repeatedly Specifying `nix run .#start-x86_64` in the Same Terminal

Note that it is only recommended to reuse the qemu startup script `dragonos-run`, because after the rootfs is generated by `nix shell` eval, it is merely the process of copying the final `rootfs.tar` to a disk file. The `rootfs.tar` needs to be regenerated by re-invoking the nix build/shell/run commands. All your modifications to nix require re-evaluation and building through re-executing nix commands, so `nix shell .#rootfs-x86_64` is not very meaningful.

```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启动
```

## View Available Build Artifacts

```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'
```

## Recycle Nix Build History Cache

```shell
❯ nix store gc
```
