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