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
nixos/device-tree: Add more options to the module #251898
nixos/device-tree: Add more options to the module #251898
Conversation
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-ready-for-review/3032/2676 |
Could you share an example on how to use I have {
hardware.deviceTree = {
dtbSource = ./dtbs;
};
} but then |
Thank you for testing! The dtbSource actually points to a directory that should contain dtb not dts since it's used as a base to apply dtb overlays on. So to test it, the directory should contain |
D'oh, thanks. It's been a while since I looked at my device tree configs.
|
Thank you for the detailed feedbacks! I added a |
8997e7d
to
5063fef
Compare
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.
I think there are two ways you could proceed with this PR:
-
The changes in the first four commits (through 88f3043) look good to me. You should just squash them down to 1-2 commits to make it ready to merge. Then, you could return to the
dtsSource
changes in a second PR. -
You could keep going with the
dtsSource
changes, making the options more composable as discussed in my other comments.
I encourage you to go with option (1) so that it's easier to merge this change ahead of 23.11. If you do, feel free to ping me on a second PR for a review.
# Compile single Device Tree overlay source | ||
# file (.dts) into its compiled variant (.dtbo) | ||
compileDTS = name: f: pkgs.callPackage({ stdenv, dtc }: stdenv.mkDerivation { | ||
name = "${name}-dtbo"; | ||
|
||
nativeBuildInputs = [ dtc ]; | ||
|
||
buildCommand = '' | ||
$CC -E -nostdinc -I${getDev cfg.kernelPackage}/lib/modules/${cfg.kernelPackage.modDirVersion}/source/scripts/dtc/include-prefixes -undef -D__DTS__ -x assembler-with-cpp ${f} | \ | ||
dtc -I dts -O dtb -@ -o $out | ||
''; | ||
}) {}; | ||
|
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.
This first commit (temporarily) breaks things because compileDTS
is no longer in scope when it's used in withDTBOs
. It also doesn't update the call to provide the right name
. It looks like both of these are present in the next commit.
Generally speaking, splitting up commits like this is good for readability, but you should make sure that each commit can be taken independently. The tree at each commit should work without errors, pass tests, etc. You can use git rebase -i
and similar commands to edit your earlier commits.
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.
Gotcha, I will be more mindful in the future with my git commits.
@@ -142,7 +250,7 @@ in | |||
default = null; | |||
example = "*rpi*.dtb"; | |||
description = lib.mdDoc '' | |||
Only include .dtb files matching glob expression. | |||
Only include .dtb files matching glob expression. Only used with {option}`hardware.deviceTree.dtbSource` option |
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.
Is this restriction needed?
I see that it won't be useful to configure a filter
when using dtsSource
, since only one dtb
will be produced anyway. Here are some reasons to make filter
work with it anyway:
- A future change could allow multiple
dtb
to be built from sources. - Conditional application makes options more confusing.
- The default filter is
null
anyway.
type = types.path; | ||
description = lib.mdDoc '' | ||
Path to dtb directory that overlays and other processing will be applied to. Uses | ||
device trees bundled with the Linux kernel by default. Will be ignored if {option}`hardware.deviceTree.dtsSource` is also specified. |
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.
Config options should compose rather than conflict with each other. It should be possible for a user to combine all of these options in a useful way.
For example, suppose I want to produce an image supporting four boards:
- Board 1 has a device tree in the Linux kernel. I want to use the DTB from the compiled
kernelPackage
. - Board 2 needs a compiled
dtb
from the vendor. I want to include that withdtbSource
. - Board 3 has my own
dts
that I need to build. I would usedtsSource
for this. - Board 4 also comes from my own
dts
. I want to specifydtsSource
multiple times. - Then, I might want to apply a
filter
on top to build images tailored to each board.
As a user, I would expect this to "just work". Each option should build upon others. Something like this:
- multiple
dtsSource
-> customdtbs
tree - custom
dtbs
tree + user-supplieddtbSource
+${kernelPackage}/dtbs
-> combineddtb
tree - combined
dtb
tree +filter
-> filtereddtb
tree - filtered
dtb
tree +overlays
-> finaldtb
tree
All of these configs could have sensible defaults that can be overridden. But that override should be an explicit choice by the user and preferably not automatic behavior behind the scenes, even if it is documented.
For example, the default value of dtbSources
could include both kernelPackages
dtbs and dtbs compiled from dtsSource
. If a user doesn't want to include dtbs from kernelPackages
, they could set kernelPackages = null
.
5063fef
to
88f3043
Compare
88f3043
to
8da7715
Compare
Gotcha! Thank you again for the detailed feedbacks! I have squashed the first 4 commits and will make another PR to wrap up the other feature. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/prs-already-reviewed/2617/1117 |
@Majiir do you know when we can merge this in? Do I need to do anything else to move this along? |
It is ready to merge in my opinion, but I don't have merge access. We will need to wait for someone in the committers group. |
I'm getting the following error, and I guess it has to do with this PR..
any pointers at where to look? |
Can you validate if |
yes it can:
|
I'm not sure if its relevant, but I am cross compiling from an x86_64-linux to an aarch64-linux system. The |
hi, sorry to hear that you are running into issues. Is it possible that an older |
No, the
The and the heading starts with:
so I guess the problem is the cooperation between the |
due to NixOS/nixpkgs#251898 the compileDTS function has been moved to `device-tree` nixos-hardware has an own overlay for the raspberry-pi which needs the `compileDTS` function now, too. This commit adds it. Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
* fix compileDTS overlay due to NixOS/nixpkgs#251898 the compileDTS function has been moved to `device-tree` nixos-hardware has an own overlay for the raspberry-pi which needs the `compileDTS` function now, too. This commit adds it. Signed-off-by: Florian Brandes <florian.brandes@posteo.de> * apply review comments Co-authored-by: Majiir Paktu <majiir@nabaal.net> Signed-off-by: Florian Brandes <florian.brandes@posteo.de> --------- Signed-off-by: Florian Brandes <florian.brandes@posteo.de> Co-authored-by: Majiir Paktu <majiir@nabaal.net>
Things done
Improve devicetree module by:
Exposing compileDTS to make it easier for user to compile their own custom dts
Expose more customization options for compiling dtbo in hardware.devicetree
Allow custom dtb source in hardware.devicetree so that users don't have to use dtb from kernel but still get other benefits of the module like overlay support
Built on platform(s)
For non-Linux: Is
sandbox = true
set innix.conf
? (See Nix manual)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 usageTested basic functionality of all binary files (usually in
./result/bin/
)23.11 Release Notes (or backporting 23.05 Release notes)
Fits CONTRIBUTING.md.
Tested by building with the various new options on the closure
nixos/modules/installer/sd-card/sd-image-aarch64.nix
closure. The dtb changes are observed to take effects