From c20aae9ccab8f058b4f5f47994c3c6f620787cf8 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Fri, 15 Jan 2021 15:00:37 +0100 Subject: [PATCH] coreboot: rewrite the toConf function - Use builtins.toJSON - Fix nested attriute sets --- coreboot.nix | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/coreboot.nix b/coreboot.nix index 827e4df..321c7ec 100644 --- a/coreboot.nix +++ b/coreboot.nix @@ -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; }; };