linux/kernel/manual-config: Do all of the config file parsing in the imported-from derivation
This commit is contained in:
parent
6585646d41
commit
f0694a3151
|
@ -1,4 +1,4 @@
|
||||||
{ stdenv, runCommand, nettools, perl, kmod, writeTextFile }:
|
{ stdenv, runCommand, nettools, perl, kmod, writeTextFile, coffeescript }:
|
||||||
|
|
||||||
with stdenv.lib;
|
with stdenv.lib;
|
||||||
|
|
||||||
|
@ -7,25 +7,65 @@ let
|
||||||
# Function to parse the config file to get the features supported
|
# Function to parse the config file to get the features supported
|
||||||
readFeatures = config:
|
readFeatures = config:
|
||||||
let
|
let
|
||||||
# !!! Original causes recursion too deep, need to import from derivation
|
configParser = writeTextFile { name = "config-parser"; executable=true; text = ''
|
||||||
# linesWithComments = splitString "\n" (builtins.readFile config);
|
#!${coffeescript}/bin/coffee
|
||||||
lines = import "${runCommand "lines.nix" {} ''
|
fs = require "fs"
|
||||||
echo "[" >> $out
|
events = require "events"
|
||||||
while read line; do
|
|
||||||
if [ -n "$line" ] && [ "#" != ''${line:0:1} ]; then
|
|
||||||
echo "'''" >> $out
|
|
||||||
echo $(echo $line | sed "s/'''/''''/g")"'''" >> $out
|
|
||||||
fi
|
|
||||||
done < ${config}
|
|
||||||
echo "]" >> $out
|
|
||||||
''}";
|
|
||||||
|
|
||||||
nvpairs = map (s: let split = splitString "=" s; fst = head split; in {
|
lineEmitter = new events.EventEmitter()
|
||||||
name = substring (stringLength "CONFIG_") (stringLength fst) fst;
|
buffer = new Buffer 0
|
||||||
value = head (tail split);
|
input = fs.createReadStream process.argv[2]
|
||||||
}) lines;
|
input.on 'data', (data) ->
|
||||||
|
nextBuffer = new Buffer buffer.length + data.length
|
||||||
|
buffer.copy(nextBuffer)
|
||||||
|
data.copy(nextBuffer, buffer.length)
|
||||||
|
start = 0
|
||||||
|
offset = buffer.length
|
||||||
|
buffer = nextBuffer
|
||||||
|
|
||||||
configAttrs = listToAttrs nvpairs;
|
for i in [1..data.length]
|
||||||
|
if data[i] == '\n'.charCodeAt 0
|
||||||
|
end = i+offset+1
|
||||||
|
line = buffer.slice start, end - 1
|
||||||
|
start = end
|
||||||
|
lineEmitter.emit "line", line.toString()
|
||||||
|
|
||||||
|
buffer = buffer.slice start
|
||||||
|
input.once 'end', ->
|
||||||
|
input.destroy()
|
||||||
|
if safeToWrite
|
||||||
|
output.end "}"
|
||||||
|
output.destroySoon()
|
||||||
|
else
|
||||||
|
output.once 'drain', ->
|
||||||
|
output.end "}"
|
||||||
|
output.destroySoon()
|
||||||
|
|
||||||
|
output = fs.createWriteStream process.env["out"]
|
||||||
|
output.setMaxListeners 0
|
||||||
|
safeToWrite = output.write "{\n"
|
||||||
|
unless safeToWrite
|
||||||
|
output.once 'drain', ->
|
||||||
|
safeToWrite = true
|
||||||
|
|
||||||
|
escapeNixString = (str) ->
|
||||||
|
str.replace("'''", "''''").replace("''${", "'''''${")
|
||||||
|
lineEmitter.on 'line', (line) ->
|
||||||
|
unless line.length is 0 or line.charAt(0) is '#'
|
||||||
|
split = line.split '='
|
||||||
|
name = split[0].substring "CONFIG_".length
|
||||||
|
value = escapeNixString split.slice(1).join ""
|
||||||
|
lineToWrite = "\"#{name}\" = '''#{value}''';\n"
|
||||||
|
if safeToWrite
|
||||||
|
safeToWrite = output.write lineToWrite
|
||||||
|
else
|
||||||
|
input.pause()
|
||||||
|
output.once 'drain', ->
|
||||||
|
safeToWrite = output.write lineToWrite
|
||||||
|
input.resume()
|
||||||
|
'';};
|
||||||
|
|
||||||
|
configAttrs = import "${runCommand "attrList.nix" {} "${configParser} ${config}"}";
|
||||||
|
|
||||||
getValue = option:
|
getValue = option:
|
||||||
if hasAttr option configAttrs then getAttr option configAttrs else null;
|
if hasAttr option configAttrs then getAttr option configAttrs else null;
|
||||||
|
|
|
@ -5858,7 +5858,8 @@ let
|
||||||
|
|
||||||
# A function to build a manually-configured kernel
|
# A function to build a manually-configured kernel
|
||||||
linuxManualConfig = import ../os-specific/linux/kernel/manual-config.nix {
|
linuxManualConfig = import ../os-specific/linux/kernel/manual-config.nix {
|
||||||
inherit stdenv runCommand nettools perl kmod writeTextFile;
|
inherit (pkgs) stdenv runCommand nettools perl kmod writeTextFile;
|
||||||
|
coffeescript = pkgs.nodePackages."coffee-script";
|
||||||
};
|
};
|
||||||
|
|
||||||
keyutils = callPackage ../os-specific/linux/keyutils { };
|
keyutils = callPackage ../os-specific/linux/keyutils { };
|
||||||
|
|
Loading…
Reference in a new issue