linuxManualConfig: Handle only y and m in readConfig

Parsing Linux config files in Nix in full is complicated, primarily due
to string values. Currently, the regular expression used is fragile and
breaks with string values containing equal signs or (escaped) quotes.

The primary use of these options is system.requiredKernelConfig, which
only really needs to track "yes" and "module". Therefore, only parse
those.

This is a breaking change. However, this is a very obscure corner of
linuxManualConfig and should have few if any affected users.
This commit is contained in:
dramforever
2025-09-19 15:36:51 +08:00
parent 12bd230118
commit 9c9848be54
+12 -18
View File
@@ -32,24 +32,18 @@ let
readConfig =
configfile:
lib.listToAttrs (
map
(
line:
let
match = lib.match "(.*)=\"?(.*)\"?" line;
in
{
name = lib.elemAt match 0;
value = lib.elemAt match 1;
}
)
(
lib.filter (line: !(lib.hasPrefix "#" line || line == "")) (
lib.splitString "\n" (builtins.readFile configfile)
)
)
);
let
matchLine =
line:
let
match = lib.match "(CONFIG_[^=]+)=([ym])" line;
in
lib.optional (match != null) {
name = lib.elemAt match 0;
value = lib.elemAt match 1;
};
in
lib.listToAttrs (lib.concatMap matchLine (lib.splitString "\n" (builtins.readFile configfile)));
in
lib.makeOverridable (
{