summaryrefslogtreecommitdiffstats
path: root/pkgs/misc/barebox/default.nix
blob: cbbc3fc8a9db5039b2526a90b66a4a272a4e30bb (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{
  stdenv,
  lib,
  fetchurl,
  bison,
  dtc,
  flex,
  libusb1,
  lzop,
  openssl,
  pkg-config,
  buildPackages,
  lz4,
}:

let
  defaultVersion = "2026.06.1";
  defaultSrc = fetchurl {
    url = "https://www.barebox.org/download/barebox-${defaultVersion}.tar.bz2";
    sha256 = "sha256-h1KzdSgZ7EqvhIodBt8FJCpklUUl+xW2zwezw91+vX8=";
  };

  buildBarebox = lib.makeOverridable (
    {
      version ? null,
      src ? null,
      filesToInstall,
      installDir ? "$out",
      defconfig,
      extraMeta ? { },
      ...
    }@args:
    stdenv.mkDerivation (finalAttrs: {
      pname = "barebox-${defconfig}";
      strictDeps = true;

      version = if version == null then defaultVersion else version;
      src = if src == null then defaultSrc else src;

      postPatch = ''
        patchShebangs scripts
      '';

      nativeBuildInputs = [
        bison
        dtc
        flex
        lz4
        lzop
        openssl
        pkg-config
      ];

      buildInputs = [
        libusb1
        lzop
        openssl
      ];

      depsBuildBuild = [ buildPackages.stdenv.cc ];

      hardeningDisable = [ "all" ];

      makeFlags = [
        "DTC=dtc"
        "CROSS_COMPILE=${stdenv.cc.targetPrefix}"
      ];

      configurePhase = ''
        runHook preConfigure

        make ${defconfig}

        runHook postConfigure
      '';

      installPhase = ''
        runHook preInstall

        mkdir -p ${installDir}
        cp ${lib.concatStringsSep " " filesToInstall} ${installDir}

        runHook postInstall
      '';

      enableParallelBuilding = true;

      __structuredAttrs = true;

      dontStrip = true;

      meta =
        with lib;
        {
          homepage = "https://www.barebox.org";
          description = "Swiss Army Knife for bare metal";
          license = licenses.gpl2Only;
          maintainers = with maintainers; [ emantor ];
        }
        // extraMeta;
    })
    // removeAttrs args [ "extraMeta" ]
  );
in
{
  inherit buildBarebox;

  bareboxTools = buildBarebox {
    defconfig = "hosttools_defconfig";
    installDir = "$out/bin";
    extraMeta.platforms = lib.platforms.linux;
    filesToInstall = [
      "scripts/bareboximd"
      "scripts/imx/imx-usb-loader"
      "scripts/omap4_usbboot"
      "scripts/omap3-usb-loader"
      "scripts/kwboot"
      "scripts/rk-usb-loader"
    ];
  };
}