aboutsummaryrefslogtreecommitdiff
path: root/pkgs/coreboot/default.nix
blob: 044e3667d650bd670dd8f1c6994d8eaa52d94230 (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
74
75
76
77
{ 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 {})}
      NIX_HARDENING_ENABLE="$\{NIX_HARDENING_ENABLE/ format/\}" make crossgcc-i386 CPUS=$NIX_BUILD_CORES
    '';
    installPhase = ''
      cp -r util/crossgcc $out
    '';
  };

  filteredConfig = lib.filterAttrs (n: v: v != null) corebootConfig;
  lines = lib.mapAttrsToList (name: value: "${name}=${value}") filteredConfig;
  configFile = writeText "config" (lib.concatStringsSep "\n" lines);
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 ${configFile} .config
    make olddefconfig
    runHook postConfigure
  '';

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

  passthru = {
    inherit toolchain configFile;
  };
}