Skip to content

nixos/boot.kernelPatches: lib.kernel.freeform "" produces CONFIG_FOO="\"\"" instead of CONFIG_FOO="" #516936

Closed

Description

@JamieMagee

Nixpkgs version

  • Unstable (26.05)

Describe the bug

Setting a Kconfig string option to the empty string via structuredExtraConfig (or boot.kernelPatches[].extraStructuredConfig) using lib.kernel.freeform "" does not produce an empty value in the generated .config. The resulting line contains the literal two-character string "" instead.

Steps to reproduce

  1. Add a kernel patch entry that clears CONFIG_LOCALVERSION:

    boot.kernelPatches = [{
      name = "empty-localversion";
      patch = null;
      extraStructuredConfig.LOCALVERSION = lib.kernel.freeform "";
    }];
  2. Build the kernel and inspect the generated .config.

Expected behaviour

CONFIG_LOCALVERSION=""

And modDirVersion equal to the kernel version with no suffix.

Screenshots

No response

Relevant log output

$ grep LOCALVERSION $out
CONFIG_LOCALVERSION="\"\""


When this value flows through to `Makefile`'s `KERNELRELEASE`, `modDirVersion` becomes e.g. `6.12.75""`, which trips the nixpkgs sanity check:


Error: modDirVersion 6.12.75 specified in the Nix expression is wrong, it should be: 6.12.75""

Additional context

Cause is in nixos/modules/system/boot/kernel_config.nix:

mkValue = val:
  if (val == "") then "\"\""
  else if val == "y" || val == "m" || val == "n" then val
  ...
  else val; # FIXME: fix quoting one day

Every other branch returns val unquoted. The intermediate format consumed by pkgs/os-specific/linux/kernel/generate-config.pl is unquoted; kconfig itself adds quotes when writing .config. The empty-string branch emits "" into the intermediate file, the perl regex captures the two " chars as the answer, and kconfig stores them as the string value.

Side issue: the perl regex ^\s*([A-Za-z0-9_]+)(\?)?\s+(.*\S)\s*$ requires at least one non-space char after the key, so simply changing mkValue "" to return "" would silently drop the line. A real fix probably needs mkValue "" to emit a recognisable token plus a post-make config rewrite of .config for empty freeform values.

freeform "" looks usable but never has worked. The most common case is clearing CONFIG_LOCALVERSION for vendor kernels (Raspberry Pi, etc.). Today's workaround is a postConfigure sed on .config, used by pkgs/os-specific/linux/kernel/linux-rpi.nix and recently re-introduced in nixos-hardware (NixOS/nixos-hardware#1860, fixes NixOS/nixos-hardware#1859).

System metadata

  • system: "x86_64-linux"
  • host os: Linux 6.6.87.2-microsoft-standard-WSL2, Arch Linux, noversion, rolling
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Determinate Nix 3.17.3) 2.33.3
  • nixpkgs: /nix/store/ps8fhbglachs62pf47aw3rzx8zfij8sp-source

Notify maintainers

cc @teto @alyssais @lheckemann


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a 👍 reaction to issues you find important.

Activity

  1. added
    0.kind: bug
    6.topic: nixos
    on May 5, 2026
  2. alyssais commented on May 6, 2026

    @alyssais
    Member
  3. added 3 commits that reference this issue on May 6, 2026
    1e215ba
    8eaabfd
    8240730
  4. JamieMagee commented on May 6, 2026

    @JamieMagee
    MemberAuthor
  5. added 3 commits that reference this issue on May 20, 2026
    34596e4
    d8e5a96
    673213c
  6. added 2 commits that reference this issue on Jun 7, 2026
    a18de65
    a29a1e3
  7. added 3 commits that reference this issue on Jun 9, 2026
    4386af9
    4ea4ac7
    ef44395
  8. added a commit that references this issue on Jul 26, 2026
    ec28c4e
  9. added 2 commits that reference this issue on Aug 24, 2026
    19d22cb
    2673bbe
  10. added a commit that references this issue on Sep 2, 2026
    b7cd9bb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug6.topic: kernel6.topic: nixos

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions