Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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>
  • Loading branch information...
commit 06fac562610c581598906841bba8534659698994 1 parent 75dd904
@shlevy authored
Showing with 29 additions and 39 deletions.
  1. +29 −39 pkgs/os-specific/linux/kernel/manual-config.nix
View
68 pkgs/os-specific/linux/kernel/manual-config.nix
@@ -1,43 +1,5 @@
{ stdenv, runCommand, nettools, bc, perl, kmod, writeTextFile, ubootChooser }:
-let
- inherit (stdenv.lib) optional optionalString optionalAttrs getAttr hasAttr;
-
- # 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
-
{
# The kernel version
version,
@@ -51,12 +13,40 @@ 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 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,
# Whether to utilize the controversial import-from-derivation feature to parse the config
allowImportFromDerivation ? false
}:
+let config_ = config; in
+
let
+ inherit (stdenv.lib) optional optionalString getAttr hasAttr;
+
+ 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
Please sign in to comment.
Something went wrong with that request. Please try again.