Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

broken "kernel.features" in linuxManualConfig #216529

Open
sss123next opened this issue Feb 15, 2023 · 11 comments
Open

broken "kernel.features" in linuxManualConfig #216529

sss123next opened this issue Feb 15, 2023 · 11 comments

Comments

@sss123next
Copy link

Describe the bug

if linuxManualConfig is used, it's impossible to set features and default ones are broken

Steps To Reproduce

Steps to reproduce the behavior:

  1. use linuxManualConfig
 cat /etc/nixos/configuration.nix
# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

{ config, pkgs, lib, ... }:


let 
  inherit (pkgs) lib buildEnv; 
  nixpkgsmaster = import <nixpkgsmaster>{};
  nixpkgsunstable = import <nixpkgsunstable>{};
  nixpkgs2111 = import <nixpkgs2111>{};
  nixpkgs2105 = import <nixpkgs2105>{};
  nixpkgs2009 = import <nixpkgs2009>{};
  nixpkgs2003 = import <nixpkgs2003>{};
  nixpkgs1809 = import <nixpkgs1809>{};
  nixgl = import <nixgl>{};
  my_kernel = (nixpkgsmaster.linuxManualConfig rec {
      inherit (pkgs) stdenv;
      version = "6.2-rc8";
      modDirVersion = "6.2.0-rc8";
#      ignoreConfigErrors = true;
      allowImportFromDerivation = true;
      src = pkgs.fetchurl {
        url = "https://git.kernel.org/torvalds/t/linux-${version}.tar.gz";
        hash = "sha256-dH1yngib/jfQwHEzONCcSP4VVoGsxIWUm7ABAmOXpzI=";
      };
      configfile = /home/sss/git/kernel/config_nixos;
      features.ia32Emulation = true;
      #config = {
      #  CONFIG_IA32_EMULATION = "y";
      #   CONFIG_MODULES = "y";
      #   CONFIG_FW_LOADER = "y";
      #};
    });
