Jump to content

Linux kernel: Difference between revisions

add cross-compiling + compiling with clang
imported>Asymmetric
(add pinning section)
imported>Mic92
(add cross-compiling + compiling with clang)
Line 151: Line 151:


If the source was unpacked and an initial config exists, you can run <code>make xconfig KCONFIG_CONFIG=build/.config</code>
If the source was unpacked and an initial config exists, you can run <code>make xconfig KCONFIG_CONFIG=build/.config</code>


== Requesting a change in the default nixos kernel configuration ==
== Requesting a change in the default nixos kernel configuration ==
Line 308: Line 307:
</syntaxHighlight>
</syntaxHighlight>


=== Cross-compiling Linux from source ===
Save the following as <code>shell.nix</code> for your nix-shell:
<syntaxHighlight lang=nix>
{ pkgs ? import <nixpkgs> {} }:
let
  # more platforms are defined here: https://github.com/NixOS/nixpkgs/blob/master/lib/systems/examples.nix
  aarch64 = pkgs.pkgsCross.aarch64-multiplatform;
in
aarch64.linux.overrideAttrs (old: {
  # the override is optional if you need for example more build dependencies
  nativeBuildInputs = old.nativeBuildInputs ++ [ pkgs.gllvm ];
}
</syntaxHighlight>
Than you can run the following commands (in the nix-shell <code>$makeFlags</code> will contain
the necessary cross-compiling arguments)
<syntaxHightlight lang=console>
$ nix-shell
# to configure
nix-shell> make $makeFlags defconfig -j $(nproc)
# to build
nix-shelll> make $makeFlags -j $(nproc)
</syntaxHightlight>
=== Compiling Linux with clang ===
Save this as <code>shell.nix</code>
<syntaxHighlight lang=nix>
{ pkgs ? import <nixpkgs> {} }:
pkgs.linux.override {
  # needs to be clang11Stdenv or newer
  stdenv = clang11Stdenv;
}
</syntaxHighlight>
Than you can use:
<syntaxHightlight lang=console>
$ nix-shell
# to configure
nix-shell> make $makeFlags defconfig -j $(nproc)
# to build
nix-shelll> make $makeFlags -j $(nproc)
</syntaxHightlight>


=== Overriding kernel packages ===
=== Overriding kernel packages ===
Anonymous user