From 9c9848be544fc20f80b2fdcb5aeb0bb12c23fbe5 Mon Sep 17 00:00:00 2001 From: dramforever Date: Fri, 19 Sep 2025 14:49:25 +0800 Subject: [PATCH] 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. --- .../linux/kernel/manual-config.nix | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index 41d23aa13240..cd207f1d610c 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -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 ( {