···66 };
6768 filterDTBs = src: if cfg.filter == null
69- then "${src}/dtbs"
70 else
71 pkgs.runCommand "dtbs-filtered" {} ''
72 mkdir -p $out
73- cd ${src}/dtbs
74 find . -type f -name '${cfg.filter}' -print0 \
75 | xargs -0 cp -v --no-preserve=mode --target-directory $out --parents
76 '';
7778- filteredDTBs = filterDTBs cfg.kernelPackage;
79-80- # Compile single Device Tree overlay source
81- # file (.dts) into its compiled variant (.dtbo)
82- compileDTS = name: f: pkgs.callPackage({ stdenv, dtc }: stdenv.mkDerivation {
83- name = "${name}-dtbo";
84-85- nativeBuildInputs = [ dtc ];
86-87- buildCommand = ''
88- $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} | \
89- dtc -I dts -O dtb -@ -o $out
90- '';
91- }) {};
9293 # Fill in `dtboFile` for each overlay if not set already.
94 # Existence of one of these is guarded by assertion below
95 withDTBOs = xs: flip map xs (o: o // { dtboFile =
000096 if o.dtboFile == null then
97- if o.dtsFile != null then compileDTS o.name o.dtsFile
98- else compileDTS o.name (pkgs.writeText "dts" o.dtsText)
0000099 else o.dtboFile; } );
100101in
···121 example = literalExpression "pkgs.linux_latest";
122 type = types.path;
123 description = lib.mdDoc ''
124- Kernel package containing the base device-tree (.dtb) to boot. Uses
00000000000000000000000000000000125 device trees bundled with the Linux kernel by default.
126 '';
127 };
···66 };
6768 filterDTBs = src: if cfg.filter == null
69+ then src
70 else
71 pkgs.runCommand "dtbs-filtered" {} ''
72 mkdir -p $out
73+ cd ${src}
74 find . -type f -name '${cfg.filter}' -print0 \
75 | xargs -0 cp -v --no-preserve=mode --target-directory $out --parents
76 '';
7778+ filteredDTBs = filterDTBs cfg.dtbSource;
00000000000007980 # Fill in `dtboFile` for each overlay if not set already.
81 # Existence of one of these is guarded by assertion below
82 withDTBOs = xs: flip map xs (o: o // { dtboFile =
83+ let
84+ includePaths = ["${getDev cfg.kernelPackage}/lib/modules/${cfg.kernelPackage.modDirVersion}/source/scripts/dtc/include-prefixes"] ++ cfg.dtboBuildExtraIncludePaths;
85+ extraPreprocessorFlags = cfg.dtboBuildExtraPreprocessorFlags;
86+ in
87 if o.dtboFile == null then
88+ let
89+ dtsFile = if o.dtsFile == null then (pkgs.writeText "dts" o.dtsText) else o.dtsFile;
90+ in
91+ pkgs.deviceTree.compileDTS {
92+ name = "${o.name}-dtbo";
93+ inherit includePaths extraPreprocessorFlags dtsFile;
94+ }
95 else o.dtboFile; } );
9697in
···117 example = literalExpression "pkgs.linux_latest";
118 type = types.path;
119 description = lib.mdDoc ''
120+ Kernel package where device tree include directory is from. Also used as default source of dtb package to apply overlays to
121+ '';
122+ };
123+124+ dtboBuildExtraPreprocessorFlags = mkOption {
125+ default = [];
126+ example = literalExpression "[ \"-DMY_DTB_DEFINE\" ]";
127+ type = types.listOf types.str;
128+ description = lib.mdDoc ''
129+ Additional flags to pass to the preprocessor during dtbo compilations
130+ '';
131+ };
132+133+ dtboBuildExtraIncludePaths = mkOption {
134+ default = [];
135+ example = literalExpression ''
136+ [
137+ ./my_custom_include_dir_1
138+ ./custom_include_dir_2
139+ ]
140+ '';
141+ type = types.listOf types.path;
142+ description = lib.mdDoc ''
143+ Additional include paths that will be passed to the preprocessor when creating the final .dts to compile into .dtbo
144+ '';
145+ };
146+147+ dtbSource = mkOption {
148+ default = "${cfg.kernelPackage}/dtbs";
149+ defaultText = literalExpression "\${cfg.kernelPackage}/dtbs";
150+ type = types.path;
151+ description = lib.mdDoc ''
152+ Path to dtb directory that overlays and other processing will be applied to. Uses
153 device trees bundled with the Linux kernel by default.
154 '';
155 };