Linux kernel: Difference between revisions

imported>Artturin
m fix formatting
imported>Mic92
replace some maybe's with things you always will have to do.
Line 244: Line 244:


   sourceRoot = "source/linux/v4l2loopback";
   sourceRoot = "source/linux/v4l2loopback";
   hardeningDisable = [ "pic" ];                                            # 1
   hardeningDisable = [ "pic" "format" ];                                            # 1
   nativeBuildInputs = kernel.moduleBuildDependencies;                      # 2
   nativeBuildInputs = kernel.moduleBuildDependencies;                      # 2


Line 263: Line 263:
</syntaxHighlight>
</syntaxHighlight>


1. for kernel modules it is normally necessary to disable <code>pic</code> and sometimes <code>format</code> hardening
1. For kernel modules it is necessary to disable <code>pic</code> in compiler hardenings as the kernel need different compiler flags.


2. most of the time you will need to set the moduleBuildDependencies to build a module
2. In addition to other dependencies in <code>nativeBuildInputs</code> you should include <code>kernel.moduleBuildDependencies</code> as this propagates additional libraries required during the build.


3. this kernel module requires the release to be set, it can be found in <code>${kernel.modDirVersion}</code>
3. Some kernel modules try guess the kernel version based on the running kernel via <code>uname</code>. Usually they save this information in a makefile variable like <code>KERNELRELEASE</code>. If this is the case you can override the kernel version via <code>makeFlags</code>. The right kernel version string can be found in <code>kernel.modDirVersion</code>.


4. You need to find out how the build environment (Makefile in general) finds the kernel tree. This is sometimes <code>KDIR</code> and sometimes <code>KERNEL_DIR</code>.
4. You need to find out how the build environment (Makefile in general) finds the kernel tree. This is sometimes <code>KDIR</code> and sometimes <code>KERNEL_DIR</code>.


5. When you get the error <code>mkdir: cannot create directory '/lib': Permission denied</code> then it may be necessary to set <code>INSTALL_MOD_PATH</code>. This can be done by setting via <code>makeFlags</code> or by setting it directly in the derivation.
5. Lastly it is required to give the kernel build system the right location where to install the kernel module. This is done by setting <code>INSTALL_MOD_PATH</code> to <code>$out</code> Otherwise an error like <code>mkdir: cannot create directory '/lib': Permission denied</code> is generated.


== See also ==
== See also ==