Skip to content

overrideAttrs on kernel derivation loses passthru values #111504

@samueldr

Description

@samueldr

Describe the bug

There is an oddity with how the kernel derivations react when overrideAttrs is used with them. Some passthru values are lost, namely features and commonStructuredConfig.

In turn, this makes customizing them harder than expected. These values are used in the NixOS modules.

To Reproduce

Using overrideAttrs, the passthru value given to the function does not hold all values found on the derivation's own passthru.

Details:

let
  kernel = pkgs.linux_latest;
  overriddenKernel = kernel.overrideAttrs({ passthru ? {}, ... }: {
    passthru = passthru // {
      world = "y'all";
    };
  });
in
  /* ok   */ assert kernel ? features;
  /* ok   */ assert kernel ? commonStructuredConfig;
  /* fail */ assert overriddenKernel ? features;
  /* fail */ assert overriddenKernel ? commonStructuredConfig;

Expected behavior

Values in passthru on the derivation should all be present in the overrideAttrs call.

Workaround

let
  kernel = pkgs.linux_latest;
  overriddenKernel = kernel.overrideAttrs({ passthru ? {}, ... }: {
    passthru = kernel.passthru // { # <- use the derivation rather than the param
      world = "y'all";
    };
  });
in

Additional context

And where I suspect this is coming from:

  • passthru = {
    features = kernelFeatures;
    inherit commonStructuredConfig isXen isZen isHardened isLibre;
    kernelOlder = lib.versionOlder version;
    kernelAtLeast = lib.versionAtLeast version;
    passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]);
    };
    in lib.extendDerivation true passthru kernel

This is can be observed against 891f607, and is an evaluation issue. No builds happened.

The linked gist contains a full reproduction.

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions