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 lib, 3 stdenv, 4 buildPackages, 5 - runCommand, 6 bc, 7 bison, 8 flex, ··· 33 34 readConfig = 35 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; 46 in 47 lib.makeOverridable ( 48 { ··· 65 configfile, 66 # Manually specified nixexpr representing the config 67 # If unspecified, this will be autodetected from the .config 68 - config ? lib.optionalAttrs allowImportFromDerivation (readConfig configfile), 69 # Custom seed used for CONFIG_GCC_PLUGIN_RANDSTRUCT if enabled. This is 70 # automatically extended with extra per-version and per-config values. 71 randstructSeed ? "",
··· 2 lib, 3 stdenv, 4 buildPackages, 5 bc, 6 bison, 7 flex, ··· 32 33 readConfig = 34 configfile: 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 + ); 53 in 54 lib.makeOverridable ( 55 { ··· 72 configfile, 73 # Manually specified nixexpr representing the config 74 # If unspecified, this will be autodetected from the .config 75 + config ? lib.optionalAttrs (builtins.isPath configfile || allowImportFromDerivation) ( 76 + readConfig configfile 77 + ), 78 # Custom seed used for CONFIG_GCC_PLUGIN_RANDSTRUCT if enabled. This is 79 # automatically extended with extra per-version and per-config values. 80 randstructSeed ? "",