Skip to content

nixos/device-tree: support out-of-tree device#403746

Draft
qbisi wants to merge 5 commits intoNixOS:staging-nextfrom
qbisi:dts
Draft

nixos/device-tree: support out-of-tree device#403746
qbisi wants to merge 5 commits intoNixOS:staging-nextfrom
qbisi:dts

Conversation

@qbisi
Copy link
Contributor

@qbisi qbisi commented May 2, 2025

This pr add support for thouse out-of-tree boards based on expose compileDts.

With some modification of kernel^dev, we can compile the deviceTree of a custom board without patching kernel source.
A test nixosTest.device-tree.{systemd-boot,grub} is added to valid this pr.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: kernel The Linux kernel 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: hardware Drivers, Firmware and Kernels 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. labels May 2, 2025
@qbisi qbisi force-pushed the dts branch 4 times, most recently from e1a9097 to 464ff72 Compare May 3, 2025 11:48
@qbisi qbisi changed the base branch from master to staging May 4, 2025 14:06
@qbisi qbisi requested a review from Mic92 May 5, 2025 14:48
@github-actions github-actions bot added 6.topic: python Python is a high-level, general-purpose programming language. 6.topic: haskell General-purpose, statically typed, purely functional programming language 6.topic: ocaml OCaml is a general-purpose, high-level, multi-paradigm programming language. 6.topic: coq A formal proof management system 6.topic: games Gaming on NixOS 8.has: maintainer-list (update) This PR changes `maintainers/maintainer-list.nix` labels May 8, 2025
@nix-owners
Copy link

nix-owners bot commented May 8, 2025

The PR's base branch is set to staging, but 163 commits from the master branch are included. Make sure you know the right base branch for your changes, then:

  • If the changes should go to the master branch, change the base branch to master
  • If the changes should go to the staging branch, rebase your PR onto the merge base with the staging branch:
    # git rebase --onto $(git merge-base upstream/staging HEAD) $(git merge-base upstream/master HEAD)
    git rebase --onto 2cd2decd3aebe7bff63c51b978c27a8e91bbab3d cf62b39840dee1ff69de1cfc3561dbcc32d87f8d
    git push --force-with-lease

@github-actions github-actions bot removed the 6.topic: python Python is a high-level, general-purpose programming language. label May 8, 2025
@qbisi qbisi force-pushed the dts branch 3 times, most recently from 9e97219 to 00e3bb2 Compare June 13, 2025 23:37
@qbisi
Copy link
Contributor Author

qbisi commented Jun 14, 2025

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 403746 --package nixosTests.device-tree.systemd-boot --package nixosTests.device-tree.grub


aarch64-linux

✅ 2 tests built:
  • nixosTests.device-tree.grub
  • nixosTests.device-tree.systemd-boot

@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 2501-5000 This PR causes many rebuilds on Linux and should target the staging branches. and removed 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Jul 4, 2025
@qbisi qbisi force-pushed the dts branch 2 times, most recently from 191ee35 to 7db3f76 Compare July 11, 2025 10:58
@qbisi
Copy link
Contributor Author

qbisi commented Jul 11, 2025

cc @K900 may i have you attention on this pr.
Keeping *.dtsi file adds up 26M to linux^dev (from 779M to 805M). However the benefical is obviouse for supporting out-of-tree boards. In fact the device-tree module is making use of those dtc include header files under linux^dev.

dtboFile =
let
includePaths = [
"${lib.getDev cfg.kernelPackage}/lib/modules/${cfg.kernelPackage.modDirVersion}/source/scripts/dtc/include-prefixes"
] ++ cfg.dtboBuildExtraIncludePaths;
extraPreprocessorFlags = cfg.dtboBuildExtraPreprocessorFlags;
in
if o.dtboFile == null then
let
dtsFile = if o.dtsFile == null then (pkgs.writeText "dts" o.dtsText) else o.dtsFile;
in
pkgs.deviceTree.compileDTS {
name = "${o.name}-dtbo";
inherit includePaths extraPreprocessorFlags dtsFile;
}
else
o.dtboFile;

It's also reasonable to keep those *.dtsi file.

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 26, 2025
@qbisi qbisi changed the base branch from master to staging-next July 27, 2025 18:10
@nixpkgs-ci nixpkgs-ci bot closed this Jul 27, 2025
@nixpkgs-ci nixpkgs-ci bot reopened this Jul 27, 2025
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jul 27, 2025
@qbisi qbisi mentioned this pull request Jul 31, 2025
13 tasks
'';
};

loadDeviceTree = mkOption {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest instead renaming the existing boot.loader.systemd-boot.installDeviceTree to boot.loader.efi.installDeviceTree and reusing that here (as done in the first commit of #439700).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, this option is more than a expilict declaration of using deviceTree command in grub.cfg.
You see i did not use the option name installDeviceTree as systemd-boot do.
There is case we put /boot in the same disk partition of /nix/store, so there's no need for grub to copy kernel/initrd/dtb to EFI partition.

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Oct 26, 2025
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Nov 6, 2025
@qbisi qbisi marked this pull request as draft December 24, 2025 19:44
@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Jan 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: hardware Drivers, Firmware and Kernels 6.topic: kernel The Linux kernel 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 2501-5000 This PR causes many rebuilds on Linux and should target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants