aboutsummaryrefslogtreecommitdiff
path: root/infra/corenix/pkgs/coreboot/default.nix
blob: d5dc4919d6837ae18caabb0729555cf258209493 (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
{ fetchgit, fetchurl, stdenv, m4, flex, bison, zlib, gnat, curl, writeText
, callPackage, lib, corebootConfig ? { CONFIG_PAYLOAD_NONE = "y"; } }:

let
  toolchain = stdenv.mkDerivation rec {
    pname = "coreboot-toolchain";
    inherit (coreboot) 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;

  coreboot = stdenv.mkDerivation rec {
    pname = "coreboot";
    version = "4.13";

    src = fetchgit {
      url = "https://review.coreboot.org/coreboot.git";
      rev = version;
      sha256 = "sha256-O5udH6RAfs5IPqzvluXAApU7TDow39aOEewL5+nln3c=";
      fetchSubmodules = true;
    };

    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; };
  };

in coreboot