in {
  imports =
    [ # Include the results of the hardware scan.
    ./hardware-configuration-local.nix
    ./network.nix
    ./guix.nix
    ./alien.nix
  ];
boot.kernelPackages = (nixpkgsmaster.linuxPackagesFor my_kernel);
  1. use anything that rely on kernel.features
  hardware.opengl = {                                                                                                                                                                           
    enable = true;
    extraPackages = with pkgs; [
      intel-media-driver
      intel-ocl
    ];
    driSupport = true;
    driSupport32Bit = true;
    extraPackages32 = with pkgs; [
      driversi686Linux.intel-media-driver
    ];
  };
  1. nixos-rebuild switch

Expected behavior

kernel with custom config should be built with appropriate features set initialized

Actual result

building Nix...
building the system configuration...
error:
       Failed assertions:
       - Option driSupport32Bit requires a kernel that supports 32bit emulation
(use '--show-trace' to show detailed location information)

Notify maintainers

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.2.0-rc8, NixOS, 22.11 (Raccoon), 22.11.2579.75e0a511d0e`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.11.1`
 - channels(root): `"alien, android-nixpkgs, nixgl, nixos-22.11-small, nixpkgs1809-18.09-small, nixpkgs2003-20.03-small, nixpkgs2009-20.09-small, nixpkgs2105-21.05-small, nixpkgs2111-21.11-small, nixpkgs2205-22.05-small, nixpkgsmaster, nixpkgsunstable, nur"`
 - channels(sss): `""`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
@ncfavier
Copy link
Member

ping @K900

@K900
Copy link
Contributor

K900 commented Feb 15, 2023

That argument is explicitly ignored. https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/linux/kernel/manual-config.nix#L52

I'm not sure why.

@sss123next
Copy link
Author

maybe it's time to start using it ?

@K900
Copy link
Contributor

K900 commented Feb 15, 2023

PRs appreciated.

@sss123next
Copy link
Author

diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix
index 18c32930f36..df24f88e713 100644
--- a/pkgs/os-specific/linux/kernel/manual-config.nix
+++ b/pkgs/os-specific/linux/kernel/manual-config.nix
@@ -48,8 +48,12 @@ in lib.makeOverridable ({
 
   # Whether to utilize the controversial import-from-derivation feature to parse the config
   allowImportFromDerivation ? false,
-  # ignored
-  features ? null, lib ? lib_, stdenv ? stdenv_,
+  features ? {   iwlwifi = true; 
+    efiBootStub = true; 
+    needsCifsUtils = true; 
+    netfilterRPFilter = true; 
+    ia32Emulation = true;     },
+    lib ? lib_, stdenv ? stdenv_,
 }:
 
 let
@@ -64,7 +68,7 @@ let
     (buildPackages.deterministic-uname.override { inherit modDirVersion; })
   ] ++ optional (lib.versionAtLeast version "5.13") zstd;
 
-  drvAttrs = config_: kernelConf: kernelPatches: configfile:
+  drvAttrs = config_: kernelConf: kernelPatches: configfile: features:
     let
       config = let attrName = attr: "CONFIG_" + attr; in {
         isSet = attr: hasAttr (attrName attr) config;
@@ -92,7 +96,7 @@ let
     in (optionalAttrs isModular { outputs = [ "out" "dev" ]; }) // {
       passthru = rec {
         inherit version modDirVersion config kernelPatches configfile
-          moduleBuildDependencies stdenv;
+          features moduleBuildDependencies stdenv;
         inherit isZen isHardened isLibre;
         isXen = lib.warn "The isXen attribute is deprecated. All Nixpkgs kernels that support it now have Xen enabled." true;
         baseVersion = lib.head (lib.splitString "-rc" version);
@@ -371,7 +375,7 @@ in
 assert lib.versionOlder version "5.8" -> libelf != null;
 assert lib.versionAtLeast version "5.8" -> elfutils != null;
 
-stdenv.mkDerivation ((drvAttrs config stdenv.hostPlatform.linux-kernel kernelPatches configfile) // {
+stdenv.mkDerivation ((drvAttrs config stdenv.hostPlatform.linux-kernel kernelPatches configfile features) // {
   pname = "linux";
   inherit version;

@K900
Copy link
Contributor

K900 commented Feb 15, 2023

Please submit it as a proper merge request, so it can be reviewed and tested.

@sss123next
Copy link
Author

unfortunately i do not have time now, i will research how to do so later.

@GrabbenD
Copy link

GrabbenD commented Apr 29, 2023

Just encountered this too 🙁

How did you actually apply your patch to nixpkgs @sss123next ?

@sss123next
Copy link
Author

  1. save it to file
  2. clone nixpkgs in some directory
  3. apply patch to nixpkgs any way you like, for example git apply
  4. use this nixpkgs in you config, for example like this:
{ config, pkgs, lib, ... }:


let 
  inherit (pkgs) lib buildEnv; 

  nixpkgslocal = import (fetchGit {
    url = "/home/sss/git/nix/nixpkgs";
    ref = "manualconfig_fix";
    rev = "eae52a25c6b9c7886d7db960d23324c79fd2274b";
  }) {};

 my_kernel = (nixpkgslocal.linuxManualConfig rec {
      inherit (pkgs) stdenv;
      version = "6.2.13";
      modDirVersion = "6.2.13";
      allowImportFromDerivation = true;
      src = fetchGit {
        url = "git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable";
        ref = "linux-6.2.y";
      };
      configfile = /home/sss/git/kernel/config_nixos;
      features = {
        iwlwifi = false;
        efiBootStub = true;
        needsCifsUtils = false;
        netfilterRPFilter = true;
        ia32Emulation = true;
      };
    });
in {
    ....

NOTE: you can find rev via git log after applying patch via git apply

but keep in mind, this allow to bypass checks, but seems work incorrectly..., so proper fix still required for this bug.

@SaltyKitkat
Copy link
Contributor

SaltyKitkat commented Jun 7, 2023

Actually, the features passed to manualConfig is ignored and useless.
In nixpkgs, features are set here and applied to the kernel at L228.

If everything works fine, we can manually override it, like this:

  let
    kernel = manualConfig(...);
    passthru = {
      features = {...};
    };
    finalkernel = lib.extendDerivation true passthru kernel;

and use the finalkernel.

However, this also doesn't work currently, due to #111504 and https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/system/boot/kernel.nix#L43 ...

So, finally, we should write something like this:

  let
    kernel = manualConfig(...);
    passthru = {
      features = {...};
    };
    finalkernel = kernel.overrideAttrs(old: {passthru = old.passthru // passthru;});

and I hope this can work ...

Update: It seems working very well on my machine!

My dear steam, long time no see!

And it would be great if my experience can help you guys!

@zzywysm
Copy link
Contributor

zzywysm commented Jun 2, 2024

Now that #288154 is merged, can this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants