From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id D46A2C2C3; Wed, 21 Dec 2022 11:32:15 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id CD9DAC309; Wed, 21 Dec 2022 11:32:12 +0000 (UTC) Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by atuin.qyliss.net (Postfix) with ESMTPS id 2C13AC307 for ; Wed, 21 Dec 2022 11:32:11 +0000 (UTC) Received: by mail-ed1-x533.google.com with SMTP id b69so21556976edf.6 for ; Wed, 21 Dec 2022 03:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unikie.com; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=kzN83IjYLf0vCgRSIqgWJOV5PVLJ9oRYxX0lz9SRnS4=; b=I/EovdyhDL7gUu+cOY165YfkDUfvllYFGmsNZPNpyIGBfkzlZn4u0U0WbVSsYWvTk7 D/AOZgC0/Sc1++J+dSLrg+1bbmOQC3iHFnscNUBli2rYAF5PH2lQO2kziykPYYc8UIrB OSYVxLqWKo8zsu5dHh5sSS6OMgKxBg2Q4jKn4k6xcwdvX0hFEq3AT2hVkv1ff+yX6Wwl rsD6P8vpjpIcRGbvGpzsNaBFxta5JIEAAK7JTOGoLUr2ya8QV4L/vZ9Vaf5AIKMRTM0E MKX6ybw4fwTHmu6M/WTFjOpGjxDilnan7dOrcqhi/KS+tuJPQ3aqteOgKRFHSEhjI4oc gB/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kzN83IjYLf0vCgRSIqgWJOV5PVLJ9oRYxX0lz9SRnS4=; b=AMRJhyyiUwucet/viD1k4+BvftQl8OSJgTL/U3sa6QxA+DjccORmIlr+LqQufxWbci Gax6xLKKPyw68wcBh23LjyHcWafcY/fOr1v0WF5LuKqkTI6Qq1fnDvJN31nl2aHpZSW5 xrzpScKoWj4VqGkstkK5lY58SBkuaOfneQqR9O0yCExftKJBNeNrDd2qH0D4ptcNsrQ6 f0/UumhVhReQa6kzA/hNoD9RM8ljQt8BuHxSALA84dlFVjfmwvOPqA3FrX3cIzGIQgfu AB00s0I0fNlWNgecYKuaf6c8BcHg9QbWiSWiJDg+jsbw3yWL0SnoRIRmgP5duHTLV8tt qz2w== X-Gm-Message-State: AFqh2krlCePhzk3DJvXlijNaeCQc6n9Zj6FtswqhQTJY/C/P3LfwLxmM Pxa023S1eD3Eusq6K0AIKGMAUhU62ZJt3Kk+ X-Google-Smtp-Source: AMrXdXtobuJsPAG/T8yglLriC7Rxy2WlPEfhks8bKjCp31iNiz1L/Tv5WmaczvUen7KWfxbeD92gXA== X-Received: by 2002:a05:6402:2a04:b0:47a:f54c:1ba4 with SMTP id ey4-20020a0564022a0400b0047af54c1ba4mr1320617edb.25.1671622330433; Wed, 21 Dec 2022 03:32:10 -0800 (PST) Received: from x220.qyliss.net (p200300ed671036010000000000000006.dip0.t-ipconnect.de. [2003:ed:6710:3601::6]) by smtp.gmail.com with ESMTPSA id co18-20020a0564020c1200b004611c230bd0sm6986460edb.37.2022.12.21.03.32.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Dec 2022 03:32:10 -0800 (PST) Received: by x220.qyliss.net (Postfix, from userid 1000) id 8C5052D2; Wed, 21 Dec 2022 11:32:09 +0000 (UTC) Date: Wed, 21 Dec 2022 11:32:09 +0000 From: Alyssa Ross To: Ivan Nikolaenko Subject: Re: Overriding Linux kernel in host/rootfs/default.nix Message-ID: <20221221113209.gajce2mmpecco7u6@x220> References: <4d41315a-05d2-747c-3708-37f7c8c34684@unikie.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="pu76owrkibisxwwl" Content-Disposition: inline In-Reply-To: <4d41315a-05d2-747c-3708-37f7c8c34684@unikie.com> Message-ID-Hash: HZPMIVCDKMCIUBPSP5NFY3N6PXZ53LGZ X-Message-ID-Hash: HZPMIVCDKMCIUBPSP5NFY3N6PXZ53LGZ X-MailFrom: alyssa.ross@unikie.com X-Mailman-Rule-Hits: header-match-devel.spectrum-os.org-0 X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1 CC: devel@spectrum-os.org X-Mailman-Version: 3.3.5 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --pu76owrkibisxwwl Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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=D1=81h, in its turn, used by rootfs > derivation. > > All that derivations introduced in the scope of rootfs derivation (the sa= me > `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=C2=A0 file and replaces= all > ${kernel} occurences with the actual value of kernel attribute (which is > linux_latest=C2=A0 at this moment). > 2. Nix sets linux_latest=C2=A0 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 l= ink > 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 ( > > =C2=A0{ lib, stdenvNoCC, nixos, runCommand, writeReferencesToFile, s6-rc, > tar2ext4 > =C2=A0, 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 > =C2=A0}: > > =C2=A0let > @@ -73,8 +73,6 @@ let > =C2=A0=C2=A0=C2=A0=C2=A0 imports =3D [ (modulesPath + "/profiles/all-hard= ware.nix") ]; > =C2=A0=C2=A0 }); > > -=C2=A0 kernel =3D pkgs.linux_latest; > - > =C2=A0=C2=A0 appvm =3D import ../../img/app { > =C2=A0=C2=A0=C2=A0=C2=A0 inherit config; > =C2=A0=C2=A0=C2=A0=C2=A0 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. --pu76owrkibisxwwl Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEH9wgcxqlHM/ARR3h+dvtSFmyccAFAmOi7rcACgkQ+dvtSFmy ccDsyg/9GePvmAeQ6yJkfpqYfqJ6juMEwq8FZEWPYhAsVFOcZ8DRRT/PXW41DJsz TM8XKhSexQatYb2DJ/cjaOUhyRzypwvpK37zyp5GMlR2m/Zd2fn+/6D65hx0o9ba bUMH3jHPFrA+rNbCEnqMUAjbYW1G+WDk4rZKds3X4coM1PvoWORUCY6VU3yKeMcV 4q5TV0t0Mbb4IcrM9CBdqCCjHQ1VRyQ3rglbM4CRkgXWeyA/eDflB+sAN6W2TA3E HnZwTRzYFagYccZ25dcSF9mTeZD6kwf/RB7uBpCHz04+WycuyZ+5ZulbaIiatdVT cLl3jM7T3+xX8HfhauKPHwtevQ3zRdkUHprCH05Oy2eSS9e/UwLLL+fkZYrjWFK4 EkDI+VcvLtx7FS7m8cbhmDTY8V6MkukngOcUh3j+CU0NXjP8mqaX61YV7+MPUbEQ 83cH/5cuItjHpCFAemfp30/Z9CvZCCupAImGNlnabmbERsIBkzZjzXboCDaEXkZr EZ4G6L5MhkTgKxH4if/M/LX1FPK8LwoXZtIO6iTS115f1vs1gGyOh2kxwow5JE3N fukcHWfl0bqgXP6iiHi0dIYd73/rBLzjjXbdjLBfrlEOlU1yOn5AwcNyTKacO8Oe xyj0ZmMgt5LrHAqFIZEGDTugQbXAVWWcdqhLvC4eGyPKl6GFbQE= =n5tJ -----END PGP SIGNATURE----- --pu76owrkibisxwwl--