patches and low-level development discussion
 help / color / mirror / code / Atom feed
From: Alyssa Ross <alyssa.ross@unikie.com>
To: Ivan Nikolaenko <ivan.nikolaenko@unikie.com>
Cc: devel@spectrum-os.org
Subject: Re: Overriding Linux kernel in host/rootfs/default.nix
Date: Wed, 21 Dec 2022 11:32:09 +0000	[thread overview]
Message-ID: <20221221113209.gajce2mmpecco7u6@x220> (raw)
In-Reply-To: <4d41315a-05d2-747c-3708-37f7c8c34684@unikie.com>

[-- Attachment #1: Type: text/plain, Size: 3350 bytes --]

On Wed, Dec 21, 2022 at 01:18:36PM +0200, Ivan Nikolaenko wrote:
> Hello everyone.
>
> Recently I faced an issue with overriding Linux kernel in rootfs recipe:
>
> Rootfs has an attribute kernel in the `let ... in` section, which is used
> for
> setting up correct paths to kernel modules in rootfs derivation. But this
> attribute is also used by the derivation `packagesSysroot` which is used
> by the derivation `packagesTar`, whiсh, in its turn, used by rootfs
> derivation.
>
> All that derivations introduced in the scope of rootfs derivation (the same
> `let ... in` section) and are anonymous.
> What happens when I override kernel attribute of the rootfs derivation:
> 1. Nix evaluates original host/rootfs/default.nix  file and replaces all
> ${kernel} occurences with the actual value of kernel attribute (which is
> linux_latest  at this moment).
> 2. Nix sets linux_latest  as the input for rootfs and packagesSysroot
> derivations.
> 3. Nix evaluates overlay with kernel override and overrides (in fact,
> introduces new) kernel attribute.
> 4. Nothing happens after that.
> Now we have:
> - `kernel` attribute of rootfs derivation pointing to the imx8 kernel.
> - `MODULES_ALIAS` and `MODULES_ORDER` variables of rootfs derivation are
> pointing to linux_latest modules.
> The root of the issue - line `ln -s ${kernel}/lib/modules
> ${firmware}/lib/firmware $out/lib`
> from `packagesSysroot` derivation build command, which creates the /lib link
> in the rootfs
> pointing to linux_latest modules. As I found, kernel attribure is not even
> passed as an attribute to
> the rootfs derivation file. But it is possible to override MODULES_ALIAS and
> MODULES_ORDER with correct kernel modules path instead.
>
> This also touches initramfs
> The possible solution is just to override linux_latest, but in this case all
> VMs will use host kernel version, and we need to avoid this.
>
> I would propose something like this for rootfs' default.nix, because this
> approach solves all kernel issues in an easy and clear way:
>
> diff --git a/host/rootfs/default.nix b/host/rootfs/default.nix
> index ad6ea1f..7bf16d2 100644
> --- a/host/rootfs/default.nix
> +++ b/host/rootfs/default.nix
> @@ -7,7 +7,7 @@ pkgs.pkgsStatic.callPackage (
>
>  { lib, stdenvNoCC, nixos, runCommand, writeReferencesToFile, s6-rc,
> tar2ext4
>  , busybox, cloud-hypervisor, cryptsetup, execline, jq, kmod
> -, mdevd, s6, s6-linux-init, socat, util-linuxMinimal, xorg
> +, mdevd, s6, s6-linux-init, socat, util-linuxMinimal, xorg, kernel ?
> linux_latest
>  }:
>
>  let
> @@ -73,8 +73,6 @@ let
>      imports = [ (modulesPath + "/profiles/all-hardware.nix") ];
>    });
>
> -  kernel = pkgs.linux_latest;
> -
>    appvm = import ../../img/app {
>      inherit config;
>      inherit (foot) terminfo;
>
> I played a bit with this, and seems that it worked.
>
> Thanks.

Seems reasonable!  Happy to apply if you resend with a Signed-off-by.

Although I think it needs to still be pkgs.linux_latest, as
linux_latest isn't defined.  (We don't want to take it as a callPackage
input because we don't need pkgsStatic.linux_latest.)  And it might be a
good idea to put the "kernel" option on a new line, so that overridable
options are different from package inputs.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      reply	other threads:[~2022-12-21 11:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-21 11:18 Overriding Linux kernel in host/rootfs/default.nix Ivan Nikolaenko
2022-12-21 11:32 ` Alyssa Ross [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221221113209.gajce2mmpecco7u6@x220 \
    --to=alyssa.ross@unikie.com \
    --cc=devel@spectrum-os.org \
    --cc=ivan.nikolaenko@unikie.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).