aboutsummaryrefslogtreecommitdiff
path: root/pkgs/coreboot/default.nix
blob: 91793f148086067b1a27e1b504161eef9eb8f372 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{ fetchgit, fetchurl, stdenv, m4, flex, bison, zlib, gnat, curl, writeText
, callPackage, lib, corebootConfig ? { CONFIG_PAYLOAD_NONE = "y"; } }:

let
  version = "4.12";
  src = fetchgit {
    url = "https://review.coreboot.org/coreboot.git";
    rev = "${version}";
    fetchSubmodules = true;
    sha256 = "1l140zbvn6pkbrr55lymhi4lycimhpy8xgm45shl4zv6a9vjd66z";
  };

  toolchain = stdenv.mkDerivation rec {
    pname = "coreboot-toolchain";
    inherit version src;
    nativeBuildInputs = [ curl stdenv m4 flex bison zlib gnat ];
    buildPhase = ''
      mkdir -p util/crossgcc/tarballs
      ${lib.concatMapStringsSep "\n"
      (file: "ln -s ${file.archive} util/crossgcc/tarballs/${file.name}")
      (callPackage ./files.nix { })}
      make crossgcc-i386 CPUS=$NIX_BUILD_CORES
    '';
    installPhase = ''
      cp -r util/crossgcc $out
    '';
  };

  writeConfig = config:
    let
      filteredConfig = lib.filterAttrs (n: v: v != null) config;
      lines =
        lib.mapAttrsToList (name: value: "${name}=${value}") filteredConfig;
      configFile = writeText "config" (lib.concatStringsSep "\n" lines);
    in configFile;

in stdenv.mkDerivation rec {

  pname = "coreboot";
  inherit version src;

  postPatch = ''
    rm -rf util/crossgcc
    cp -r ${toolchain} util/crossgcc
    chmod u+rwX -R util/crossgcc
    patchShebangs util/xcompile/xcompile
  '';

  configurePhase = ''
    runHook preConfigure
    cp ${writeConfig corebootConfig} .config
    make olddefconfig
    runHook postConfigure
  '';

  installPhase = ''
    mkdir -p $out
    cp build/coreboot.rom $out
  '';

  passthru = { inherit toolchain writeConfig corebootConfig; };
}