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 C9273C165; Wed, 21 Dec 2022 11:18:52 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 496) id CC143C156; Wed, 21 Dec 2022 11:18:49 +0000 (UTC) Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by atuin.qyliss.net (Postfix) with ESMTPS id 1E7A1C0D7 for ; Wed, 21 Dec 2022 11:18:45 +0000 (UTC) Received: by mail-lj1-x233.google.com with SMTP id b9so15278302ljr.5 for ; Wed, 21 Dec 2022 03:18:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unikie.com; s=google; h=content-transfer-encoding:subject:from:content-language:to :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=GLwokHGYmBe5jpFDCugYQlMA885itS0ReS02srh7uHg=; b=CVfXOl8ucdUn+/24ubSl0AZonkDztgxuVy6J2cDHQbZcjkXdtY1iDfSIyJ8o2W9EWH sigjIXPBQScly3zJaZaf30btxgpkov7Bs0iX0pzAFhZXyXqDmExXyk3Rl4G7Z/O2ekpq A6iDL9n0wRULs/nDSQo/ck6p39fNVvA2Gf1gXSWyopOGSCKPvRjcTEfFSsno65Dp324e pXZ91FBzLE41kk5TuG4whbhVlGnxK3Ps/JIuTQURcJ6zotA32L4l06Iu6buffDorQaX4 eWcflj70as9lDANUovFcKq21HB5MmyVAZWLjDNc8W+Tu6THv9/rAFVOIfjBWNndeJfbk 63ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:subject:from:content-language:to :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=GLwokHGYmBe5jpFDCugYQlMA885itS0ReS02srh7uHg=; b=UEWPCsZcio2v1IToyogdxuXB5TJnY+6VVVodc6dlg/vIaEm0qKnXEDZYOGtC/Utr3F VE2sCWz0SIOIT6jxHorVMQniDSCFCzaJm7fVSq10Im7kye1mJZ1ebQNWTyqW/nnN8KC/ CSby1tCZzQjOsVLwo177t7bsXcCpEfgeMTOKdUnaf8t63TP5Pl2aqbAhAmpwf2HAqwjj Zn3xgYfW9wVa2PR2dR0gmHrBD5XoeUwx9sxdvXh+7fC/+RyKbdCtXI0+AWuY2lG17tZg Os7xkpDwq4OSrbgUQtulZ8K1prby+fV6NXaRE6ABd9K5ozaRD0+pIxrNLo8OaVizSjDe +KIA== X-Gm-Message-State: AFqh2kq2nQZOfqodTFnte73D+1G3QiFJoQKqyXv1golTsaD3IK3iSJe8 NdBhw3TJTPapnyXfDTlVsdf/JjNjW/YMj5dO X-Google-Smtp-Source: AMrXdXvSgoha0aDcuMQLuZmXdGabSykRM0sF5AFMjJA2rJWx0QmElYDorWxdBHefQcCrfVpYb29nlA== X-Received: by 2002:a2e:720f:0:b0:27a:991:4d11 with SMTP id n15-20020a2e720f000000b0027a09914d11mr383046ljc.30.1671621517256; Wed, 21 Dec 2022 03:18:37 -0800 (PST) Received: from [172.18.8.48] ([109.204.204.138]) by smtp.gmail.com with ESMTPSA id u24-20020a2e9b18000000b00279ff5d5e10sm1284677lji.38.2022.12.21.03.18.36 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Dec 2022 03:18:36 -0800 (PST) Message-ID: <4d41315a-05d2-747c-3708-37f7c8c34684@unikie.com> Date: Wed, 21 Dec 2022 13:18:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 To: devel@spectrum-os.org Content-Language: en-US From: Ivan Nikolaenko Subject: Overriding Linux kernel in host/rootfs/default.nix Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Message-ID-Hash: HNN6BDRHDT5G545DK2IEWO3PRWTZODPB X-Message-ID-Hash: HNN6BDRHDT5G545DK2IEWO3PRWTZODPB X-MailFrom: ivan.nikolaenko@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 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: 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.