diff options
author | Shea Levy <shea@shealevy.com> | 2013-12-31 22:46:43 -0500 |
---|---|---|
committer | Shea Levy <shea@shealevy.com> | 2013-12-31 22:46:43 -0500 |
commit | fe185f0a180a0482c89e9fe8f573bb2ce158b1fd (patch) | |
tree | 09439d5f4bf48e5ff056eada55f8185577299e60 | |
parent | 008992619f0ca5a61d6cd91394c818c5da345050 (diff) | |
download | nixlib-fe185f0a180a0482c89e9fe8f573bb2ce158b1fd.tar nixlib-fe185f0a180a0482c89e9fe8f573bb2ce158b1fd.tar.gz nixlib-fe185f0a180a0482c89e9fe8f573bb2ce158b1fd.tar.bz2 nixlib-fe185f0a180a0482c89e9fe8f573bb2ce158b1fd.tar.lz nixlib-fe185f0a180a0482c89e9fe8f573bb2ce158b1fd.tar.xz nixlib-fe185f0a180a0482c89e9fe8f573bb2ce158b1fd.tar.zst nixlib-fe185f0a180a0482c89e9fe8f573bb2ce158b1fd.zip |
manual-config: Always add config query functions
If the config attrset is manually specified, we still want isYes, isModule, etc. to work. But we let the passed in config attrset take precedence, if for some reason the caller wants to provide their own implementation of one or more of these functions. Signed-off-by: Shea Levy <shea@shealevy.com>
-rw-r--r-- | pkgs/os-specific/linux/kernel/manual-config.nix | 72 |
1 files changed, 32 insertions, 40 deletions
diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix index d96c8e5494cf..3036d8a04b0f 100644 --- a/pkgs/os-specific/linux/kernel/manual-config.nix +++ b/pkgs/os-specific/linux/kernel/manual-config.nix @@ -1,45 +1,16 @@ { stdenv, runCommand, nettools, bc, perl, kmod, writeTextFile, ubootChooser }: let - inherit (stdenv.lib) - hasAttr getAttr optionalAttrs optional optionalString maintainers platforms; - - # Function to parse the config file into a nix expression - readConfig = configFile: - let - configAttrs = 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 - ''}"; - - config = configAttrs // rec { - attrName = attr: "CONFIG_" + attr; - - isSet = attr: hasAttr (attrName attr) config; - - getValue = attr: if isSet attr then getAttr (attrName attr) config else null; - - isYes = attr: (isSet attr) && ((getValue attr) == "y"); - - isNo = attr: (isSet attr) && ((getValue attr) == "n"); - - isModule = attr: (isSet attr) && ((getValue attr) == "m"); - - isEnabled = attr: (isModule attr) || (isYes attr); - - isDisabled = attr: (!(isSet attr)) || (isNo attr); - }; - in - config; - -in - -{ + 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; +in { # The kernel version version, # The version of the kernel module directory @@ -52,12 +23,33 @@ in configfile, # Manually specified nixexpr representing the config # If unspecified, this will be autodetected from the .config - config ? optionalAttrs allowImportFromDerivation (readConfig configfile), + config ? stdenv.lib.optionalAttrs allowImportFromDerivation (readConfig configfile), # Whether to utilize the controversial import-from-derivation feature to parse the config allowImportFromDerivation ? false }: +let config_ = config; in + let + inherit (stdenv.lib) + hasAttr getAttr optionalAttrs optional optionalString maintainers platforms; + + config = let attrName = attr: "CONFIG_" + attr; in { + isSet = attr: hasAttr (attrName attr) config; + + getValue = attr: if config.isSet attr then getAttr (attrName attr) config else null; + + isYes = attr: (config.getValue attr) == "y"; + + isNo = attr: (config.getValue attr) == "n"; + + isModule = attr: (config.getValue attr) == "m"; + + isEnabled = attr: (config.isModule attr) || (config.isYes attr); + + isDisabled = attr: (!(config.isSet attr)) || (config.isNo attr); + } // config_; + installkernel = writeTextFile { name = "installkernel"; executable=true; text = '' #!${stdenv.shell} -e mkdir -p $4 |