aboutsummaryrefslogtreecommitdiff
path: root/pkgs/coreboot-base/default.nix
blob: 3b8fe28f29bef649ccb986a4dd167d1def4ab389 (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
63
64
65
66
67
68
69
70
71
72
73
{ fetchgit
, fetchurl
, stdenv
, m4
, flex
, bison
, zlib
, gnat
, curl
, grub-coreboot
, tianocore-coreboot
, perl
, writeText
, config ? {}
}:

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
      ${}
      NIX_HARDENING_ENABLE="$\{NIX_HARDENING_ENABLE/ format/\}" make crossgcc-i386 CPUS=$NIX_BUILD_CORES
    '';
    installPhase = ''
      cp -r util/crossgcc $out
    '';
  };

in stdenv.mkDerivation rec {
  pname = "coreboot";
  inherit version src;
  configurePhase = let
    filteredConfig = lib.filterAttrs (n: v: v != null) config;
    lines = lib.mapAttrsToList (name: value: "${name}=${value}") filteredConfig;
    configFile = writeText "config" (concatStringsSept "\n" lines);
  in ''
    cp ${configFile} .config
    make olddefconfig
  '';
  buildPhase = ''
    rm -rf util/crossgcc
    cp -r ${toolchain} util/crossgcc
    chmod u+rwX -R util/crossgcc
    patchShebangs util/xcompile/xcompile
    make
  '';
  installPhase = ''
    mkdir -p $out
    cp build/coreboot.rom $out
  '';
  passthru = {
    inherit toolchain configfile;
  };
}