coreboot: rewrite the toConf function

- Use builtins.toJSON
- Fix nested attriute sets
This commit is contained in:
Michele Guerini Rocco 2021-01-15 15:00:37 +01:00
parent 993e009dba
commit c20aae9cca
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450

View File

@ -1,4 +1,4 @@
{ stdenv, fetchurl, fetchgit
{ lib, stdenv, fetchurl, fetchgit
, linkFarm, overrideCC
, writeText, writeShellScriptBin
, gnat, bison, flex, zlib, python3
@ -11,7 +11,6 @@
}:
let
lib = stdenv.lib;
adaStdenv = overrideCC stdenv gnat;
version = lib.substring 0 6 rev;
@ -29,7 +28,7 @@ in rec {
# seabios source
seabios = builtins.fetchGit {
url = "https://review.coreboot.org/seabios.git";
rev = conf.seabios.revision_id;
rev = conf.seabios.revision-id;
};
# tarballs needed to build the toolchain
@ -41,25 +40,23 @@ in rec {
## Helpers
# converts Nix attrs to Kconfig format
toConf = top: n: v: with builtins;
toConf = prefix: name: val:
let
prefix = lib.optionalString top "CONFIG_";
nconv = n: replaceStrings ["-"] ["_"] (lib.toUpper n);
vconv = v: if isBool v then (if v then "y" else "n")
else if (isString v) || (isPath v) || (lib.isDerivation v) then "\"${v}\""
else toString v;
name' = lib.replaceStrings ["-"] ["_"] (lib.toUpper name);
val' = if lib.isBool val then (if val then "y" else "n")
else builtins.toJSON val;
sub = "${prefix}_${name'}";
in
if (lib.isAttrs v && ! lib.isDerivation v)
then (lib.concatMapStringsSep "\n"
(line: "${prefix}${nconv n}_${line}")
(lib.mapAttrsToList (toConf false) v))
else "${prefix}${nconv n}=${vconv v}";
if lib.isAttrs val && ! lib.isDerivation val
then (lib.concatStringsSep "\n"
(lib.mapAttrsToList (toConf sub) val))
else "${prefix}_${name'}=${val'}";
# the coreboot Kconfig file
defConfig = with lib;
writeText "defconfig"
(concatStringsSep "\n"
(mapAttrsToList (toConf true) conf));
(mapAttrsToList (toConf "CONFIG") conf));
# returns the current revision
fakegit = writeShellScriptBin "git" "echo ${version}";
@ -141,7 +138,7 @@ in rec {
make savedefconfig DEFCONFIG=$out/defconfig
'';
meta = with stdenv.lib; {
meta = {
description = "Fast, secure and flexible OpenSource firmware";
longDescription = ''
coreboot is an extended firmware platform that delivers a lightning
@ -150,8 +147,8 @@ in rec {
control over technology.
'';
homepage = "https://www.coreboot.org";
license = licenses.gpl2Only;
platforms = platforms.all;
license = lib.licenses.gpl2Only;
platforms = lib.platforms.all;
};
};