linux: parse configfile at eval-time if possible (#434608)

authored by K900 and committed by GitHub 8c412c3f e2de2c4a

+21 -12
+21 -12
pkgs/os-specific/linux/kernel/manual-config.nix
··· 2 2 lib, 3 3 stdenv, 4 4 buildPackages, 5 - runCommand, 6 5 bc, 7 6 bison, 8 7 flex, ··· 33 32 34 33 readConfig = 35 34 configfile: 36 - import 37 - (runCommand "config.nix" { } '' 38 - echo "{" > "$out" 39 - while IFS='=' read key val; do 40 - [ "x''${key#CONFIG_}" != "x$key" ] || continue 41 - no_firstquote="''${val#\"}"; 42 - echo ' "'"$key"'" = "'"''${no_firstquote%\"}"'";' >> "$out" 43 - done < "${configfile}" 44 - echo "}" >> $out 45 - '').outPath; 35 + lib.listToAttrs ( 36 + map 37 + ( 38 + line: 39 + let 40 + match = lib.match "(.*)=\"?(.*)\"?" line; 41 + in 42 + { 43 + name = lib.elemAt match 0; 44 + value = lib.elemAt match 1; 45 + } 46 + ) 47 + ( 48 + lib.filter (line: !(lib.hasPrefix "#" line || line == "")) ( 49 + lib.splitString "\n" (builtins.readFile configfile) 50 + ) 51 + ) 52 + ); 46 53 in 47 54 lib.makeOverridable ( 48 55 { ··· 65 72 configfile, 66 73 # Manually specified nixexpr representing the config 67 74 # If unspecified, this will be autodetected from the .config 68 - config ? lib.optionalAttrs allowImportFromDerivation (readConfig configfile), 75 + config ? lib.optionalAttrs (builtins.isPath configfile || allowImportFromDerivation) ( 76 + readConfig configfile 77 + ), 69 78 # Custom seed used for CONFIG_GCC_PLUGIN_RANDSTRUCT if enabled. This is 70 79 # automatically extended with extra per-version and per-config values. 71 80 randstructSeed ? "",