NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.29k stars 13.54k forks source link

broken "kernel.features" in linuxManualConfig #216529

Open sss123next opened 1 year ago

sss123next commented 1 year ago

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 {}; nixpkgsunstable = import {}; nixpkgs2111 = import {}; nixpkgs2105 = import {}; nixpkgs2009 = import {}; nixpkgs2003 = import {}; nixpkgs1809 = import {}; nixgl = import {}; 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);

2. 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 ]; };

3. `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:

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 commented 1 year ago

ping @K900

K900 commented 1 year ago

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 commented 1 year ago

maybe it's time to start using it ?

K900 commented 1 year ago

PRs appreciated.

sss123next commented 1 year ago
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 commented 1 year ago

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

sss123next commented 1 year ago

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

GrabbenD commented 1 year ago

Just encountered this too 🙁

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

sss123next commented 1 year ago
  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 commented 1 year ago

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 commented 3 months ago

Now that https://github.com/NixOS/nixpkgs/pull/288154 is merged, can this be closed?