Repository navigation
linux/kernel: support empty-string values via lib.kernel.freeform "" - #517382
Conversation
1e215ba to
8eaabfd
Compare
8eaabfd to
8240730
Compare
8240730 to
34596e4
Compare
Review dismissed automatically
doronbehar
left a comment
There was a problem hiding this comment.
Small Perl suggestion, shouldn't be a blocker though.
|
Friendly ping @JamieMagee |
34596e4 to
d8e5a96
Compare
doronbehar
left a comment
There was a problem hiding this comment.
Changes look good but maybe something got broken at some point - I tested with the following change to nixos-raspberrypi:
diff --git i/flake.lock w/flake.lock
index 8793b4b..f41edc3 100644
--- i/flake.lock
+++ w/flake.lock
@@ -57,16 +57,16 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1778737229,
- "narHash": "sha256-6xWoytx8jFW4PF1GjRm/i/53trbpKGfz6zjzQGBr4cI=",
- "owner": "NixOS",
+ "lastModified": 1779887054,
+ "narHash": "sha256-qJ1s23xZwPREMIBIpt7TA1ITXE1Vu/g8uYHK/KTWRSI=",
+ "owner": "doronbehar",
"repo": "nixpkgs",
- "rev": "d7a713c0b7e47c908258e71cba7a2d77cc8d71d5",
+ "rev": "00fac792b1f67a1d91395d21c3a45b5805962b45",
"type": "github"
},
"original": {
- "owner": "NixOS",
- "ref": "nixos-25.11",
+ "owner": "doronbehar",
+ "ref": "jamieMagee-kernel-config@master",
"repo": "nixpkgs",
"type": "github"
}
diff --git i/flake.nix w/flake.nix
index 0e10e90..2ef4591 100644
--- i/flake.nix
+++ w/flake.nix
@@ -1,18 +1,18 @@
{
description = "Flake for RaspberryPi support on NixOS";
- nixConfig = {
- extra-substituters = [
- "https://nixos-raspberrypi.cachix.org"
- ];
- extra-trusted-public-keys = [
- "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI="
- ];
- connect-timeout = 5;
- };
+ #nixConfig = {
+ # extra-substituters = [
+ # "https://nixos-raspberrypi.cachix.org"
+ # ];
+ # extra-trusted-public-keys = [
+ # "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI="
+ # ];
+ # connect-timeout = 5;
+ #};
inputs = {
- nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
+ nixpkgs.url = "github:doronbehar/nixpkgs/jamieMagee-kernel-config@master";
argononed = {
# url = "git+file:../argononed?shallow=1";
diff --git i/pkgs/linux-rpi/kernels.nix w/pkgs/linux-rpi/kernels.nix
index f08a776..1b15b58 100644
--- i/pkgs/linux-rpi/kernels.nix
+++ w/pkgs/linux-rpi/kernels.nix
@@ -63,6 +63,8 @@ listToAttrsWLVer [
NFS_V4 = yes; # =module in nixos;
NLS_CODEPAGE_437 = mkKernelOverride yes; # =module in nixos;
ROOT_NFS = yes;
+ # Requires https://github.com/NixOS/nixpkgs/pull/517382
+ CONFIG_LOCALVERSION="";
# UEVENT_HELPER = yes;
# UNICODE = module; # =y in nixos
# USB_SERIAL = module ; # =yes in nixos;
diff --git i/pkgs/linux-rpi/package.nix w/pkgs/linux-rpi/package.nix
index 1ce080e..97c11be 100644
--- i/pkgs/linux-rpi/package.nix
+++ w/pkgs/linux-rpi/package.nix
@@ -98,12 +98,6 @@ in
// (args.argsOverride or { })
)).overrideAttrs
{
- postConfigure = ''
- # The v7 defconfig has this set to '-v7' which screws up our modDirVersion.
- sed -i $buildRoot/.config -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/'
- sed -i $buildRoot/include/config/auto.conf -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/'
- '';
-
postFixup =
let
armArch = if stdenv.isAarch64 then "arm64" else "arm";And the following command (inside nixos-raspberrypi):
nix build -Lf. packages.aarch64-linux.linux-rpi3And got:
Error: modDirVersion 6.12.87 specified in the Nix expression is wrong, it should be: 6.12.87-v8
Where the nixpkgs fork is this PR merged upon branch master:
- github.com/NixOS/nixpkgs/compare/master...doronbehar:jamieMagee-kernel-config@master
|
Still not working: With this diff --git i/flake.lock w/flake.lock
index 8793b4b..172ac65 100644
--- i/flake.lock
+++ w/flake.lock
@@ -57,16 +57,16 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1778737229,
- "narHash": "sha256-6xWoytx8jFW4PF1GjRm/i/53trbpKGfz6zjzQGBr4cI=",
- "owner": "NixOS",
+ "lastModified": 1780903365,
+ "narHash": "sha256-ooWyCnDTd780PBIJSspLxZ8mFjzmucl4K5aW2BQMxBk=",
+ "owner": "doronbehar",
"repo": "nixpkgs",
- "rev": "d7a713c0b7e47c908258e71cba7a2d77cc8d71d5",
+ "rev": "6e402ddd20ac144d8f225fbc1d1dbb5d4f7a5c45",
"type": "github"
},
"original": {
- "owner": "NixOS",
- "ref": "nixos-25.11",
+ "owner": "doronbehar",
+ "ref": "tmp/jamieMagee-kernel-config@master",
"repo": "nixpkgs",
"type": "github"
}
diff --git i/flake.nix w/flake.nix
index 0e10e90..3e087cd 100644
--- i/flake.nix
+++ w/flake.nix
@@ -1,18 +1,18 @@
{
description = "Flake for RaspberryPi support on NixOS";
- nixConfig = {
- extra-substituters = [
- "https://nixos-raspberrypi.cachix.org"
- ];
- extra-trusted-public-keys = [
- "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI="
- ];
- connect-timeout = 5;
- };
+ #nixConfig = {
+ # extra-substituters = [
+ # "https://nixos-raspberrypi.cachix.org"
+ # ];
+ # extra-trusted-public-keys = [
+ # "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI="
+ # ];
+ # connect-timeout = 5;
+ #};
inputs = {
- nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
+ nixpkgs.url = "github:doronbehar/nixpkgs/tmp/jamieMagee-kernel-config@master";
argononed = {
# url = "git+file:../argononed?shallow=1";
diff --git i/pkgs/linux-rpi/kernels.nix w/pkgs/linux-rpi/kernels.nix
index f08a776..bf903ad 100644
--- i/pkgs/linux-rpi/kernels.nix
+++ w/pkgs/linux-rpi/kernels.nix
@@ -63,6 +63,8 @@ listToAttrsWLVer [
NFS_V4 = yes; # =module in nixos;
NLS_CODEPAGE_437 = mkKernelOverride yes; # =module in nixos;
ROOT_NFS = yes;
+ # Requires https://github.com/NixOS/nixpkgs/pull/517382
+ LOCALVERSION = freeform "";
# UEVENT_HELPER = yes;
# UNICODE = module; # =y in nixos
# USB_SERIAL = module ; # =yes in nixos;
diff --git i/pkgs/linux-rpi/package.nix w/pkgs/linux-rpi/package.nix
index 1ce080e..97c11be 100644
--- i/pkgs/linux-rpi/package.nix
+++ w/pkgs/linux-rpi/package.nix
@@ -98,12 +98,6 @@ in
// (args.argsOverride or { })
)).overrideAttrs
{
- postConfigure = ''
- # The v7 defconfig has this set to '-v7' which screws up our modDirVersion.
- sed -i $buildRoot/.config -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/'
- sed -i $buildRoot/include/config/auto.conf -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/'
- '';
-
postFixup =
let
armArch = if stdenv.isAarch64 then "arm64" else "arm";Now I notice that the |
|
@doronbehar OK, I think I've got it, and the PR itself is fine. The issue is where the override ended up in your tree. I reproduced the full flow against the rpi source: a defconfig forced to The reason you're still on The structuredExtraConfig = configFixup // genericConfig // {
LOCALVERSION = lib.kernel.freeform "";
};That applies it to all versions and the |
a18de65 to
a29a1e3
Compare
|
Thanks @JamieMagee for investigating this. I managed to build the kernel without that diff --git i/flake.lock w/flake.lock
index 8793b4b..b1142ed 100644
--- i/flake.lock
+++ w/flake.lock
@@ -57,16 +57,16 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1778737229,
- "narHash": "sha256-6xWoytx8jFW4PF1GjRm/i/53trbpKGfz6zjzQGBr4cI=",
- "owner": "NixOS",
+ "lastModified": 1780997208,
+ "narHash": "sha256-R3jeIi/5wjWJQItYcxp1E7reRjRBHCxdn7IWZZ29Ero=",
+ "owner": "doronbehar",
"repo": "nixpkgs",
- "rev": "d7a713c0b7e47c908258e71cba7a2d77cc8d71d5",
+ "rev": "4386af9eadecc12cd47673b881c8a8ffa154263c",
"type": "github"
},
"original": {
- "owner": "NixOS",
- "ref": "nixos-25.11",
+ "owner": "doronbehar",
+ "ref": "tmp/jamieMagee-kernel-config@master",
"repo": "nixpkgs",
"type": "github"
}
diff --git i/flake.nix w/flake.nix
index 0e10e90..3e087cd 100644
--- i/flake.nix
+++ w/flake.nix
@@ -1,18 +1,18 @@
{
description = "Flake for RaspberryPi support on NixOS";
- nixConfig = {
- extra-substituters = [
- "https://nixos-raspberrypi.cachix.org"
- ];
- extra-trusted-public-keys = [
- "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI="
- ];
- connect-timeout = 5;
- };
+ #nixConfig = {
+ # extra-substituters = [
+ # "https://nixos-raspberrypi.cachix.org"
+ # ];
+ # extra-trusted-public-keys = [
+ # "nixos-raspberrypi.cachix.org-1:4iMO9LXa8BqhU+Rpg6LQKiGa2lsNh/j2oiYLNOQ5sPI="
+ # ];
+ # connect-timeout = 5;
+ #};
inputs = {
- nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
+ nixpkgs.url = "github:doronbehar/nixpkgs/tmp/jamieMagee-kernel-config@master";
argononed = {
# url = "git+file:../argononed?shallow=1";
diff --git i/pkgs/linux-rpi/package.nix w/pkgs/linux-rpi/package.nix
index 1ce080e..afbbafb 100644
--- i/pkgs/linux-rpi/package.nix
+++ w/pkgs/linux-rpi/package.nix
@@ -25,7 +25,10 @@ let
# specific to <name> and the arch it is being built for
configFixup = args.fixupStructuredConfig.${name}.${arch} or { };
in
- configFixup // genericConfig;
+ configFixup // genericConfig // {
+ # Requires https://github.com/NixOS/nixpkgs/pull/517382
+ LOCALVERSION = lib.kernel.freeform "";
+ };
};
in
{
@@ -98,12 +101,6 @@ in
// (args.argsOverride or { })
)).overrideAttrs
{
- postConfigure = ''
- # The v7 defconfig has this set to '-v7' which screws up our modDirVersion.
- sed -i $buildRoot/.config -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/'
- sed -i $buildRoot/include/config/auto.conf -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/'
- '';
-
postFixup =
let
armArch = if stdenv.isAarch64 then "arm64" else "arm";While the diff to Nixpkgs
|
|
Wait I was wrong, the "simpler" substitution of I can only testify this works, but it'd be nice to get @alyssais' final approval on this PR - it should be fully ready now. |
a29a1e3 to
ec28c4e
Compare
ec28c4e to
19d22cb
Compare
19d22cb to
2673bbe
Compare
doronbehar
left a comment
There was a problem hiding this comment.
LGTM, Is this tested?
|
@doronbehar Yes. I reproduced the original The generated config contains |
|
Is the PR description just out of date now? |
|
Yes, yes it is 🤦 Just a minute... EDIT: Updated. |
doronbehar
left a comment
There was a problem hiding this comment.
Looks better, but I will need to test it myself too.
|
@JamieMagee what do you think about this alternative patch? commit e70c26961740aaa05678c2781bce5f24661418c3
Author: Jamie Magee <[email protected]>
Date: Wed May 6 09:30:12 2026 -0700
linux/kernel: support empty-string values via lib.kernel.freeform ""
Resolves #516936
Assisted-by: GitHub Copilot (Claude Opus 4.8)
diff --git a/nixos/modules/system/boot/kernel_config.nix b/nixos/modules/system/boot/kernel_config.nix
index 115b55d98143..b5f9803f9daf 100644
--- a/nixos/modules/system/boot/kernel_config.nix
+++ b/nixos/modules/system/boot/kernel_config.nix
@@ -70,9 +70,7 @@ let
];
in
- if (val == "") then
- "\"\""
- else if val == "y" || val == "m" || val == "n" then
+ if val == "y" || val == "m" || val == "n" then
val
else if all isNumber (stringToCharacters val) then
val
@@ -87,6 +85,9 @@ let
# VIRTIO_BLK y
# VIRTIO_CONSOLE n
# NET_9P_VIRTIO? y
+ # LOCALVERSION
+ #
+ # A line without a value represents an empty string.
#
# Borrowed from copumpkin https://github.com/NixOS/nixpkgs/pull/12158
# returns a string, expr should be an attribute set
@@ -100,9 +101,8 @@ let
let
val = if item.freeform != null then item.freeform else item.tristate;
in
- optionalString (val != null) (
- if (item.optional) then "${key}? ${mkValue val}\n" else "${key} ${mkValue val}\n"
- );
+ optionalString (val != null)
+ "${key}${optionalString item.optional "?"}${optionalString (val != "") " ${mkValue val}"}\n";
mkConf = cfg: concatStrings (mapAttrsToList mkConfigLine cfg);
in
@@ -119,6 +119,7 @@ in
example = ''
USB? y
DEBUG n
+ LOCALVERSION
'';
description = ''
The result of converting the structured kernel configuration in settings
diff --git a/pkgs/os-specific/linux/kernel/generate-config.pl b/pkgs/os-specific/linux/kernel/generate-config.pl
index 18d1f2150562..d1842623355a 100644
--- a/pkgs/os-specific/linux/kernel/generate-config.pl
+++ b/pkgs/os-specific/linux/kernel/generate-config.pl
@@ -4,10 +4,10 @@
# and otherwise uses the default answer (as determined by the default
# config for the architecture). Overrides are read from the file
# $KERNEL_CONFIG, which on each line contains an option name and an
-# answer, e.g. "EXT2_FS_POSIX_ACL y". The script warns about ignored
-# options in $KERNEL_CONFIG, and barfs if `make config' selects
-# another answer for an option than the one provided in
-# $KERNEL_CONFIG.
+# answer, e.g. "EXT2_FS_POSIX_ACL y". A name without an answer means
+# an empty string. The script warns about ignored options in
+# $KERNEL_CONFIG, and barfs if `make config' selects another answer
+# for an option than the one provided in $KERNEL_CONFIG.
use strict;
use IPC::Open2;
@@ -22,15 +22,19 @@ my $buildRoot = $ENV{'BUILD_ROOT'};
my $makeFlags = $ENV{'MAKE_FLAGS'};
$SIG{PIPE} = 'IGNORE';
-# Read the answers.
+# Read the answers. A record without a value represents an empty string.
my %answers;
my %requiredAnswers;
open ANSWERS, "<$ENV{KERNEL_CONFIG}" or die "Could not open answer file";
while (<ANSWERS>) {
chomp;
s/#.*//;
- if (/^\s*([A-Za-z0-9_]+)(\?)?\s+(.*\S)\s*$/) {
- $answers{$1} = $3;
+ if (/^\s*([A-Za-z0-9_]+)(\?)?(?:\s+(.*\S))?\s*$/) {
+ if (defined $3) {
+ $answers{$1} = $3;
+ } else {
+ $answers{$1} = "";
+ }
$requiredAnswers{$1} = !(defined $2);
} elsif (!/^\s*$/) {
die "invalid config line: $_";
@@ -140,20 +144,32 @@ runConfig;
# Read the final .config file and check that our answers are in
# there. `make config' often overrides answers if later questions
# cause options to be selected.
+#
+# While reading, also rewrite any option that was requested as an empty
+# string: `make config` treats an empty interactive answer as "use the
+# default", so a non-empty defconfig value (e.g. CONFIG_LOCALVERSION="-v8")
+# must be replaced directly in the file. Options missing from .config stay
+# absent, so the validation below still reports them as unused.
my %config;
-open CONFIG, "<$buildRoot/.config" or die "Could not read .config";
-while (<CONFIG>) {
- chomp;
- if (/^CONFIG_([A-Za-z0-9_]+)="(.*)"$/) {
- # String options have double quotes, e.g. 'CONFIG_NLS_DEFAULT="utf8"' and allow escaping.
- ($config{$1} = $2) =~ s/\\([\\"])/$1/g;
- } elsif (/^CONFIG_([A-Za-z0-9_]+)=(.*)$/) {
- $config{$1} = $2;
- } elsif (/^# CONFIG_([A-Za-z0-9_]+) is not set$/) {
- $config{$1} = "n";
+{
+ local @ARGV = ("$buildRoot/.config");
+ local $^I = ""; # edit in place
+ while (<>) {
+ if (/^CONFIG_([^=]+)=/ && exists $answers{$1} && $answers{$1} eq "") {
+ $_ = "CONFIG_$1=\"\"\n";
+ }
+ chomp(my $line = $_);
+ if ($line =~ /^CONFIG_([A-Za-z0-9_]+)="(.*)"$/) {
+ # String options have double quotes, e.g. 'CONFIG_NLS_DEFAULT="utf8"' and allow escaping.
+ ($config{$1} = $2) =~ s/\\([\\"])/$1/g;
+ } elsif ($line =~ /^CONFIG_([A-Za-z0-9_]+)=(.*)$/) {
+ $config{$1} = $2;
+ } elsif ($line =~ /^# CONFIG_([A-Za-z0-9_]+) is not set$/) {
+ $config{$1} = "n";
+ }
+ print;
}
}
-close CONFIG;
my $ret = 0;
foreach my $name (sort (keys %answers)) {I tested it and it works too, and I find it a bit more readable, and no extra variables are used, and |
Resolves NixOS#516936 Assisted-by: GitHub Copilot (Claude Opus 4.8)
2673bbe to
b7cd9bb
Compare
|
@doronbehar Taken, thanks. The merged pass does read better, and dropping I just made a few edits to the comments. Nothing major. |
|
FWIW I had the following patch locally waiting to be pushed out which handles this far more straightforwardly: Commit ID: a4bccf21a6ac92d2d511f469e4ae38226cd4fec6
Change ID: pksuvuypqmuutzspvnlmqroxoxosnmzp
Author : Emily <[email protected]> (2026-08-17 08:48:32)
Committer: Emily <[email protected]> (2026-09-08 23:10:11)
buildLinux: support empty string configuration values
This is meaningful for e.g. `SYSTEM_TRUSTED_KEYS`, and the upstream
documentation has examples of using `scripts/config` to set an empty
string in this way.
Of course, driving the interactive configuration script this way is
horrible in general and this whole thing should probably be rewritten,
but this seems fine at a pinch.
diff --git a/nixos/modules/system/boot/kernel_config.nix b/nixos/modules/system/boot/kernel_config.nix
index 115b55d981..58b13ece06 100644
--- a/nixos/modules/system/boot/kernel_config.nix
+++ b/nixos/modules/system/boot/kernel_config.nix
@@ -70,9 +70,7 @@
];
in
- if (val == "") then
- "\"\""
- else if val == "y" || val == "m" || val == "n" then
+ if val == "y" || val == "m" || val == "n" then
val
else if all isNumber (stringToCharacters val) then
val
diff --git a/pkgs/os-specific/linux/kernel/generate-config.pl b/pkgs/os-specific/linux/kernel/generate-config.pl
index 18d1f21505..bed4b9ca95 100644
--- a/pkgs/os-specific/linux/kernel/generate-config.pl
+++ b/pkgs/os-specific/linux/kernel/generate-config.pl
@@ -29,7 +29,7 @@
while (<ANSWERS>) {
chomp;
s/#.*//;
- if (/^\s*([A-Za-z0-9_]+)(\?)?\s+(.*\S)\s*$/) {
+ if (/^\s*([A-Za-z0-9_]+)(\?)?\s+(.*\S?)\s*$/) {
$answers{$1} = $3;
$requiredAnswers{$1} = !(defined $2);
} elsif (!/^\s*$/) {
@@ -131,6 +131,18 @@
waitpid $pid, 0;
}
+# `make config` interprets an empty line as taking the previous/default
+# value of an option, so we need to set empty values ahead of time.
+foreach my $name (keys %answers) {
+ if ($answers{$name} eq "") {
+ system(
+ "$ENV{SRC}/scripts/config",
+ "--file", "$buildRoot/.config",
+ "--set-str", $name, "",
+ ) == 0 or die "Could not set empty $name";
+ }
+}
+
# Run `make config' several times to converge on the desired result.
# (Some options may only become available after other options are
# set in a previous run.) |
lib.kernel.freeform ""currently producesCONFIG_FOO="\"\"". The intermediate config writes""as the answer, andgenerate-config.plpasses those quote characters to Kconfig instead of setting an empty value.This PR represents an empty value as an option with no value:
generate-config.plrecords these as empty strings. After bothmake configruns, it rewrites matching assignments in.configtoCONFIG_<name>="".Resolves #516936.
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.