From 35956ce40e13ad8aa297f0c6ec1de4132807efdf Mon Sep 17 00:00:00 2001 From: Jared Baur Date: Sun, 17 Aug 2025 19:01:27 -0700 Subject: [PATCH] linux: parse configfile at eval-time if possible Users might call `manualConfig` with a path presented at evaluation time, in which case they shouldn't need to set `allowImportFromDerivation` to true, since IFD wouldn't be needed. --- .../linux/kernel/manual-config.nix | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index 4456a3e0d5c6..200969bc8af2 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -32,16 +32,24 @@ let readConfig = configfile: - import - (runCommand "config.nix" { } '' - echo "{" > "$out" - while IFS='=' read key val; do - [ "x''${key#CONFIG_}" != "x$key" ] || continue - no_firstquote="''${val#\"}"; - echo ' "'"$key"'" = "'"''${no_firstquote%\"}"'";' >> "$out" - done < "${configfile}" - echo "}" >> $out - '').outPath; + 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) + ) + ) + ); in lib.makeOverridable ( { @@ -64,7 +72,9 @@ lib.makeOverridable ( configfile, # Manually specified nixexpr representing the config # If unspecified, this will be autodetected from the .config - config ? lib.optionalAttrs allowImportFromDerivation (readConfig configfile), + config ? lib.optionalAttrs (builtins.isPath configfile || allowImportFromDerivation) ( + readConfig configfile + ), # Custom seed used for CONFIG_GCC_PLUGIN_RANDSTRUCT if enabled. This is # automatically extended with extra per-version and per-config values. randstructSeed ? "",