nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{ stdenv
2, lib
3, fetchgit
4, fetchpatch
5, meson
6, ninja
7, flex
8, bison
9, pkg-config
10, which
11, pythonSupport ? false
12, python ? null
13, swig
14, libyaml
15}:
16
17stdenv.mkDerivation rec {
18 pname = "dtc";
19 version = "1.7.0";
20
21 src = fetchgit {
22 url = "https://git.kernel.org/pub/scm/utils/dtc/dtc.git";
23 rev = "refs/tags/v${version}";
24 sha256 = "sha256-FMh3VvlY3fUK8fbd0M+aCmlUrmG9YegiOOQ7MOByffc=";
25 };
26
27 patches = [
28 # meson: Fix cell overflow tests when running from meson
29 (fetchpatch {
30 url = "https://github.com/dgibson/dtc/commit/32174a66efa4ad19fc6a2a6422e4af2ae4f055cb.patch";
31 sha256 = "sha256-C7OzwY0zq+2CV3SB5unI7Ill2M3deF7FXeQE3B/Kx2s=";
32 })
33
34 # meson.build: bump version to 1.7.0
35 (fetchpatch {
36 url = "https://github.com/dgibson/dtc/commit/64a907f08b9bedd89833c1eee674148cff2343c6.patch";
37 sha256 = "sha256-p2KGS5GW+3uIPgXfuIx6aDC54csM+5FZDkK03t58AL8=";
38 })
39
40 # Fix version in libfdt/meson.build
41 (fetchpatch {
42 url = "https://github.com/dgibson/dtc/commit/723545ebe9933b90ea58dc125e4987c6bcb04ade.patch";
43 sha256 = "sha256-5Oq7q+62ZObj3e7rguN9jhSpYoQkwjSfo/N893229dQ=";
44 })
45
46 # Use #ifdef NO_VALGRIND
47 (fetchpatch {
48 url = "https://github.com/dgibson/dtc/commit/41821821101ad8a9f83746b96b163e5bcbdbe804.patch";
49 sha256 = "sha256-7QEFDtap2DWbUGqtyT/RgJZJFldKB8oSubKiCtLZ0w4=";
50 })
51 ];
52
53 env.SETUPTOOLS_SCM_PRETEND_VERSION = version;
54
55 nativeBuildInputs = [
56 meson
57 ninja
58 flex
59 bison
60 pkg-config
61 which
62 ] ++ lib.optionals pythonSupport [
63 python
64 python.pkgs.setuptools-scm
65 swig
66 ];
67
68 buildInputs = [ libyaml ];
69
70 postPatch = ''
71 patchShebangs setup.py
72 '';
73
74 # Required for installation of Python library and is innocuous otherwise.
75 env.DESTDIR = "/";
76
77 mesonAutoFeatures = "auto";
78 mesonFlags = [
79 (lib.mesonBool "static-build" stdenv.hostPlatform.isStatic)
80 ];
81
82 postFixup = lib.optionalString stdenv.isDarwin ''
83 install_name_tool -id $out/lib/libfdt.dylib $out/lib/libfdt-${version}.dylib
84 '';
85
86 # Checks are broken on aarch64 darwin
87 # https://github.com/NixOS/nixpkgs/pull/118700#issuecomment-885892436
88 doCheck = !stdenv.isDarwin;
89
90 meta = with lib; {
91 description = "Device Tree Compiler";
92 homepage = "https://git.kernel.org/pub/scm/utils/dtc/dtc.git";
93 license = licenses.gpl2Plus; # dtc itself is GPLv2, libfdt is dual GPL/BSD
94 maintainers = [ maintainers.dezgeg ];
95 platforms = platforms.unix;
96 };
97}